1
by mbp at sourcefrog
import from baz patch-364 |
1 |
# -*- coding: UTF-8 -*-
|
2 |
||
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.
|
|
7 |
||
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.
|
|
12 |
||
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
|
|
16 |
||
17 |
||
18 |
__copyright__ = "Copyright (C) 2005 Canonical Ltd." |
|
19 |
__author__ = "Martin Pool <mbp@canonical.com>" |
|
20 |
||
21 |
||
22 |
######################################################################
|
|
23 |
# exceptions
|
|
24 |
class BzrError(StandardError): |
|
1193
by Martin Pool
- better string formatting of BzrErrors with explanation |
25 |
def __str__(self): |
1393.1.64
by Martin Pool
- improved display of some errors, including NotBranchError |
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 = '' |
|
1195
by Martin Pool
- better error display |
31 |
if len(self.args) == 1: |
1393.1.64
by Martin Pool
- improved display of some errors, including NotBranchError |
32 |
return n + self.args[0] |
1195
by Martin Pool
- better error display |
33 |
elif len(self.args) == 2: |
1193
by Martin Pool
- better string formatting of BzrErrors with explanation |
34 |
# further explanation or suggestions
|
1405
by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave |
35 |
try: |
1393.1.64
by Martin Pool
- improved display of some errors, including NotBranchError |
36 |
return n + '\n '.join([self.args[0]] + self.args[1]) |
1405
by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave |
37 |
except TypeError: |
1393.1.64
by Martin Pool
- improved display of some errors, including NotBranchError |
38 |
return n + "%r" % self |
1193
by Martin Pool
- better string formatting of BzrErrors with explanation |
39 |
else: |
1393.1.64
by Martin Pool
- improved display of some errors, including NotBranchError |
40 |
return n + `self.args` |
1193
by Martin Pool
- better string formatting of BzrErrors with explanation |
41 |
|
1185.1.14
by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD. |
42 |
|
1
by mbp at sourcefrog
import from baz patch-364 |
43 |
class BzrCheckError(BzrError): |
44 |
pass
|
|
45 |
||
46 |
||
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
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 |
||
329
by Martin Pool
- refactor command functions into command classes |
56 |
class BzrCommandError(BzrError): |
57 |
# Error from malformed user command
|
|
1393.1.64
by Martin Pool
- improved display of some errors, including NotBranchError |
58 |
def __str__(self): |
59 |
return self.args[0] |
|
1
by mbp at sourcefrog
import from baz patch-364 |
60 |
|
61 |
||
573
by Martin Pool
- new exception NotBranchError |
62 |
class NotBranchError(BzrError): |
63 |
"""Specified path is not in a branch"""
|
|
1393.1.64
by Martin Pool
- improved display of some errors, including NotBranchError |
64 |
def __str__(self): |
65 |
return 'not a branch: %s' % self.args[0] |
|
573
by Martin Pool
- new exception NotBranchError |
66 |
|
67 |
||
753
by Martin Pool
- new exception NotVersionedError |
68 |
class NotVersionedError(BzrError): |
69 |
"""Specified object is not versioned."""
|
|
70 |
||
71 |
||
599
by Martin Pool
- better error reporting from smart_add |
72 |
class BadFileKindError(BzrError): |
73 |
"""Specified file is of a kind that cannot be added.
|
|
74 |
||
75 |
(For example a symlink or device file.)"""
|
|
76 |
pass
|
|
77 |
||
78 |
||
79 |
class ForbiddenFileError(BzrError): |
|
80 |
"""Cannot operate on a file because it is a control file."""
|
|
81 |
pass
|
|
82 |
||
83 |
||
614
by Martin Pool
- unify two defintions of LockError |
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
|
|
88 |
"""
|
|
89 |
def __init__(self, e=None): |
|
90 |
self.original_error = e |
|
91 |
if e: |
|
92 |
Exception.__init__(self, e) |
|
93 |
else: |
|
94 |
Exception.__init__(self) |
|
882
by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this. |
95 |
|
96 |
||
885
by Martin Pool
- commit command refuses unless something is changed or --unchanged is given |
97 |
class PointlessCommit(Exception): |
882
by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this. |
98 |
"""Commit failed because nothing was changed."""
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
99 |
|
100 |
||
101 |
class NoSuchRevision(BzrError): |
|
102 |
def __init__(self, branch, revision): |
|
103 |
self.branch = branch |
|
104 |
self.revision = revision |
|
105 |
msg = "Branch %s has no revision %s" % (branch, revision) |
|
106 |
BzrError.__init__(self, msg) |
|
107 |
||
1034
by Martin Pool
- merge bzrlib.revision.is_ancestor from aaron |
108 |
|
1192
by Martin Pool
- clean up code for retrieving stored inventories |
109 |
class HistoryMissing(BzrError): |
110 |
def __init__(self, branch, object_type, object_id): |
|
111 |
self.branch = branch |
|
112 |
BzrError.__init__(self, |
|
113 |
'%s is missing %s {%s}' |
|
114 |
% (branch, object_type, object_id)) |
|
115 |
||
116 |
||
1185.2.1
by Lalo Martins
moving DivergedBranches from bzrlib.branch to bzrlib.errors, obeying: |
117 |
class DivergedBranches(BzrError): |
118 |
def __init__(self, branch1, branch2): |
|
1185.1.14
by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD. |
119 |
BzrError.__init__(self, "These branches have diverged.") |
1185.2.1
by Lalo Martins
moving DivergedBranches from bzrlib.branch to bzrlib.errors, obeying: |
120 |
self.branch1 = branch1 |
121 |
self.branch2 = branch2 |
|
122 |
||
1390
by Robert Collins
pair programming worx... merge integration and weave |
123 |
|
1105
by Martin Pool
- expose 'find-merge-base' as a new expert command, |
124 |
class UnrelatedBranches(BzrCommandError): |
125 |
def __init__(self): |
|
126 |
msg = "Branches have no common ancestor, and no base revision"\ |
|
127 |
" specified."
|
|
128 |
BzrCommandError.__init__(self, msg) |
|
129 |
||
974.1.80
by Aaron Bentley
Improved merge error handling and testing |
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) |
|
135 |
||
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) |
|
1105
by Martin Pool
- expose 'find-merge-base' as a new expert command, |
141 |
|
974.2.7
by aaron.bentley at utoronto
Merged from bzr.24 |
142 |
class NotAncestor(BzrError): |
143 |
def __init__(self, rev_id, not_ancestor_id): |
|
1185.1.14
by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD. |
144 |
msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, |
145 |
rev_id) |
|
146 |
BzrError.__init__(self, msg) |
|
147 |
self.rev_id = rev_id |
|
148 |
self.not_ancestor_id = not_ancestor_id |
|
1185.1.12
by Robert Collins
merge in lsdiff/filterdiff friendliness |
149 |
|
150 |
||
1092.3.4
by Robert Collins
update symlink branch to integration |
151 |
class NotAncestor(BzrError): |
152 |
def __init__(self, rev_id, not_ancestor_id): |
|
153 |
self.rev_id = rev_id |
|
154 |
self.not_ancestor_id = not_ancestor_id |
|
155 |
msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, |
|
156 |
rev_id) |
|
157 |
BzrError.__init__(self, msg) |
|
158 |
||
159 |
||
974.1.30
by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions |
160 |
class InstallFailed(BzrError): |
161 |
def __init__(self, revisions): |
|
1185.1.14
by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD. |
162 |
msg = "Could not install revisions:\n%s" % " ,".join(revisions) |
163 |
BzrError.__init__(self, msg) |
|
974.1.30
by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions |
164 |
self.revisions = revisions |
1154
by Martin Pool
- fix imports for moved errors |
165 |
|
166 |
||
167 |
class AmbiguousBase(BzrError): |
|
168 |
def __init__(self, bases): |
|
169 |
msg = "The correct base is unclear, becase %s are all equally close" %\ |
|
170 |
", ".join(bases) |
|
171 |
BzrError.__init__(self, msg) |
|
172 |
self.bases = bases |
|
173 |
||
974.1.80
by Aaron Bentley
Improved merge error handling and testing |
174 |
class NoCommits(BzrError): |
175 |
def __init__(self, branch): |
|
176 |
msg = "Branch %s has no commits." % branch |
|
177 |
BzrError.__init__(self, msg) |
|
1185.10.1
by Aaron Bentley
Added --basis option to bzr branch |
178 |
|
179 |
class UnlistableStore(BzrError): |
|
180 |
def __init__(self, store): |
|
181 |
BzrError.__init__(self, "Store %s is not listable" % store) |
|
182 |
||
183 |
class UnlistableBranch(BzrError): |
|
184 |
def __init__(self, br): |
|
185 |
BzrError.__init__(self, "Stores for branch %s are not listable" % br) |
|
1392
by Robert Collins
reinstate testfetch test case |
186 |
|
187 |
||
188 |
from bzrlib.weave import WeaveError |
|
1393.2.1
by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still. |
189 |
|
1185.11.9
by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv |
190 |
class TransportError(BzrError): |
191 |
"""All errors thrown by Transport implementations should derive
|
|
192 |
from this class.
|
|
193 |
"""
|
|
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) |
|
198 |
self.msg = msg |
|
199 |
self.orig_error = orig_error |
|
200 |
||
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.
|
|
205 |
"""
|
|
206 |
pass
|
|
207 |
||
208 |
class NonRelativePath(TransportError): |
|
209 |
"""An absolute path was supplied, that could not be decoded into
|
|
210 |
a relative path.
|
|
211 |
"""
|
|
212 |
pass
|
|
213 |
||
214 |
class NoSuchFile(TransportError, IOError): |
|
215 |
"""A get() was issued for a file that doesn't exist."""
|
|
1405
by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave |
216 |
|
1393.1.64
by Martin Pool
- improved display of some errors, including NotBranchError |
217 |
# XXX: Is multiple inheritance for exceptions really needed?
|
218 |
||
1405
by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave |
219 |
def __str__(self): |
1393.1.64
by Martin Pool
- improved display of some errors, including NotBranchError |
220 |
return 'no such file: ' + self.msg |
1405
by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave |
221 |
|
1185.11.9
by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv |
222 |
def __init__(self, msg=None, orig_error=None): |
223 |
import errno |
|
224 |
TransportError.__init__(self, msg=msg, orig_error=orig_error) |
|
225 |
IOError.__init__(self, errno.ENOENT, self.msg) |
|
226 |
||
227 |
class FileExists(TransportError, OSError): |
|
228 |
"""An operation was attempted, which would overwrite an entry,
|
|
229 |
but overwritting is not supported.
|
|
230 |
||
231 |
mkdir() can throw this, but put() just overwites existing files.
|
|
232 |
"""
|
|
1393.1.64
by Martin Pool
- improved display of some errors, including NotBranchError |
233 |
# XXX: Is multiple inheritance for exceptions really needed?
|
1185.11.9
by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv |
234 |
def __init__(self, msg=None, orig_error=None): |
235 |
import errno |
|
236 |
TransportError.__init__(self, msg=msg, orig_error=orig_error) |
|
237 |
OSError.__init__(self, errno.EEXIST, self.msg) |
|
238 |
||
239 |
class PermissionDenied(TransportError): |
|
240 |
"""An operation cannot succeed because of a lack of permissions."""
|
|
241 |
pass
|
|
242 |
||
243 |
class ConnectionReset(TransportError): |
|
244 |
"""The connection has been closed."""
|
|
245 |
pass
|
|
246 |