23
22
######################################################################
25
24
class BzrError(StandardError):
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__ + ': '
31
if len(self.args) == 1:
32
return n + self.args[0]
33
elif len(self.args) == 2:
34
# further explanation or suggestions
36
return n + '\n '.join([self.args[0]] + self.args[1])
38
return n + "%r" % self
40
return n + `self.args`
28
43
class BzrCheckError(BzrError):
47
class InvalidRevisionNumber(BzrError):
49
return 'invalid revision number: %r' % self.args[0]
52
class InvalidRevisionId(BzrError):
32
56
class BzrCommandError(BzrError):
33
57
# Error from malformed user command
37
def bailout(msg, explanation=[]):
38
ex = BzrError(msg, explanation)
40
trace._tracefile.write('* raising %s\n' % ex)
62
class NotBranchError(BzrError):
63
"""Specified path is not in a branch"""
65
return 'not a branch: %s' % self.args[0]
68
class NotVersionedError(BzrError):
69
"""Specified object is not versioned."""
72
class BadFileKindError(BzrError):
73
"""Specified file is of a kind that cannot be added.
75
(For example a symlink or device file.)"""
79
class ForbiddenFileError(BzrError):
80
"""Cannot operate on a file because it is a control file."""
84
class LockError(Exception):
85
"""All exceptions from the lock/unlock functions should be from
86
this exception class. They will be translated as necessary. The
87
original exception is available as e.original_error
89
def __init__(self, e=None):
90
self.original_error = e
92
Exception.__init__(self, e)
94
Exception.__init__(self)
97
class PointlessCommit(Exception):
98
"""Commit failed because nothing was changed."""
101
class NoSuchRevision(BzrError):
102
def __init__(self, branch, revision):
104
self.revision = revision
105
msg = "Branch %s has no revision %s" % (branch, revision)
106
BzrError.__init__(self, msg)
109
class HistoryMissing(BzrError):
110
def __init__(self, branch, object_type, object_id):
112
BzrError.__init__(self,
113
'%s is missing %s {%s}'
114
% (branch, object_type, object_id))
117
class DivergedBranches(BzrError):
118
def __init__(self, branch1, branch2):
119
BzrError.__init__(self, "These branches have diverged.")
120
self.branch1 = branch1
121
self.branch2 = branch2
124
class UnrelatedBranches(BzrCommandError):
126
msg = "Branches have no common ancestor, and no base revision"\
128
BzrCommandError.__init__(self, msg)
130
class NoCommonAncestor(BzrError):
131
def __init__(self, revision_a, revision_b):
132
msg = "Revisions have no common ancestor: %s %s." \
133
% (revision_a, revision_b)
134
BzrError.__init__(self, msg)
136
class NoCommonRoot(BzrError):
137
def __init__(self, revision_a, revision_b):
138
msg = "Revisions are not derived from the same root: %s %s." \
139
% (revision_a, revision_b)
140
BzrError.__init__(self, msg)
142
class NotAncestor(BzrError):
143
def __init__(self, rev_id, not_ancestor_id):
144
msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id,
146
BzrError.__init__(self, msg)
148
self.not_ancestor_id = not_ancestor_id
151
class NotAncestor(BzrError):
152
def __init__(self, rev_id, not_ancestor_id):
154
self.not_ancestor_id = not_ancestor_id
155
msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id,
157
BzrError.__init__(self, msg)
160
class InstallFailed(BzrError):
161
def __init__(self, revisions):
162
msg = "Could not install revisions:\n%s" % " ,".join(revisions)
163
BzrError.__init__(self, msg)
164
self.revisions = revisions
167
class AmbiguousBase(BzrError):
168
def __init__(self, bases):
169
msg = "The correct base is unclear, becase %s are all equally close" %\
171
BzrError.__init__(self, msg)
174
class NoCommits(BzrError):
175
def __init__(self, branch):
176
msg = "Branch %s has no commits." % branch
177
BzrError.__init__(self, msg)
179
class UnlistableStore(BzrError):
180
def __init__(self, store):
181
BzrError.__init__(self, "Store %s is not listable" % store)
183
class UnlistableBranch(BzrError):
184
def __init__(self, br):
185
BzrError.__init__(self, "Stores for branch %s are not listable" % br)
188
from bzrlib.weave import WeaveError
190
class TransportError(BzrError):
191
"""All errors thrown by Transport implementations should derive
194
def __init__(self, msg=None, orig_error=None):
195
if msg is None and orig_error is not None:
196
msg = str(orig_error)
197
BzrError.__init__(self, msg)
199
self.orig_error = orig_error
201
# A set of semi-meaningful errors which can be thrown
202
class TransportNotPossible(TransportError):
203
"""This is for transports where a specific function is explicitly not
204
possible. Such as pushing files to an HTTP server.
208
class NonRelativePath(TransportError):
209
"""An absolute path was supplied, that could not be decoded into
214
class NoSuchFile(TransportError, IOError):
215
"""A get() was issued for a file that doesn't exist."""
217
# XXX: Is multiple inheritance for exceptions really needed?
220
return 'no such file: ' + self.msg
222
def __init__(self, msg=None, orig_error=None):
224
TransportError.__init__(self, msg=msg, orig_error=orig_error)
225
IOError.__init__(self, errno.ENOENT, self.msg)
227
class FileExists(TransportError, OSError):
228
"""An operation was attempted, which would overwrite an entry,
229
but overwritting is not supported.
231
mkdir() can throw this, but put() just overwites existing files.
233
# XXX: Is multiple inheritance for exceptions really needed?
234
def __init__(self, msg=None, orig_error=None):
236
TransportError.__init__(self, msg=msg, orig_error=orig_error)
237
OSError.__init__(self, errno.EEXIST, self.msg)
239
class PermissionDenied(TransportError):
240
"""An operation cannot succeed because of a lack of permissions."""
243
class ConnectionReset(TransportError):
244
"""The connection has been closed."""