1
# -*- coding: UTF-8 -*-
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
__copyright__ = "Copyright (C) 2005 Canonical Ltd."
19
__author__ = "Martin Pool <mbp@canonical.com>"
22
######################################################################
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`
43
class BzrCheckError(BzrError):
47
class InvalidRevisionNumber(BzrError):
49
return 'invalid revision number: %r' % self.args[0]
52
class InvalidRevisionId(BzrError):
56
class BzrCommandError(BzrError):
57
# Error from malformed user command
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 CommitNotPossible(LockError):
98
"""A commit was attempted but we do not have a write lock open."""
101
class AlreadyCommitted(LockError):
102
"""A rollback was requested, but is not able to be accomplished."""
105
class PointlessCommit(Exception):
106
"""Commit failed because nothing was changed."""
109
class NoSuchRevision(BzrError):
110
def __init__(self, branch, revision):
112
self.revision = revision
113
msg = "Branch %s has no revision %s" % (branch, revision)
114
BzrError.__init__(self, msg)
117
class HistoryMissing(BzrError):
118
def __init__(self, branch, object_type, object_id):
120
BzrError.__init__(self,
121
'%s is missing %s {%s}'
122
% (branch, object_type, object_id))
125
class DivergedBranches(BzrError):
126
def __init__(self, branch1, branch2):
127
BzrError.__init__(self, "These branches have diverged.")
128
self.branch1 = branch1
129
self.branch2 = branch2
132
class UnrelatedBranches(BzrCommandError):
134
msg = "Branches have no common ancestor, and no base revision"\
136
BzrCommandError.__init__(self, msg)
138
class NoCommonAncestor(BzrError):
139
def __init__(self, revision_a, revision_b):
140
msg = "Revisions have no common ancestor: %s %s." \
141
% (revision_a, revision_b)
142
BzrError.__init__(self, msg)
144
class NoCommonRoot(BzrError):
145
def __init__(self, revision_a, revision_b):
146
msg = "Revisions are not derived from the same root: %s %s." \
147
% (revision_a, revision_b)
148
BzrError.__init__(self, msg)
150
class NotAncestor(BzrError):
151
def __init__(self, rev_id, not_ancestor_id):
152
msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id,
154
BzrError.__init__(self, msg)
156
self.not_ancestor_id = not_ancestor_id
159
class NotAncestor(BzrError):
160
def __init__(self, rev_id, not_ancestor_id):
162
self.not_ancestor_id = not_ancestor_id
163
msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id,
165
BzrError.__init__(self, msg)
168
class InstallFailed(BzrError):
169
def __init__(self, revisions):
170
msg = "Could not install revisions:\n%s" % " ,".join(revisions)
171
BzrError.__init__(self, msg)
172
self.revisions = revisions
175
class AmbiguousBase(BzrError):
176
def __init__(self, bases):
177
msg = "The correct base is unclear, becase %s are all equally close" %\
179
BzrError.__init__(self, msg)
182
class NoCommits(BzrError):
183
def __init__(self, branch):
184
msg = "Branch %s has no commits." % branch
185
BzrError.__init__(self, msg)
187
class UnlistableStore(BzrError):
188
def __init__(self, store):
189
BzrError.__init__(self, "Store %s is not listable" % store)
191
class UnlistableBranch(BzrError):
192
def __init__(self, br):
193
BzrError.__init__(self, "Stores for branch %s are not listable" % br)
196
from bzrlib.weave import WeaveError
198
class TransportError(BzrError):
199
"""All errors thrown by Transport implementations should derive
202
def __init__(self, msg=None, orig_error=None):
203
if msg is None and orig_error is not None:
204
msg = str(orig_error)
205
BzrError.__init__(self, msg)
207
self.orig_error = orig_error
209
# A set of semi-meaningful errors which can be thrown
210
class TransportNotPossible(TransportError):
211
"""This is for transports where a specific function is explicitly not
212
possible. Such as pushing files to an HTTP server.
216
class NonRelativePath(TransportError):
217
"""An absolute path was supplied, that could not be decoded into
222
class NoSuchFile(TransportError, IOError):
223
"""A get() was issued for a file that doesn't exist."""
225
# XXX: Is multiple inheritance for exceptions really needed?
228
return 'no such file: ' + self.msg
230
def __init__(self, msg=None, orig_error=None):
232
TransportError.__init__(self, msg=msg, orig_error=orig_error)
233
IOError.__init__(self, errno.ENOENT, self.msg)
235
class FileExists(TransportError, OSError):
236
"""An operation was attempted, which would overwrite an entry,
237
but overwritting is not supported.
239
mkdir() can throw this, but put() just overwites existing files.
241
# XXX: Is multiple inheritance for exceptions really needed?
242
def __init__(self, msg=None, orig_error=None):
244
TransportError.__init__(self, msg=msg, orig_error=orig_error)
245
OSError.__init__(self, errno.EEXIST, self.msg)
247
class PermissionDenied(TransportError):
248
"""An operation cannot succeed because of a lack of permissions."""
251
class ConnectionReset(TransportError):
252
"""The connection has been closed."""
255
class ConflictsInTree(BzrError):
257
BzrError.__init__(self, "Working tree has conflicts.")