~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

- ignore .swp files from upload

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
1
# -*- coding: UTF-8 -*-
3
2
 
4
3
# This program is free software; you can redistribute it and/or modify
23
22
######################################################################
24
23
# exceptions 
25
24
class BzrError(StandardError):
26
 
    pass
 
25
    def __str__(self):
 
26
        # XXX: Should we show the exception class in 
 
27
        # exceptions that don't provide their own message?  
 
28
        # maybe it should be done at a higher level
 
29
        ## n = self.__class__.__name__ + ': '
 
30
        n = ''
 
31
        if len(self.args) == 1:
 
32
            return n + self.args[0]
 
33
        elif len(self.args) == 2:
 
34
            # further explanation or suggestions
 
35
            try:
 
36
                return n + '\n  '.join([self.args[0]] + self.args[1])
 
37
            except TypeError:
 
38
                return n + "%r" % self
 
39
        else:
 
40
            return n + `self.args`
 
41
 
27
42
 
28
43
class BzrCheckError(BzrError):
29
44
    pass
30
45
 
31
46
 
32
 
 
33
 
 
34
 
def bailout(msg, explanation=[]):
35
 
    ex = BzrError(msg, explanation)
36
 
    import trace
37
 
    trace._tracefile.write('* raising %s\n' % ex)
38
 
    raise ex
39
 
 
 
47
class InvalidRevisionNumber(BzrError):
 
48
    def __str__(self):
 
49
        return 'invalid revision number: %r' % self.args[0]
 
50
 
 
51
 
 
52
class InvalidRevisionId(BzrError):
 
53
    pass
 
54
 
 
55
 
 
56
class BzrCommandError(BzrError):
 
57
    # Error from malformed user command
 
58
    def __str__(self):
 
59
        return self.args[0]
 
60
 
 
61
 
 
62
class NotBranchError(BzrError):
 
63
    """Specified path is not in a branch"""
 
64
    def __str__(self):
 
65
        return 'not a branch: %s' % self.args[0]
 
66
 
 
67
 
 
68
class UnsupportedFormatError(BzrError):
 
69
    """Specified path is a bzr branch that we cannot read."""
 
70
    def __str__(self):
 
71
        return 'unsupported branch format: %s' % self.args[0]
 
72
 
 
73
 
 
74
class NotVersionedError(BzrError):
 
75
    """Specified object is not versioned."""
 
76
 
 
77
 
 
78
class BadFileKindError(BzrError):
 
79
    """Specified file is of a kind that cannot be added.
 
80
 
 
81
    (For example a symlink or device file.)"""
 
82
    pass
 
83
 
 
84
 
 
85
class ForbiddenFileError(BzrError):
 
86
    """Cannot operate on a file because it is a control file."""
 
87
    pass
 
88
 
 
89
 
 
90
class LockError(Exception):
 
91
    """All exceptions from the lock/unlock functions should be from
 
92
    this exception class.  They will be translated as necessary. The
 
93
    original exception is available as e.original_error
 
94
    """
 
95
    def __init__(self, e=None):
 
96
        self.original_error = e
 
97
        if e:
 
98
            Exception.__init__(self, e)
 
99
        else:
 
100
            Exception.__init__(self)
 
101
 
 
102
 
 
103
class CommitNotPossible(LockError):
 
104
    """A commit was attempted but we do not have a write lock open."""
 
105
 
 
106
 
 
107
class AlreadyCommitted(LockError):
 
108
    """A rollback was requested, but is not able to be accomplished."""
 
109
 
 
110
 
 
111
class ReadOnlyError(LockError):
 
112
    """A write attempt was made in a read only transaction."""
 
113
 
 
114
 
 
115
class PointlessCommit(Exception):
 
116
    """Commit failed because nothing was changed."""
 
117
 
 
118
 
 
119
class NoSuchRevision(BzrError):
 
120
    def __init__(self, branch, revision):
 
121
        self.branch = branch
 
122
        self.revision = revision
 
123
        msg = "Branch %s has no revision %s" % (branch, revision)
 
124
        BzrError.__init__(self, msg)
 
125
 
 
126
 
 
127
class HistoryMissing(BzrError):
 
128
    def __init__(self, branch, object_type, object_id):
 
129
        self.branch = branch
 
130
        BzrError.__init__(self,
 
131
                          '%s is missing %s {%s}'
 
132
                          % (branch, object_type, object_id))
 
133
 
 
134
 
 
135
class DivergedBranches(BzrError):
 
136
    def __init__(self, branch1, branch2):
 
137
        BzrError.__init__(self, "These branches have diverged.")
 
138
        self.branch1 = branch1
 
139
        self.branch2 = branch2
 
140
 
 
141
 
 
142
class UnrelatedBranches(BzrCommandError):
 
143
    def __init__(self):
 
144
        msg = "Branches have no common ancestor, and no base revision"\
 
145
            " specified."
 
146
        BzrCommandError.__init__(self, msg)
 
147
 
 
148
class NoCommonAncestor(BzrError):
 
149
    def __init__(self, revision_a, revision_b):
 
150
        msg = "Revisions have no common ancestor: %s %s." \
 
151
            % (revision_a, revision_b) 
 
152
        BzrError.__init__(self, msg)
 
153
 
 
154
class NoCommonRoot(BzrError):
 
155
    def __init__(self, revision_a, revision_b):
 
156
        msg = "Revisions are not derived from the same root: %s %s." \
 
157
            % (revision_a, revision_b) 
 
158
        BzrError.__init__(self, msg)
 
159
 
 
160
class NotAncestor(BzrError):
 
161
    def __init__(self, rev_id, not_ancestor_id):
 
162
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
 
163
                                                        rev_id)
 
164
        BzrError.__init__(self, msg)
 
165
        self.rev_id = rev_id
 
166
        self.not_ancestor_id = not_ancestor_id
 
167
 
 
168
 
 
169
class NotAncestor(BzrError):
 
170
    def __init__(self, rev_id, not_ancestor_id):
 
171
        self.rev_id = rev_id
 
172
        self.not_ancestor_id = not_ancestor_id
 
173
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
 
174
                                                        rev_id)
 
175
        BzrError.__init__(self, msg)
 
176
 
 
177
 
 
178
class InstallFailed(BzrError):
 
179
    def __init__(self, revisions):
 
180
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
 
181
        BzrError.__init__(self, msg)
 
182
        self.revisions = revisions
 
183
 
 
184
 
 
185
class AmbiguousBase(BzrError):
 
186
    def __init__(self, bases):
 
187
        msg = "The correct base is unclear, becase %s are all equally close" %\
 
188
            ", ".join(bases)
 
189
        BzrError.__init__(self, msg)
 
190
        self.bases = bases
 
191
 
 
192
class NoCommits(BzrError):
 
193
    def __init__(self, branch):
 
194
        msg = "Branch %s has no commits." % branch
 
195
        BzrError.__init__(self, msg)
 
196
 
 
197
class UnlistableStore(BzrError):
 
198
    def __init__(self, store):
 
199
        BzrError.__init__(self, "Store %s is not listable" % store)
 
200
 
 
201
class UnlistableBranch(BzrError):
 
202
    def __init__(self, br):
 
203
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
 
204
 
 
205
 
 
206
from bzrlib.weave import WeaveError, WeaveParentMismatch
 
207
 
 
208
class TransportError(BzrError):
 
209
    """All errors thrown by Transport implementations should derive
 
210
    from this class.
 
211
    """
 
212
    def __init__(self, msg=None, orig_error=None):
 
213
        if msg is None and orig_error is not None:
 
214
            msg = str(orig_error)
 
215
        BzrError.__init__(self, msg)
 
216
        self.msg = msg
 
217
        self.orig_error = orig_error
 
218
 
 
219
# A set of semi-meaningful errors which can be thrown
 
220
class TransportNotPossible(TransportError):
 
221
    """This is for transports where a specific function is explicitly not
 
222
    possible. Such as pushing files to an HTTP server.
 
223
    """
 
224
    pass
 
225
 
 
226
class NonRelativePath(TransportError):
 
227
    """An absolute path was supplied, that could not be decoded into
 
228
    a relative path.
 
229
    """
 
230
    pass
 
231
 
 
232
class NoSuchFile(TransportError, IOError):
 
233
    """A get() was issued for a file that doesn't exist."""
 
234
 
 
235
    # XXX: Is multiple inheritance for exceptions really needed?
 
236
 
 
237
    def __str__(self):
 
238
        return 'no such file: ' + self.msg
 
239
 
 
240
    def __init__(self, msg=None, orig_error=None):
 
241
        import errno
 
242
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
 
243
        IOError.__init__(self, errno.ENOENT, self.msg)
 
244
 
 
245
class FileExists(TransportError, OSError):
 
246
    """An operation was attempted, which would overwrite an entry,
 
247
    but overwritting is not supported.
 
248
 
 
249
    mkdir() can throw this, but put() just overwites existing files.
 
250
    """
 
251
    # XXX: Is multiple inheritance for exceptions really needed?
 
252
    def __init__(self, msg=None, orig_error=None):
 
253
        import errno
 
254
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
 
255
        OSError.__init__(self, errno.EEXIST, self.msg)
 
256
 
 
257
class PermissionDenied(TransportError):
 
258
    """An operation cannot succeed because of a lack of permissions."""
 
259
    pass
 
260
 
 
261
class ConnectionReset(TransportError):
 
262
    """The connection has been closed."""
 
263
    pass
 
264
 
 
265
class ConflictsInTree(BzrError):
 
266
    def __init__(self):
 
267
        BzrError.__init__(self, "Working tree has conflicts.")