19
18
__copyright__ = "Copyright (C) 2005 Canonical Ltd."
20
19
__author__ = "Martin Pool <mbp@canonical.com>"
21
# TODO: Change to a standard exception pattern:
23
# - docstring of exceptions is a template for formatting the exception
24
# so the __str__ method can be defined only in the superclass
25
# - the arguments to the exception are interpolated into this string
27
# when printing the exception we'd then require special handling only
28
# for built-in exceptions with no decent __str__ method, such as
29
# ValueError and AssertionError. See
30
# scott@canonical.com--2005/hct--devel--0.10 util/errors.py
23
33
######################################################################
25
35
class BzrError(StandardError):
37
# XXX: Should we show the exception class in
38
# exceptions that don't provide their own message?
39
# maybe it should be done at a higher level
40
## n = self.__class__.__name__ + ': '
27
42
if len(self.args) == 1:
43
return str(self.args[0])
29
44
elif len(self.args) == 2:
30
45
# further explanation or suggestions
31
return '\n '.join([self.args[0]] + self.args[1])
47
return n + '\n '.join([self.args[0]] + self.args[1])
49
return n + "%r" % self
51
return n + `self.args`
36
54
class BzrCheckError(BzrError):
108
143
% (branch, object_type, object_id))
146
class DivergedBranches(BzrError):
147
def __init__(self, branch1, branch2):
148
BzrError.__init__(self, "These branches have diverged.")
149
self.branch1 = branch1
150
self.branch2 = branch2
111
153
class UnrelatedBranches(BzrCommandError):
112
154
def __init__(self):
113
155
msg = "Branches have no common ancestor, and no base revision"\
115
157
BzrCommandError.__init__(self, msg)
159
class NoCommonAncestor(BzrError):
160
def __init__(self, revision_a, revision_b):
161
msg = "Revisions have no common ancestor: %s %s." \
162
% (revision_a, revision_b)
163
BzrError.__init__(self, msg)
165
class NoCommonRoot(BzrError):
166
def __init__(self, revision_a, revision_b):
167
msg = "Revisions are not derived from the same root: %s %s." \
168
% (revision_a, revision_b)
169
BzrError.__init__(self, msg)
171
class NotAncestor(BzrError):
172
def __init__(self, rev_id, not_ancestor_id):
173
msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id,
175
BzrError.__init__(self, msg)
177
self.not_ancestor_id = not_ancestor_id
118
180
class NotAncestor(BzrError):
119
181
def __init__(self, rev_id, not_ancestor_id):
138
200
BzrError.__init__(self, msg)
139
201
self.bases = bases
203
class NoCommits(BzrError):
204
def __init__(self, branch):
205
msg = "Branch %s has no commits." % branch
206
BzrError.__init__(self, msg)
208
class UnlistableStore(BzrError):
209
def __init__(self, store):
210
BzrError.__init__(self, "Store %s is not listable" % store)
212
class UnlistableBranch(BzrError):
213
def __init__(self, br):
214
BzrError.__init__(self, "Stores for branch %s are not listable" % br)
217
from bzrlib.weave import WeaveError, WeaveParentMismatch
219
class TransportError(BzrError):
220
"""All errors thrown by Transport implementations should derive
223
def __init__(self, msg=None, orig_error=None):
224
if msg is None and orig_error is not None:
225
msg = str(orig_error)
226
BzrError.__init__(self, msg)
228
self.orig_error = orig_error
230
# A set of semi-meaningful errors which can be thrown
231
class TransportNotPossible(TransportError):
232
"""This is for transports where a specific function is explicitly not
233
possible. Such as pushing files to an HTTP server.
237
class NonRelativePath(TransportError):
238
"""An absolute path was supplied, that could not be decoded into
243
class NoSuchFile(TransportError, IOError):
244
"""A get() was issued for a file that doesn't exist."""
246
# XXX: Is multiple inheritance for exceptions really needed?
249
return 'no such file: ' + self.msg
251
def __init__(self, msg=None, orig_error=None):
253
TransportError.__init__(self, msg=msg, orig_error=orig_error)
254
IOError.__init__(self, errno.ENOENT, self.msg)
256
class FileExists(TransportError, OSError):
257
"""An operation was attempted, which would overwrite an entry,
258
but overwritting is not supported.
260
mkdir() can throw this, but put() just overwites existing files.
262
# XXX: Is multiple inheritance for exceptions really needed?
263
def __init__(self, msg=None, orig_error=None):
265
TransportError.__init__(self, msg=msg, orig_error=orig_error)
266
OSError.__init__(self, errno.EEXIST, self.msg)
268
class PermissionDenied(TransportError):
269
"""An operation cannot succeed because of a lack of permissions."""
272
class ConnectionReset(TransportError):
273
"""The connection has been closed."""
276
class ConflictsInTree(BzrError):
278
BzrError.__init__(self, "Working tree has conflicts.")
280
class ParseConfigError(BzrError):
281
def __init__(self, errors, filename):
284
message = "Error(s) parsing config file %s:\n%s" % \
285
(filename, ('\n'.join(e.message for e in errors)))
286
BzrError.__init__(self, message)
288
class SigningFailed(BzrError):
289
def __init__(self, command_line):
290
BzrError.__init__(self, "Failed to gpg sign data with command '%s'"