18
19
__copyright__ = "Copyright (C) 2005 Canonical Ltd."
19
20
__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
33
23
######################################################################
35
25
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__ + ': '
42
if len(self.args) == 1:
43
return str(self.args[0])
44
elif len(self.args) == 2:
45
# further explanation or suggestions
47
return n + '\n '.join([self.args[0]] + self.args[1])
49
return n + "%r" % self
51
return n + `self.args`
54
28
class BzrCheckError(BzrError):
58
class InvalidRevisionNumber(BzrError):
60
return 'invalid revision number: %r' % self.args[0]
63
class InvalidRevisionId(BzrError):
67
class BzrCommandError(BzrError):
68
# Error from malformed user command
73
class NotBranchError(BzrError):
74
"""Specified path is not in a branch"""
76
return 'not a branch: %s' % self.args[0]
79
class UnsupportedFormatError(BzrError):
80
"""Specified path is a bzr branch that we cannot read."""
82
return 'unsupported branch format: %s' % self.args[0]
85
class NotVersionedError(BzrError):
86
"""Specified object is not versioned."""
89
class BadFileKindError(BzrError):
90
"""Specified file is of a kind that cannot be added.
92
(For example a symlink or device file.)"""
96
class ForbiddenFileError(BzrError):
97
"""Cannot operate on a file because it is a control file."""
101
class LockError(Exception):
102
"""All exceptions from the lock/unlock functions should be from
103
this exception class. They will be translated as necessary. The
104
original exception is available as e.original_error
106
def __init__(self, e=None):
107
self.original_error = e
109
Exception.__init__(self, e)
111
Exception.__init__(self)
114
class CommitNotPossible(LockError):
115
"""A commit was attempted but we do not have a write lock open."""
118
class AlreadyCommitted(LockError):
119
"""A rollback was requested, but is not able to be accomplished."""
122
class ReadOnlyError(LockError):
123
"""A write attempt was made in a read only transaction."""
126
class PointlessCommit(Exception):
127
"""Commit failed because nothing was changed."""
130
class NoSuchRevision(BzrError):
131
def __init__(self, branch, revision):
133
self.revision = revision
134
msg = "Branch %s has no revision %s" % (branch, revision)
135
BzrError.__init__(self, msg)
138
class HistoryMissing(BzrError):
139
def __init__(self, branch, object_type, object_id):
141
BzrError.__init__(self,
142
'%s is missing %s {%s}'
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
153
class UnrelatedBranches(BzrCommandError):
155
msg = "Branches have no common ancestor, and no base revision"\
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
180
class NotAncestor(BzrError):
181
def __init__(self, rev_id, not_ancestor_id):
183
self.not_ancestor_id = not_ancestor_id
184
msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id,
186
BzrError.__init__(self, msg)
189
class InstallFailed(BzrError):
190
def __init__(self, revisions):
191
msg = "Could not install revisions:\n%s" % " ,".join(revisions)
192
BzrError.__init__(self, msg)
193
self.revisions = revisions
196
class AmbiguousBase(BzrError):
197
def __init__(self, bases):
198
msg = "The correct base is unclear, becase %s are all equally close" %\
200
BzrError.__init__(self, msg)
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.")
34
def bailout(msg, explanation=[]):
35
ex = BzrError(msg, explanation)
37
trace._tracefile.write('* raising %s\n' % ex)