58
34
# constructed to make sure it will succeed. But that says nothing about
59
35
# exceptions that are never raised.
61
# TODO: Convert all the other error classes here to BzrNewError, and eliminate
37
# TODO: selftest assertRaises should probably also check that every error
38
# raised can be formatted as a string successfully, and without giving
65
42
class BzrError(StandardError):
44
Base class for errors raised by bzrlib.
46
:cvar internal_error: if true (or absent) this was probably caused by a
47
bzr bug and should be displayed with a traceback; if False this was
48
probably a user or environment error and they don't need the gory details.
49
(That can be overridden by -Derror on the command line.)
51
:cvar _fmt: Format string to display the error; this is expanded
52
by the instance's dict.
55
internal_error = False
57
def __init__(self, msg=None, **kwds):
58
"""Construct a new BzrError.
60
There are two alternative forms for constructing these objects.
61
Either a preformatted string may be passed, or a set of named
62
arguments can be given. The first is for generic "user" errors which
63
are not intended to be caught and so do not need a specific subclass.
64
The second case is for use with subclasses that provide a _fmt format
65
string to print the arguments.
67
Keyword arguments are taken as parameters to the error, which can
68
be inserted into the format string template. It's recommended
69
that subclasses override the __init__ method to require specific
72
:param msg: If given, this is the literal complete text for the error,
73
not subject to expansion.
75
StandardError.__init__(self)
77
## symbol_versioning.warn(
78
## 'constructing a BzrError from a string was deprecated '
79
## 'in bzr 0.12; please raise a specific subclass instead',
80
## DeprecationWarning,
82
self._preformatted_string = msg
84
self._preformatted_string = None
85
for key, value in kwds.items():
86
setattr(self, key, value)
67
# XXX: Should we show the exception class in
68
# exceptions that don't provide their own message?
69
# maybe it should be done at a higher level
70
## n = self.__class__.__name__ + ': '
72
if len(self.args) == 1:
73
return str(self.args[0])
74
elif len(self.args) == 2:
75
# further explanation or suggestions
77
return n + '\n '.join([self.args[0]] + self.args[1])
79
return n + "%r" % self
81
return n + `self.args`
89
s = getattr(self, '_preformatted_string', None)
91
# contains a preformatted message; must be cast to plain str
94
fmt = self._get_format_string()
96
s = fmt % self.__dict__
97
# __str__() should always return a 'str' object
98
# never a 'unicode' object.
99
if isinstance(s, unicode):
100
return s.encode('utf8')
102
except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
103
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
104
% (self.__class__.__name__,
106
getattr(self, '_fmt', None),
109
def _get_format_string(self):
110
"""Return format string for this exception or None"""
111
fmt = getattr(self, '_fmt', None)
114
fmt = getattr(self, '__doc__', None)
116
symbol_versioning.warn("%s uses its docstring as a format, "
117
"it should use _fmt instead" % self.__class__.__name__,
119
# TODO: This should be deprecated when all exceptions have
120
# been changed not to rely on this.
122
return 'Unprintable exception %s: dict=%r, fmt=%r' \
123
% (self.__class__.__name__,
125
getattr(self, '_fmt', None),
84
129
class BzrNewError(BzrError):
130
"""Deprecated error base class."""
86
131
# base classes should override the docstring with their human-
87
132
# readable explanation
89
def __init__(self, **kwds):
134
def __init__(self, *args, **kwds):
135
# XXX: Use the underlying BzrError to always generate the args attribute
136
# if it doesn't exist. We can't use super here, because exceptions are
137
# old-style classes in python2.4 (but new in 2.5). --bmc, 20060426
138
symbol_versioning.warn('BzrNewError was deprecated in bzr 0.12; '
139
'please convert %s to use BzrError instead'
140
% self.__class__.__name__,
143
BzrError.__init__(self, *args)
90
144
for key, value in kwds.items():
91
145
setattr(self, key, value)
93
147
def __str__(self):
95
return self.__doc__ % self.__dict__
96
except (NameError, ValueError, KeyError), e:
97
return 'Unprintable exception %s: %s' \
98
% (self.__class__.__name__, str(e))
101
class BzrCheckError(BzrNewError):
102
"""Internal check failed: %(message)s"""
149
# __str__() should always return a 'str' object
150
# never a 'unicode' object.
151
s = self.__doc__ % self.__dict__
152
if isinstance(s, unicode):
153
return s.encode('utf8')
155
except (TypeError, NameError, ValueError, KeyError), e:
156
return 'Unprintable exception %s(%r): %s' \
157
% (self.__class__.__name__,
158
self.__dict__, str(e))
161
class AlreadyBuilding(BzrError):
163
_fmt = "The tree builder is already building a tree."
166
class BzrCheckError(BzrError):
168
_fmt = "Internal check failed: %(message)s"
170
internal_error = True
103
172
def __init__(self, message):
173
BzrError.__init__(self)
104
174
self.message = message
107
class InvalidEntryName(BzrNewError):
108
"""Invalid entry name: %(name)s"""
177
class InvalidEntryName(BzrError):
179
_fmt = "Invalid entry name: %(name)s"
181
internal_error = True
109
183
def __init__(self, name):
184
BzrError.__init__(self)
113
class InvalidRevisionNumber(BzrNewError):
114
"""Invalid revision number %(revno)d"""
188
class InvalidRevisionNumber(BzrError):
190
_fmt = "Invalid revision number %(revno)s"
115
192
def __init__(self, revno):
193
BzrError.__init__(self)
116
194
self.revno = revno
119
class InvalidRevisionId(BzrNewError):
120
"""Invalid revision-id"""
197
class InvalidRevisionId(BzrError):
199
_fmt = "Invalid revision-id {%(revision_id)s} in %(branch)s"
201
def __init__(self, revision_id, branch):
202
# branch can be any string or object with __str__ defined
203
BzrError.__init__(self)
204
self.revision_id = revision_id
208
class NoSuchId(BzrError):
210
_fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
212
def __init__(self, tree, file_id):
213
BzrError.__init__(self)
214
self.file_id = file_id
218
class InventoryModified(BzrError):
220
_fmt = ("The current inventory for the tree %(tree)r has been modified, "
221
"so a clean inventory cannot be read without data loss.")
223
internal_error = True
225
def __init__(self, tree):
229
class NoWorkingTree(BzrError):
231
_fmt = "No WorkingTree exists for %(base)s."
233
def __init__(self, base):
234
BzrError.__init__(self)
238
class NotBuilding(BzrError):
240
_fmt = "Not currently building a tree."
243
class NotLocalUrl(BzrError):
245
_fmt = "%(url)s is not a local path."
247
def __init__(self, url):
251
class WorkingTreeAlreadyPopulated(BzrError):
253
_fmt = """Working tree already populated in %(base)s"""
255
internal_error = True
257
def __init__(self, base):
123
260
class BzrCommandError(BzrError):
124
# Error from malformed user command
261
"""Error from user command"""
263
internal_error = False
265
# Error from malformed user command; please avoid raising this as a
266
# generic exception not caused by user input.
268
# I think it's a waste of effort to differentiate between errors that
269
# are not intended to be caught anyway. UI code need not subclass
270
# BzrCommandError, and non-UI code should not throw a subclass of
271
# BzrCommandError. ADHB 20051211
272
def __init__(self, msg):
273
# Object.__str__() must return a real string
274
# returning a Unicode string is a python error.
275
if isinstance(msg, unicode):
276
self.msg = msg.encode('utf8')
125
280
def __str__(self):
128
class StrictCommitFailed(Exception):
129
"""Commit refused because there are unknowns in the tree."""
131
class NotBranchError(BzrNewError):
132
"""Not a branch: %(path)s"""
284
class NotWriteLocked(BzrError):
286
_fmt = """%(not_locked)r is not write locked but needs to be."""
288
def __init__(self, not_locked):
289
self.not_locked = not_locked
292
class BzrOptionError(BzrCommandError):
294
_fmt = "Error in command line options"
297
class StrictCommitFailed(BzrError):
299
_fmt = "Commit refused because there are unknown files in the tree"
302
# XXX: Should be unified with TransportError; they seem to represent the
304
class PathError(BzrError):
306
_fmt = "Generic path error: %(path)r%(extra)s)"
308
def __init__(self, path, extra=None):
309
BzrError.__init__(self)
312
self.extra = ': ' + str(extra)
317
class NoSuchFile(PathError):
319
_fmt = "No such file: %(path)r%(extra)s"
322
class FileExists(PathError):
324
_fmt = "File exists: %(path)r%(extra)s"
327
class DirectoryNotEmpty(PathError):
329
_fmt = "Directory not empty: %(path)r%(extra)s"
332
class ReadingCompleted(BzrError):
334
_fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
335
"called upon it - the request has been completed and no more "
338
internal_error = True
340
def __init__(self, request):
341
self.request = request
344
class ResourceBusy(PathError):
346
_fmt = "Device or resource busy: %(path)r%(extra)s"
349
class PermissionDenied(PathError):
351
_fmt = "Permission denied: %(path)r%(extra)s"
354
class InvalidURL(PathError):
356
_fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
359
class InvalidURLJoin(PathError):
361
_fmt = "Invalid URL join request: %(args)s%(extra)s"
363
def __init__(self, msg, base, args):
364
PathError.__init__(self, base, msg)
365
self.args = [base] + list(args)
368
class UnsupportedProtocol(PathError):
370
_fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
372
def __init__(self, url, extra):
373
PathError.__init__(self, url, extra=extra)
376
class ShortReadvError(PathError):
378
_fmt = "readv() read %(actual)s bytes rather than %(length)s bytes at %(offset)s for %(path)s%(extra)s"
380
internal_error = True
382
def __init__(self, path, offset, length, actual, extra=None):
383
PathError.__init__(self, path, extra=extra)
389
class PathNotChild(BzrError):
391
_fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
393
internal_error = True
395
def __init__(self, path, base, extra=None):
396
BzrError.__init__(self)
400
self.extra = ': ' + str(extra)
405
class InvalidNormalization(PathError):
407
_fmt = "Path %(path)r is not unicode normalized"
410
# TODO: This is given a URL; we try to unescape it but doing that from inside
411
# the exception object is a bit undesirable.
412
# TODO: Probably this behavior of should be a common superclass
413
class NotBranchError(PathError):
415
_fmt = "Not a branch: %(path)s"
133
417
def __init__(self, path):
134
BzrNewError.__init__(self)
418
import bzrlib.urlutils as urlutils
419
self.path = urlutils.unescape_for_display(path, 'ascii')
422
class AlreadyBranchError(PathError):
424
_fmt = "Already a branch: %(path)s."
427
class BranchExistsWithoutWorkingTree(PathError):
429
_fmt = "Directory contains a branch, but no working tree \
430
(use bzr checkout if you wish to build a working tree): %(path)s"
433
class AtomicFileAlreadyClosed(PathError):
435
_fmt = "'%(function)s' called on an AtomicFile after it was closed: %(path)s"
437
def __init__(self, path, function):
438
PathError.__init__(self, path=path, extra=None)
439
self.function = function
442
class InaccessibleParent(PathError):
444
_fmt = "Parent not accessible given base %(base)s and relative path %(path)s"
446
def __init__(self, path, base):
447
PathError.__init__(self, path)
451
class NoRepositoryPresent(BzrError):
453
_fmt = "No repository present: %(path)r"
454
def __init__(self, bzrdir):
455
BzrError.__init__(self)
456
self.path = bzrdir.transport.clone('..').base
459
class FileInWrongBranch(BzrError):
461
_fmt = "File %(path)s in not in branch %(branch_base)s."
463
def __init__(self, branch, path):
464
BzrError.__init__(self)
466
self.branch_base = branch.base
138
470
class UnsupportedFormatError(BzrError):
139
"""Specified path is a bzr branch that we cannot read."""
141
return 'unsupported branch format: %s' % self.args[0]
144
class NotVersionedError(BzrNewError):
145
"""%(path)s is not versioned"""
472
_fmt = "Unsupported branch format: %(format)s"
475
class UnknownFormatError(BzrError):
477
_fmt = "Unknown branch format: %(format)r"
480
class IncompatibleFormat(BzrError):
482
_fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
484
def __init__(self, format, bzrdir_format):
485
BzrError.__init__(self)
487
self.bzrdir = bzrdir_format
490
class IncompatibleRevision(BzrError):
492
_fmt = "Revision is not compatible with %(repo_format)s"
494
def __init__(self, repo_format):
495
BzrError.__init__(self)
496
self.repo_format = repo_format
499
class NotVersionedError(BzrError):
501
_fmt = "%(path)s is not versioned"
146
503
def __init__(self, path):
147
BzrNewError.__init__(self)
504
BzrError.__init__(self)
508
class PathsNotVersionedError(BzrError):
509
# used when reporting several paths are not versioned
511
_fmt = "Path(s) are not versioned: %(paths_as_string)s"
513
def __init__(self, paths):
514
from bzrlib.osutils import quotefn
515
BzrError.__init__(self)
517
self.paths_as_string = ' '.join([quotefn(p) for p in paths])
520
class PathsDoNotExist(BzrError):
522
_fmt = "Path(s) do not exist: %(paths_as_string)s"
524
# used when reporting that paths are neither versioned nor in the working
527
def __init__(self, paths):
529
from bzrlib.osutils import quotefn
530
BzrError.__init__(self)
532
self.paths_as_string = ' '.join([quotefn(p) for p in paths])
151
535
class BadFileKindError(BzrError):
152
"""Specified file is of a kind that cannot be added.
154
(For example a symlink or device file.)"""
157
class ForbiddenFileError(BzrError):
158
"""Cannot operate on a file because it is a control file."""
161
class LockError(Exception):
537
_fmt = "Cannot operate on %(filename)s of unsupported kind %(kind)s"
540
class ForbiddenControlFileError(BzrError):
542
_fmt = "Cannot operate on %(filename)s because it is a control file"
545
class LockError(BzrError):
547
_fmt = "Lock error: %(message)s"
163
549
# All exceptions from the lock/unlock functions should be from
164
550
# this exception class. They will be translated as necessary. The
165
551
# original exception is available as e.original_error
553
# New code should prefer to raise specific subclasses
554
def __init__(self, message):
555
self.message = message
168
558
class CommitNotPossible(LockError):
169
"""A commit was attempted but we do not have a write lock open."""
560
_fmt = "A commit was attempted but we do not have a write lock open."
172
566
class AlreadyCommitted(LockError):
173
"""A rollback was requested, but is not able to be accomplished."""
568
_fmt = "A rollback was requested, but is not able to be accomplished."
176
574
class ReadOnlyError(LockError):
177
"""A write attempt was made in a read only transaction."""
180
class PointlessCommit(BzrNewError):
181
"""No changes to commit"""
576
_fmt = "A write attempt was made in a read only transaction on %(obj)s"
578
def __init__(self, obj):
582
class OutSideTransaction(BzrError):
584
_fmt = "A transaction related operation was attempted after the transaction finished."
587
class ObjectNotLocked(LockError):
589
_fmt = "%(obj)r is not locked"
591
internal_error = True
593
# this can indicate that any particular object is not locked; see also
594
# LockNotHeld which means that a particular *lock* object is not held by
595
# the caller -- perhaps they should be unified.
596
def __init__(self, obj):
600
class ReadOnlyObjectDirtiedError(ReadOnlyError):
602
_fmt = "Cannot change object %(obj)r in read only transaction"
604
def __init__(self, obj):
608
class UnlockableTransport(LockError):
610
_fmt = "Cannot lock: transport is read only: %(transport)s"
612
def __init__(self, transport):
613
self.transport = transport
616
class LockContention(LockError):
618
_fmt = "Could not acquire lock %(lock)s"
619
# TODO: show full url for lock, combining the transport and relative bits?
621
def __init__(self, lock):
625
class LockBroken(LockError):
627
_fmt = "Lock was broken while still open: %(lock)s - check storage consistency!"
629
def __init__(self, lock):
633
class LockBreakMismatch(LockError):
635
_fmt = "Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"
637
def __init__(self, lock, holder, target):
643
class LockNotHeld(LockError):
645
_fmt = "Lock not held: %(lock)s"
647
def __init__(self, lock):
651
class PointlessCommit(BzrError):
653
_fmt = "No changes to commit"
656
class UpgradeReadonly(BzrError):
658
_fmt = "Upgrade URL cannot work with readonly URLs."
661
class UpToDateFormat(BzrError):
663
_fmt = "The branch format %(format)s is already at the most recent format."
665
def __init__(self, format):
666
BzrError.__init__(self)
670
class StrictCommitFailed(Exception):
672
_fmt = "Commit refused because there are unknowns in the tree."
184
675
class NoSuchRevision(BzrError):
677
_fmt = "Branch %(branch)s has no revision %(revision)s"
679
internal_error = True
185
681
def __init__(self, branch, revision):
187
self.revision = revision
188
msg = "Branch %s has no revision %s" % (branch, revision)
189
BzrError.__init__(self, msg)
682
BzrError.__init__(self, branch=branch, revision=revision)
685
class NoSuchRevisionSpec(BzrError):
687
_fmt = "No namespace registered for string: %(spec)r"
689
def __init__(self, spec):
690
BzrError.__init__(self, spec=spec)
693
class InvalidRevisionSpec(BzrError):
695
_fmt = "Requested revision: %(spec)r does not exist in branch: %(branch)s%(extra)s"
697
def __init__(self, spec, branch, extra=None):
698
BzrError.__init__(self, branch=branch, spec=spec)
700
self.extra = '\n' + str(extra)
192
705
class HistoryMissing(BzrError):
193
def __init__(self, branch, object_type, object_id):
195
BzrError.__init__(self,
196
'%s is missing %s {%s}'
197
% (branch, object_type, object_id))
707
_fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
200
710
class DivergedBranches(BzrError):
712
_fmt = "These branches have diverged. Use the merge command to reconcile them."""
714
internal_error = False
201
716
def __init__(self, branch1, branch2):
202
BzrError.__init__(self, "These branches have diverged.")
203
717
self.branch1 = branch1
204
718
self.branch2 = branch2
207
class UnrelatedBranches(BzrCommandError):
209
msg = "Branches have no common ancestor, and no base revision"\
211
BzrCommandError.__init__(self, msg)
721
class UnrelatedBranches(BzrError):
723
_fmt = "Branches have no common ancestor, and no merge base revision was specified."
725
internal_error = False
213
728
class NoCommonAncestor(BzrError):
730
_fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
214
732
def __init__(self, revision_a, revision_b):
215
msg = "Revisions have no common ancestor: %s %s." \
216
% (revision_a, revision_b)
217
BzrError.__init__(self, msg)
733
self.revision_a = revision_a
734
self.revision_b = revision_b
219
737
class NoCommonRoot(BzrError):
739
_fmt = "Revisions are not derived from the same root: " \
740
"%(revision_a)s %(revision_b)s."
220
742
def __init__(self, revision_a, revision_b):
221
msg = "Revisions are not derived from the same root: %s %s." \
222
% (revision_a, revision_b)
223
BzrError.__init__(self, msg)
225
class NotAncestor(BzrError):
226
def __init__(self, rev_id, not_ancestor_id):
227
msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id,
229
BzrError.__init__(self, msg)
231
self.not_ancestor_id = not_ancestor_id
234
class NotAncestor(BzrError):
235
def __init__(self, rev_id, not_ancestor_id):
237
self.not_ancestor_id = not_ancestor_id
238
msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id,
240
BzrError.__init__(self, msg)
743
BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
746
class NotAncestor(BzrError):
748
_fmt = "Revision %(rev_id)s is not an ancestor of %(not_ancestor_id)s"
750
def __init__(self, rev_id, not_ancestor_id):
751
BzrError.__init__(self, rev_id=rev_id,
752
not_ancestor_id=not_ancestor_id)
243
755
class InstallFailed(BzrError):
244
757
def __init__(self, revisions):
245
758
msg = "Could not install revisions:\n%s" % " ,".join(revisions)
246
759
BzrError.__init__(self, msg)
250
763
class AmbiguousBase(BzrError):
251
765
def __init__(self, bases):
252
msg = "The correct base is unclear, becase %s are all equally close" %\
766
warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
768
msg = "The correct base is unclear, because %s are all equally close" %\
254
770
BzrError.__init__(self, msg)
255
771
self.bases = bases
257
774
class NoCommits(BzrError):
776
_fmt = "Branch %(branch)s has no commits."
258
778
def __init__(self, branch):
259
msg = "Branch %s has no commits." % branch
260
BzrError.__init__(self, msg)
779
BzrError.__init__(self, branch=branch)
262
782
class UnlistableStore(BzrError):
263
784
def __init__(self, store):
264
785
BzrError.__init__(self, "Store %s is not listable" % store)
266
789
class UnlistableBranch(BzrError):
267
791
def __init__(self, br):
268
792
BzrError.__init__(self, "Stores for branch %s are not listable" % br)
271
from bzrlib.weave import WeaveError, WeaveParentMismatch
795
class BoundBranchOutOfDate(BzrError):
797
_fmt = "Bound branch %(branch)s is out of date with master branch %(master)s."
799
def __init__(self, branch, master):
800
BzrError.__init__(self)
805
class CommitToDoubleBoundBranch(BzrError):
807
_fmt = "Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."
809
def __init__(self, branch, master, remote):
810
BzrError.__init__(self)
816
class OverwriteBoundBranch(BzrError):
818
_fmt = "Cannot pull --overwrite to a branch which is bound %(branch)s"
820
def __init__(self, branch):
821
BzrError.__init__(self)
825
class BoundBranchConnectionFailure(BzrError):
827
_fmt = "Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"
829
def __init__(self, branch, target, error):
830
BzrError.__init__(self)
836
class WeaveError(BzrError):
838
_fmt = "Error in processing weave: %(message)s"
840
def __init__(self, message=None):
841
BzrError.__init__(self)
842
self.message = message
845
class WeaveRevisionAlreadyPresent(WeaveError):
847
_fmt = "Revision {%(revision_id)s} already present in %(weave)s"
849
def __init__(self, revision_id, weave):
851
WeaveError.__init__(self)
852
self.revision_id = revision_id
856
class WeaveRevisionNotPresent(WeaveError):
858
_fmt = "Revision {%(revision_id)s} not present in %(weave)s"
860
def __init__(self, revision_id, weave):
861
WeaveError.__init__(self)
862
self.revision_id = revision_id
866
class WeaveFormatError(WeaveError):
868
_fmt = "Weave invariant violated: %(what)s"
870
def __init__(self, what):
871
WeaveError.__init__(self)
875
class WeaveParentMismatch(WeaveError):
877
_fmt = "Parents are mismatched between two revisions."
880
class WeaveInvalidChecksum(WeaveError):
882
_fmt = "Text did not match it's checksum: %(message)s"
885
class WeaveTextDiffers(WeaveError):
887
_fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
889
def __init__(self, revision_id, weave_a, weave_b):
890
WeaveError.__init__(self)
891
self.revision_id = revision_id
892
self.weave_a = weave_a
893
self.weave_b = weave_b
896
class WeaveTextDiffers(WeaveError):
898
_fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
900
def __init__(self, revision_id, weave_a, weave_b):
901
WeaveError.__init__(self)
902
self.revision_id = revision_id
903
self.weave_a = weave_a
904
self.weave_b = weave_b
907
class VersionedFileError(BzrError):
909
_fmt = "Versioned file error"
912
class RevisionNotPresent(VersionedFileError):
914
_fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
916
def __init__(self, revision_id, file_id):
917
VersionedFileError.__init__(self)
918
self.revision_id = revision_id
919
self.file_id = file_id
922
class RevisionAlreadyPresent(VersionedFileError):
924
_fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
926
def __init__(self, revision_id, file_id):
927
VersionedFileError.__init__(self)
928
self.revision_id = revision_id
929
self.file_id = file_id
932
class KnitError(BzrError):
937
class KnitHeaderError(KnitError):
939
_fmt = "Knit header error: %(badline)r unexpected"
941
def __init__(self, badline):
942
KnitError.__init__(self)
943
self.badline = badline
946
class KnitCorrupt(KnitError):
948
_fmt = "Knit %(filename)s corrupt: %(how)s"
950
def __init__(self, filename, how):
951
KnitError.__init__(self)
952
self.filename = filename
956
class NoSuchExportFormat(BzrError):
958
_fmt = "Export format %(format)r not supported"
960
def __init__(self, format):
961
BzrError.__init__(self)
273
965
class TransportError(BzrError):
274
"""All errors thrown by Transport implementations should derive
967
_fmt = "Transport error: %(msg)s %(orig_error)s"
277
969
def __init__(self, msg=None, orig_error=None):
278
970
if msg is None and orig_error is not None:
279
971
msg = str(orig_error)
280
BzrError.__init__(self, msg)
972
if orig_error is None:
282
977
self.orig_error = orig_error
978
BzrError.__init__(self)
981
class TooManyConcurrentRequests(BzrError):
983
_fmt = ("The medium '%(medium)s' has reached its concurrent request limit. "
984
"Be sure to finish_writing and finish_reading on the "
985
"current request that is open.")
987
internal_error = True
989
def __init__(self, medium):
993
class SmartProtocolError(TransportError):
995
_fmt = "Generic bzr smart protocol error: %(details)s"
997
def __init__(self, details):
998
self.details = details
284
1001
# A set of semi-meaningful errors which can be thrown
285
1002
class TransportNotPossible(TransportError):
286
"""This is for transports where a specific function is explicitly not
287
possible. Such as pushing files to an HTTP server.
291
class NonRelativePath(TransportError):
292
"""An absolute path was supplied, that could not be decoded into
297
class NoSuchFile(TransportError, IOError):
298
"""A get() was issued for a file that doesn't exist."""
300
# XXX: Is multiple inheritance for exceptions really needed?
303
return 'no such file: ' + self.msg
305
def __init__(self, msg=None, orig_error=None):
307
TransportError.__init__(self, msg=msg, orig_error=orig_error)
308
IOError.__init__(self, errno.ENOENT, self.msg)
310
class FileExists(TransportError, OSError):
311
"""An operation was attempted, which would overwrite an entry,
312
but overwritting is not supported.
314
mkdir() can throw this, but put() just overwites existing files.
316
# XXX: Is multiple inheritance for exceptions really needed?
317
def __init__(self, msg=None, orig_error=None):
319
TransportError.__init__(self, msg=msg, orig_error=orig_error)
320
OSError.__init__(self, errno.EEXIST, self.msg)
322
class PermissionDenied(TransportError):
323
"""An operation cannot succeed because of a lack of permissions."""
1004
_fmt = "Transport operation not possible: %(msg)s %(orig_error)s"
1007
class ConnectionError(TransportError):
1009
_fmt = "Connection error: %(msg)s %(orig_error)s"
1012
class SocketConnectionError(ConnectionError):
1014
_fmt = "%(msg)s %(host)s%(port)s%(orig_error)s"
1016
def __init__(self, host, port=None, msg=None, orig_error=None):
1018
msg = 'Failed to connect to'
1019
if orig_error is None:
1022
orig_error = '; ' + str(orig_error)
1023
ConnectionError.__init__(self, msg=msg, orig_error=orig_error)
1028
self.port = ':%s' % port
326
1031
class ConnectionReset(TransportError):
327
"""The connection has been closed."""
1033
_fmt = "Connection closed: %(msg)s %(orig_error)s"
1036
class InvalidRange(TransportError):
1038
_fmt = "Invalid range access in %(path)s at %(offset)s."
1040
def __init__(self, path, offset):
1041
TransportError.__init__(self, ("Invalid range access in %s at %d"
1044
self.offset = offset
1047
class InvalidHttpResponse(TransportError):
1049
_fmt = "Invalid http response for %(path)s: %(msg)s"
1051
def __init__(self, path, msg, orig_error=None):
1053
TransportError.__init__(self, msg, orig_error=orig_error)
1056
class InvalidHttpRange(InvalidHttpResponse):
1058
_fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1060
def __init__(self, path, range, msg):
1062
InvalidHttpResponse.__init__(self, path, msg)
1065
class InvalidHttpContentType(InvalidHttpResponse):
1067
_fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1069
def __init__(self, path, ctype, msg):
1071
InvalidHttpResponse.__init__(self, path, msg)
330
1074
class ConflictsInTree(BzrError):
332
BzrError.__init__(self, "Working tree has conflicts.")
1076
_fmt = "Working tree has conflicts."
1079
class ParseConfigError(BzrError):
1081
def __init__(self, errors, filename):
1082
if filename is None:
1084
message = "Error(s) parsing config file %s:\n%s" % \
1085
(filename, ('\n'.join(e.message for e in errors)))
1086
BzrError.__init__(self, message)
1089
class NoEmailInUsername(BzrError):
1091
_fmt = "%(username)r does not seem to contain a reasonable email address"
1093
def __init__(self, username):
1094
BzrError.__init__(self)
1095
self.username = username
334
1098
class SigningFailed(BzrError):
1100
_fmt = "Failed to gpg sign data with command %(command_line)r"
335
1102
def __init__(self, command_line):
336
BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
1103
BzrError.__init__(self, command_line=command_line)
1106
class WorkingTreeNotRevision(BzrError):
1108
_fmt = ("The working tree for %(basedir)s has changed since"
1109
" the last commit, but weave merge requires that it be"
1112
def __init__(self, tree):
1113
BzrError.__init__(self, basedir=tree.basedir)
1116
class CantReprocessAndShowBase(BzrError):
1118
_fmt = "Can't reprocess and show base, because reprocessing obscures " \
1119
"the relationship of conflicting lines to the base"
1122
class GraphCycleError(BzrError):
1124
_fmt = "Cycle in graph %(graph)r"
1126
def __init__(self, graph):
1127
BzrError.__init__(self)
1131
class WritingCompleted(BzrError):
1133
_fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1134
"called upon it - accept bytes may not be called anymore.")
1136
internal_error = True
1138
def __init__(self, request):
1139
self.request = request
1142
class WritingNotComplete(BzrError):
1144
_fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1145
"called upon it - until the write phase is complete no "
1146
"data may be read.")
1148
internal_error = True
1150
def __init__(self, request):
1151
self.request = request
1154
class NotConflicted(BzrError):
1156
_fmt = "File %(filename)s is not conflicted."
1158
def __init__(self, filename):
1159
BzrError.__init__(self)
1160
self.filename = filename
1163
class MediumNotConnected(BzrError):
1165
_fmt = """The medium '%(medium)s' is not connected."""
1167
internal_error = True
1169
def __init__(self, medium):
1170
self.medium = medium
1173
class MustUseDecorated(Exception):
1175
_fmt = """A decorating function has requested its original command be used."""
1178
class NoBundleFound(BzrError):
1180
_fmt = "No bundle was found in %(filename)s"
1182
def __init__(self, filename):
1183
BzrError.__init__(self)
1184
self.filename = filename
1187
class BundleNotSupported(BzrError):
1189
_fmt = "Unable to handle bundle version %(version)s: %(msg)s"
1191
def __init__(self, version, msg):
1192
BzrError.__init__(self)
1193
self.version = version
1197
class MissingText(BzrError):
1199
_fmt = "Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"
1201
def __init__(self, branch, text_revision, file_id):
1202
BzrError.__init__(self)
1203
self.branch = branch
1204
self.base = branch.base
1205
self.text_revision = text_revision
1206
self.file_id = file_id
1209
class DuplicateKey(BzrError):
1211
_fmt = "Key %(key)s is already present in map"
1214
class MalformedTransform(BzrError):
1216
_fmt = "Tree transform is malformed %(conflicts)r"
1219
class NoFinalPath(BzrError):
1221
_fmt = ("No final name for trans_id %(trans_id)r\n"
1222
"file-id: %(file_id)r\n"
1223
"root trans-id: %(root_trans_id)r\n")
1225
def __init__(self, trans_id, transform):
1226
self.trans_id = trans_id
1227
self.file_id = transform.final_file_id(trans_id)
1228
self.root_trans_id = transform.root
1231
class BzrBadParameter(BzrError):
1233
_fmt = "Bad parameter: %(param)r"
1235
# This exception should never be thrown, but it is a base class for all
1236
# parameter-to-function errors.
1238
def __init__(self, param):
1239
BzrError.__init__(self)
1243
class BzrBadParameterNotUnicode(BzrBadParameter):
1245
_fmt = "Parameter %(param)s is neither unicode nor utf8."
1248
class ReusingTransform(BzrError):
1250
_fmt = "Attempt to reuse a transform that has already been applied."
1253
class CantMoveRoot(BzrError):
1255
_fmt = "Moving the root directory is not supported at this time"
1258
class BzrBadParameterNotString(BzrBadParameter):
1260
_fmt = "Parameter %(param)s is not a string or unicode string."
1263
class BzrBadParameterMissing(BzrBadParameter):
1265
_fmt = "Parameter $(param)s is required but not present."
1268
class BzrBadParameterUnicode(BzrBadParameter):
1270
_fmt = "Parameter %(param)s is unicode but only byte-strings are permitted."
1273
class BzrBadParameterContainsNewline(BzrBadParameter):
1275
_fmt = "Parameter %(param)s contains a newline."
1278
class DependencyNotPresent(BzrError):
1280
_fmt = 'Unable to import library "%(library)s": %(error)s'
1282
def __init__(self, library, error):
1283
BzrError.__init__(self, library=library, error=error)
1286
class ParamikoNotPresent(DependencyNotPresent):
1288
_fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1290
def __init__(self, error):
1291
DependencyNotPresent.__init__(self, 'paramiko', error)
1294
class PointlessMerge(BzrError):
1296
_fmt = "Nothing to merge."
1299
class UninitializableFormat(BzrError):
1301
_fmt = "Format %(format)s cannot be initialised by this version of bzr."
1303
def __init__(self, format):
1304
BzrError.__init__(self)
1305
self.format = format
1308
class BadConversionTarget(BzrError):
1310
_fmt = "Cannot convert to format %(format)s. %(problem)s"
1312
def __init__(self, problem, format):
1313
BzrError.__init__(self)
1314
self.problem = problem
1315
self.format = format
1318
class NoDiff(BzrError):
1320
_fmt = "Diff is not installed on this machine: %(msg)s"
1322
def __init__(self, msg):
1323
BzrError.__init__(self, msg=msg)
1326
class NoDiff3(BzrError):
1328
_fmt = "Diff3 is not installed on this machine."
1331
class ExistingLimbo(BzrError):
1333
_fmt = """This tree contains left-over files from a failed operation.
1334
Please examine %(limbo_dir)s to see if it contains any files you wish to
1335
keep, and delete it when you are done."""
1337
def __init__(self, limbo_dir):
1338
BzrError.__init__(self)
1339
self.limbo_dir = limbo_dir
1342
class ImmortalLimbo(BzrError):
1344
_fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
1345
Please examine %(limbo_dir)s to see if it contains any files you wish to
1346
keep, and delete it when you are done."""
1348
def __init__(self, limbo_dir):
1349
BzrError.__init__(self)
1350
self.limbo_dir = limbo_dir
1353
class OutOfDateTree(BzrError):
1355
_fmt = "Working tree is out of date, please run 'bzr update'."
1357
def __init__(self, tree):
1358
BzrError.__init__(self)
1362
class MergeModifiedFormatError(BzrError):
1364
_fmt = "Error in merge modified format"
1367
class ConflictFormatError(BzrError):
1369
_fmt = "Format error in conflict listings"
1372
class CorruptRepository(BzrError):
1374
_fmt = """An error has been detected in the repository %(repo_path)s.
1375
Please run bzr reconcile on this repository."""
1377
def __init__(self, repo):
1378
BzrError.__init__(self)
1379
self.repo_path = repo.bzrdir.root_transport.base
1382
class UpgradeRequired(BzrError):
1384
_fmt = "To use this feature you must upgrade your branch at %(path)s."
1386
def __init__(self, path):
1387
BzrError.__init__(self)
1391
class LocalRequiresBoundBranch(BzrError):
1393
_fmt = "Cannot perform local-only commits on unbound branches."
1396
class MissingProgressBarFinish(BzrError):
1398
_fmt = "A nested progress bar was not 'finished' correctly."
1401
class InvalidProgressBarType(BzrError):
1403
_fmt = """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
1404
Select one of: %(valid_types)s"""
1406
def __init__(self, bar_type, valid_types):
1407
BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1410
class UnsupportedOperation(BzrError):
1412
_fmt = "The method %(mname)s is not supported on objects of type %(tname)s."
1414
def __init__(self, method, method_self):
1415
self.method = method
1416
self.mname = method.__name__
1417
self.tname = type(method_self).__name__
1420
class BinaryFile(BzrError):
1422
_fmt = "File is binary but should be text."
1425
class IllegalPath(BzrError):
1427
_fmt = "The path %(path)s is not permitted on this platform"
1429
def __init__(self, path):
1430
BzrError.__init__(self)
1434
class TestamentMismatch(BzrError):
1436
_fmt = """Testament did not match expected value.
1437
For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
1440
def __init__(self, revision_id, expected, measured):
1441
self.revision_id = revision_id
1442
self.expected = expected
1443
self.measured = measured
1446
class NotABundle(BzrError):
1448
_fmt = "Not a bzr revision-bundle: %(text)r"
1450
def __init__(self, text):
1451
BzrError.__init__(self)
1455
class BadBundle(BzrError):
1457
_fmt = "Bad bzr revision-bundle: %(text)r"
1459
def __init__(self, text):
1460
BzrError.__init__(self)
1464
class MalformedHeader(BadBundle):
1466
_fmt = "Malformed bzr revision-bundle header: %(text)r"
1469
class MalformedPatches(BadBundle):
1471
_fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1474
class MalformedFooter(BadBundle):
1476
_fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1479
class UnsupportedEOLMarker(BadBundle):
1481
_fmt = "End of line marker was not \\n in bzr revision-bundle"
1484
# XXX: BadBundle's constructor assumes there's explanatory text,
1485
# but for this there is not
1486
BzrError.__init__(self)
1489
class IncompatibleBundleFormat(BzrError):
1491
_fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1493
def __init__(self, bundle_format, other):
1494
BzrError.__init__(self)
1495
self.bundle_format = bundle_format
1499
class BadInventoryFormat(BzrError):
1501
_fmt = "Root class for inventory serialization errors"
1504
class UnexpectedInventoryFormat(BadInventoryFormat):
1506
_fmt = "The inventory was not in the expected format:\n %(msg)s"
1508
def __init__(self, msg):
1509
BadInventoryFormat.__init__(self, msg=msg)
1512
class NoSmartMedium(BzrError):
1514
_fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
1516
def __init__(self, transport):
1517
self.transport = transport
1520
class NoSmartServer(NotBranchError):
1522
_fmt = "No smart server available at %(url)s"
1524
def __init__(self, url):
1528
class UnknownSSH(BzrError):
1530
_fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1532
def __init__(self, vendor):
1533
BzrError.__init__(self)
1534
self.vendor = vendor
1537
class GhostRevisionUnusableHere(BzrError):
1539
_fmt = "Ghost revision {%(revision_id)s} cannot be used here."
1541
def __init__(self, revision_id):
1542
BzrError.__init__(self)
1543
self.revision_id = revision_id
1546
class IllegalUseOfScopeReplacer(BzrError):
1548
_fmt = "ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"
1550
internal_error = True
1552
def __init__(self, name, msg, extra=None):
1553
BzrError.__init__(self)
1557
self.extra = ': ' + str(extra)
1562
class InvalidImportLine(BzrError):
1564
_fmt = "Not a valid import statement: %(msg)\n%(text)s"
1566
internal_error = True
1568
def __init__(self, text, msg):
1569
BzrError.__init__(self)
1574
class ImportNameCollision(BzrError):
1576
_fmt = "Tried to import an object to the same name as an existing object. %(name)s"
1578
internal_error = True
1580
def __init__(self, name):
1581
BzrError.__init__(self)