39
85
# constructed to make sure it will succeed. But that says nothing about
40
86
# exceptions that are never raised.
42
# TODO: selftest assertRaises should probably also check that every error
43
# raised can be formatted as a string successfully, and without giving
88
# TODO: Convert all the other error classes here to BzrNewError, and eliminate
91
# TODO: The pattern (from hct) of using classes docstrings as message
92
# templates is cute but maybe not such a great idea - perhaps should have a
93
# separate static message_template.
47
96
class BzrError(StandardError):
49
Base class for errors raised by bzrlib.
51
:cvar internal_error: if true (or absent) this was probably caused by a
52
bzr bug and should be displayed with a traceback; if False this was
53
probably a user or environment error and they don't need the gory details.
54
(That can be overridden by -Derror on the command line.)
56
:cvar _fmt: Format string to display the error; this is expanded
57
by the instance's dict.
60
internal_error = False
62
def __init__(self, msg=None, **kwds):
63
"""Construct a new BzrError.
65
There are two alternative forms for constructing these objects.
66
Either a preformatted string may be passed, or a set of named
67
arguments can be given. The first is for generic "user" errors which
68
are not intended to be caught and so do not need a specific subclass.
69
The second case is for use with subclasses that provide a _fmt format
70
string to print the arguments.
72
Keyword arguments are taken as parameters to the error, which can
73
be inserted into the format string template. It's recommended
74
that subclasses override the __init__ method to require specific
77
:param msg: If given, this is the literal complete text for the error,
78
not subject to expansion.
80
StandardError.__init__(self)
82
# I was going to deprecate this, but it actually turns out to be
83
# quite handy - mbp 20061103.
84
self._preformatted_string = msg
101
# XXX: Should we show the exception class in
102
# exceptions that don't provide their own message?
103
# maybe it should be done at a higher level
104
## n = self.__class__.__name__ + ': '
106
if len(self.args) == 1:
107
return str(self.args[0])
108
elif len(self.args) == 2:
109
# further explanation or suggestions
111
return n + '\n '.join([self.args[0]] + self.args[1])
113
return n + "%r" % self
86
self._preformatted_string = None
87
for key, value in kwds.items():
88
setattr(self, key, value)
91
s = getattr(self, '_preformatted_string', None)
93
# contains a preformatted message; must be cast to plain str
96
fmt = self._get_format_string()
98
s = fmt % self.__dict__
99
# __str__() should always return a 'str' object
100
# never a 'unicode' object.
101
if isinstance(s, unicode):
102
return s.encode('utf8')
104
except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
105
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
106
% (self.__class__.__name__,
108
getattr(self, '_fmt', None),
111
def _get_format_string(self):
112
"""Return format string for this exception or None"""
113
fmt = getattr(self, '_fmt', None)
116
fmt = getattr(self, '__doc__', None)
118
symbol_versioning.warn("%s uses its docstring as a format, "
119
"it should use _fmt instead" % self.__class__.__name__,
122
return 'Unprintable exception %s: dict=%r, fmt=%r' \
123
% (self.__class__.__name__,
125
getattr(self, '_fmt', None),
115
return n + `self.args`
129
118
class BzrNewError(BzrError):
130
"""Deprecated error base class."""
131
120
# base classes should override the docstring with their human-
132
121
# readable explanation
134
def __init__(self, *args, **kwds):
135
# XXX: Use the underlying BzrError to always generate the args
136
# attribute if it doesn't exist. We can't use super here, because
137
# exceptions are old-style classes in python2.4 (but new in 2.5).
139
symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
140
'please convert %s to use BzrError instead'
141
% self.__class__.__name__,
144
BzrError.__init__(self, *args)
123
def __init__(self, **kwds):
145
124
for key, value in kwds.items():
146
125
setattr(self, key, value)
153
132
if isinstance(s, unicode):
154
133
return s.encode('utf8')
156
except (TypeError, NameError, ValueError, KeyError), e:
157
return 'Unprintable exception %s(%r): %s' \
158
% (self.__class__.__name__,
159
self.__dict__, str(e))
162
class AlreadyBuilding(BzrError):
164
_fmt = "The tree builder is already building a tree."
167
class BzrCheckError(BzrError):
169
_fmt = "Internal check failed: %(message)s"
171
internal_error = True
135
except (NameError, ValueError, KeyError), e:
136
return 'Unprintable exception %s: %s' \
137
% (self.__class__.__name__, str(e))
140
class BzrCheckError(BzrNewError):
141
"""Internal check failed: %(message)s"""
143
is_user_error = False
173
145
def __init__(self, message):
174
BzrError.__init__(self)
146
BzrNewError.__init__(self)
175
147
self.message = message
178
class DisabledMethod(BzrError):
180
_fmt = "The smart server method '%(class_name)s' is disabled."
182
internal_error = True
184
def __init__(self, class_name):
185
BzrError.__init__(self)
186
self.class_name = class_name
189
class InvalidEntryName(BzrError):
191
_fmt = "Invalid entry name: %(name)s"
193
internal_error = True
150
class InvalidEntryName(BzrNewError):
151
"""Invalid entry name: %(name)s"""
153
is_user_error = False
195
155
def __init__(self, name):
196
BzrError.__init__(self)
156
BzrNewError.__init__(self)
200
class InvalidRevisionNumber(BzrError):
202
_fmt = "Invalid revision number %(revno)s"
160
class InvalidRevisionNumber(BzrNewError):
161
"""Invalid revision number %(revno)d"""
204
162
def __init__(self, revno):
205
BzrError.__init__(self)
163
BzrNewError.__init__(self)
206
164
self.revno = revno
209
class InvalidRevisionId(BzrError):
211
_fmt = "Invalid revision-id {%(revision_id)s} in %(branch)s"
167
class InvalidRevisionId(BzrNewError):
168
"""Invalid revision-id {%(revision_id)s} in %(branch)s"""
213
170
def __init__(self, revision_id, branch):
214
171
# branch can be any string or object with __str__ defined
215
BzrError.__init__(self)
172
BzrNewError.__init__(self)
216
173
self.revision_id = revision_id
217
174
self.branch = branch
219
class ReservedId(BzrError):
221
_fmt = "Reserved revision-id {%(revision_id)s}"
223
def __init__(self, revision_id):
224
self.revision_id = revision_id
226
class NoSuchId(BzrError):
228
_fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
177
class NoSuchId(BzrNewError):
178
"""The file id %(file_id)s is not present in the tree %(tree)s."""
230
180
def __init__(self, tree, file_id):
231
BzrError.__init__(self)
181
BzrNewError.__init__(self)
232
182
self.file_id = file_id
236
class InventoryModified(BzrError):
238
_fmt = ("The current inventory for the tree %(tree)r has been modified,"
239
" so a clean inventory cannot be read without data loss.")
241
internal_error = True
243
def __init__(self, tree):
247
class NoWorkingTree(BzrError):
249
_fmt = "No WorkingTree exists for %(base)s."
186
class NoWorkingTree(BzrNewError):
187
"""No WorkingTree exists for %(base)s."""
251
189
def __init__(self, base):
252
BzrError.__init__(self)
190
BzrNewError.__init__(self)
256
class NotBuilding(BzrError):
258
_fmt = "Not currently building a tree."
261
class NotLocalUrl(BzrError):
263
_fmt = "%(url)s is not a local path."
194
class NotLocalUrl(BzrNewError):
195
"""%(url)s is not a local path."""
265
197
def __init__(self, url):
198
BzrNewError.__init__(self)
269
class WorkingTreeAlreadyPopulated(BzrError):
271
_fmt = """Working tree already populated in %(base)s"""
273
internal_error = True
275
def __init__(self, base):
278
class BzrCommandError(BzrError):
202
class BzrCommandError(BzrNewError):
279
203
"""Error from user command"""
281
internal_error = False
283
207
# Error from malformed user command; please avoid raising this as a
284
208
# generic exception not caused by user input.
515
335
class InaccessibleParent(PathError):
517
_fmt = ("Parent not accessible given base %(base)s and"
518
" relative path %(path)s")
336
"""Parent not accessible given base %(base)s and relative path %(path)s"""
520
338
def __init__(self, path, base):
521
339
PathError.__init__(self, path)
525
class NoRepositoryPresent(BzrError):
527
_fmt = "No repository present: %(path)r"
343
class NoRepositoryPresent(BzrNewError):
344
"""No repository present: %(path)r"""
528
345
def __init__(self, bzrdir):
529
BzrError.__init__(self)
346
BzrNewError.__init__(self)
530
347
self.path = bzrdir.transport.clone('..').base
533
class FileInWrongBranch(BzrError):
535
_fmt = "File %(path)s in not in branch %(branch_base)s."
350
class FileInWrongBranch(BzrNewError):
351
"""File %(path)s in not in branch %(branch_base)s."""
537
353
def __init__(self, branch, path):
538
BzrError.__init__(self)
354
BzrNewError.__init__(self)
539
355
self.branch = branch
540
356
self.branch_base = branch.base
544
class UnsupportedFormatError(BzrError):
546
_fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
549
class UnknownFormatError(BzrError):
551
_fmt = "Unknown branch format: %(format)r"
554
class IncompatibleFormat(BzrError):
556
_fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
360
class UnsupportedFormatError(BzrNewError):
361
"""Unsupported branch format: %(format)s"""
364
class UnknownFormatError(BzrNewError):
365
"""Unknown branch format: %(format)r"""
368
class IncompatibleFormat(BzrNewError):
369
"""Format %(format)s is not compatible with .bzr version %(bzrdir)s."""
558
371
def __init__(self, format, bzrdir_format):
559
BzrError.__init__(self)
372
BzrNewError.__init__(self)
560
373
self.format = format
561
374
self.bzrdir = bzrdir_format
564
class IncompatibleRepositories(BzrError):
566
_fmt = "Repository %(target)s is not compatible with repository"\
569
def __init__(self, source, target):
570
BzrError.__init__(self, target=target, source=source)
573
class IncompatibleRevision(BzrError):
575
_fmt = "Revision is not compatible with %(repo_format)s"
577
def __init__(self, repo_format):
578
BzrError.__init__(self)
579
self.repo_format = repo_format
582
class AlreadyVersionedError(BzrError):
583
"""Used when a path is expected not to be versioned, but it is."""
585
_fmt = "%(context_info)s%(path)s is already versioned"
587
def __init__(self, path, context_info=None):
588
"""Construct a new AlreadyVersionedError.
590
:param path: This is the path which is versioned,
591
which should be in a user friendly form.
592
:param context_info: If given, this is information about the context,
593
which could explain why this is expected to not be versioned.
595
BzrError.__init__(self)
597
if context_info is None:
598
self.context_info = ''
600
self.context_info = context_info + ". "
603
class NotVersionedError(BzrError):
604
"""Used when a path is expected to be versioned, but it is not."""
606
_fmt = "%(context_info)s%(path)s is not versioned"
608
def __init__(self, path, context_info=None):
609
"""Construct a new NotVersionedError.
611
:param path: This is the path which is not versioned,
612
which should be in a user friendly form.
613
:param context_info: If given, this is information about the context,
614
which could explain why this is expected to be versioned.
616
BzrError.__init__(self)
618
if context_info is None:
619
self.context_info = ''
621
self.context_info = context_info + ". "
624
class PathsNotVersionedError(BzrError):
625
"""Used when reporting several paths which are not versioned"""
627
_fmt = "Path(s) are not versioned: %(paths_as_string)s"
377
class NotVersionedError(BzrNewError):
378
"""%(path)s is not versioned"""
379
def __init__(self, path):
380
BzrNewError.__init__(self)
384
class PathsNotVersionedError(BzrNewError):
385
# used when reporting several paths are not versioned
386
"""Path(s) are not versioned: %(paths_as_string)s"""
629
388
def __init__(self, paths):
630
389
from bzrlib.osutils import quotefn
631
BzrError.__init__(self)
390
BzrNewError.__init__(self)
632
391
self.paths = paths
633
392
self.paths_as_string = ' '.join([quotefn(p) for p in paths])
636
class PathsDoNotExist(BzrError):
638
_fmt = "Path(s) do not exist: %(paths_as_string)s%(extra)s"
395
class PathsDoNotExist(BzrNewError):
396
"""Path(s) do not exist: %(paths_as_string)s"""
640
398
# used when reporting that paths are neither versioned nor in the working
643
def __init__(self, paths, extra=None):
401
def __init__(self, paths):
644
402
# circular import
645
403
from bzrlib.osutils import quotefn
646
BzrError.__init__(self)
404
BzrNewError.__init__(self)
647
405
self.paths = paths
648
406
self.paths_as_string = ' '.join([quotefn(p) for p in paths])
650
self.extra = ': ' + str(extra)
655
class BadFileKindError(BzrError):
657
_fmt = 'Cannot operate on "%(filename)s" of unsupported kind "%(kind)s"'
659
def __init__(self, filename, kind):
660
BzrError.__init__(self, filename=filename, kind=kind)
663
class ForbiddenControlFileError(BzrError):
665
_fmt = "Cannot operate on %(filename)s because it is a control file"
668
class LockError(BzrError):
670
_fmt = "Lock error: %(msg)s"
672
internal_error = True
409
class BadFileKindError(BzrNewError):
410
"""Cannot operate on %(filename)s of unsupported kind %(kind)s"""
413
class ForbiddenControlFileError(BzrNewError):
414
"""Cannot operate on %(filename)s because it is a control file"""
417
class LockError(BzrNewError):
418
"""Lock error: %(message)s"""
674
419
# All exceptions from the lock/unlock functions should be from
675
420
# this exception class. They will be translated as necessary. The
676
421
# original exception is available as e.original_error
678
423
# New code should prefer to raise specific subclasses
679
424
def __init__(self, message):
680
# Python 2.5 uses a slot for StandardError.message,
681
# so use a different variable name
682
# so it is exposed in self.__dict__
686
class LockActive(LockError):
688
_fmt = "The lock for '%(lock_description)s' is in use and cannot be broken."
690
internal_error = False
692
def __init__(self, lock_description):
693
self.lock_description = lock_description
425
self.message = message
696
428
class CommitNotPossible(LockError):
698
_fmt = "A commit was attempted but we do not have a write lock open."
429
"""A commit was attempted but we do not have a write lock open."""
700
430
def __init__(self):
704
434
class AlreadyCommitted(LockError):
706
_fmt = "A rollback was requested, but is not able to be accomplished."
435
"""A rollback was requested, but is not able to be accomplished."""
708
436
def __init__(self):
712
440
class ReadOnlyError(LockError):
714
_fmt = "A write attempt was made in a read only transaction on %(obj)s"
716
# TODO: There should also be an error indicating that you need a write
717
# lock and don't have any lock at all... mbp 20070226
441
"""A write attempt was made in a read only transaction on %(obj)s"""
719
442
def __init__(self, obj):
723
class ReadOnlyLockError(LockError):
725
_fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
727
def __init__(self, fname, msg):
728
LockError.__init__(self, '')
733
class OutSideTransaction(BzrError):
735
_fmt = ("A transaction related operation was attempted after"
736
" the transaction finished.")
446
class OutSideTransaction(BzrNewError):
447
"""A transaction related operation was attempted after the transaction finished."""
739
450
class ObjectNotLocked(LockError):
451
"""%(obj)r is not locked"""
741
_fmt = "%(obj)r is not locked"
453
is_user_error = False
743
455
# this can indicate that any particular object is not locked; see also
744
456
# LockNotHeld which means that a particular *lock* object is not held by
968
581
class NoCommonRoot(BzrError):
970
_fmt = ("Revisions are not derived from the same root: "
971
"%(revision_a)s %(revision_b)s.")
973
582
def __init__(self, revision_a, revision_b):
974
BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
583
msg = "Revisions are not derived from the same root: %s %s." \
584
% (revision_a, revision_b)
585
BzrError.__init__(self, msg)
977
589
class NotAncestor(BzrError):
979
_fmt = "Revision %(rev_id)s is not an ancestor of %(not_ancestor_id)s"
981
590
def __init__(self, rev_id, not_ancestor_id):
982
BzrError.__init__(self, rev_id=rev_id,
983
not_ancestor_id=not_ancestor_id)
591
msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id,
593
BzrError.__init__(self, msg)
595
self.not_ancestor_id = not_ancestor_id
986
598
class InstallFailed(BzrError):
988
599
def __init__(self, revisions):
989
revision_str = ", ".join(str(r) for r in revisions)
990
msg = "Could not install revisions:\n%s" % revision_str
600
msg = "Could not install revisions:\n%s" % " ,".join(revisions)
991
601
BzrError.__init__(self, msg)
992
602
self.revisions = revisions
995
605
class AmbiguousBase(BzrError):
997
606
def __init__(self, bases):
998
607
warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
999
608
DeprecationWarning)
1000
msg = ("The correct base is unclear, because %s are all equally close"
609
msg = "The correct base is unclear, because %s are all equally close" %\
1002
611
BzrError.__init__(self, msg)
1003
612
self.bases = bases
1006
class NoCommits(BzrError):
1008
_fmt = "Branch %(branch)s has no commits."
615
class NoCommits(BzrNewError):
616
"""Branch %(branch)s has no commits."""
1010
618
def __init__(self, branch):
1011
BzrError.__init__(self, branch=branch)
619
BzrNewError.__init__(self, branch=branch)
1014
622
class UnlistableStore(BzrError):
1016
623
def __init__(self, store):
1017
624
BzrError.__init__(self, "Store %s is not listable" % store)
1021
628
class UnlistableBranch(BzrError):
1023
629
def __init__(self, br):
1024
630
BzrError.__init__(self, "Stores for branch %s are not listable" % br)
1027
class BoundBranchOutOfDate(BzrError):
1029
_fmt = ("Bound branch %(branch)s is out of date"
1030
" with master branch %(master)s.")
633
class BoundBranchOutOfDate(BzrNewError):
634
"""Bound branch %(branch)s is out of date with master branch %(master)s."""
1032
635
def __init__(self, branch, master):
1033
BzrError.__init__(self)
636
BzrNewError.__init__(self)
1034
637
self.branch = branch
1035
638
self.master = master
1038
class CommitToDoubleBoundBranch(BzrError):
1040
_fmt = ("Cannot commit to branch %(branch)s."
1041
" It is bound to %(master)s, which is bound to %(remote)s.")
641
class CommitToDoubleBoundBranch(BzrNewError):
642
"""Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."""
1043
643
def __init__(self, branch, master, remote):
1044
BzrError.__init__(self)
644
BzrNewError.__init__(self)
1045
645
self.branch = branch
1046
646
self.master = master
1047
647
self.remote = remote
1050
class OverwriteBoundBranch(BzrError):
1052
_fmt = "Cannot pull --overwrite to a branch which is bound %(branch)s"
650
class OverwriteBoundBranch(BzrNewError):
651
"""Cannot pull --overwrite to a branch which is bound %(branch)s"""
1054
652
def __init__(self, branch):
1055
BzrError.__init__(self)
653
BzrNewError.__init__(self)
1056
654
self.branch = branch
1059
class BoundBranchConnectionFailure(BzrError):
1061
_fmt = ("Unable to connect to target of bound branch %(branch)s"
1062
" => %(target)s: %(error)s")
657
class BoundBranchConnectionFailure(BzrNewError):
658
"""Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"""
1064
659
def __init__(self, branch, target, error):
1065
BzrError.__init__(self)
660
BzrNewError.__init__(self)
1066
661
self.branch = branch
1067
662
self.target = target
1068
663
self.error = error
1071
class WeaveError(BzrError):
1073
_fmt = "Error in processing weave: %(message)s"
666
class WeaveError(BzrNewError):
667
"""Error in processing weave: %(message)s"""
1075
669
def __init__(self, message=None):
1076
BzrError.__init__(self)
670
BzrNewError.__init__(self)
1077
671
self.message = message
1080
674
class WeaveRevisionAlreadyPresent(WeaveError):
1082
_fmt = "Revision {%(revision_id)s} already present in %(weave)s"
675
"""Revision {%(revision_id)s} already present in %(weave)s"""
1084
676
def __init__(self, revision_id, weave):
1086
678
WeaveError.__init__(self)
1394
851
BzrError.__init__(self, message)
1397
class NoEmailInUsername(BzrError):
1399
_fmt = "%(username)r does not seem to contain a reasonable email address"
1401
def __init__(self, username):
1402
BzrError.__init__(self)
1403
self.username = username
1406
854
class SigningFailed(BzrError):
1408
_fmt = "Failed to gpg sign data with command %(command_line)r"
1410
855
def __init__(self, command_line):
1411
BzrError.__init__(self, command_line=command_line)
856
BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
1414
860
class WorkingTreeNotRevision(BzrError):
1416
_fmt = ("The working tree for %(basedir)s has changed since"
1417
" the last commit, but weave merge requires that it be"
1420
861
def __init__(self, tree):
1421
BzrError.__init__(self, basedir=tree.basedir)
1424
class CantReprocessAndShowBase(BzrError):
1426
_fmt = ("Can't reprocess and show base, because reprocessing obscures "
1427
"the relationship of conflicting lines to the base")
1430
class GraphCycleError(BzrError):
1432
_fmt = "Cycle in graph %(graph)r"
862
BzrError.__init__(self, "The working tree for %s has changed since"
863
" last commit, but weave merge requires that it be"
864
" unchanged." % tree.basedir)
867
class CantReprocessAndShowBase(BzrNewError):
868
"""Can't reprocess and show base.
869
Reprocessing obscures relationship of conflicting lines to base."""
872
class GraphCycleError(BzrNewError):
873
"""Cycle in graph %(graph)r"""
1434
874
def __init__(self, graph):
1435
BzrError.__init__(self)
875
BzrNewError.__init__(self)
1436
876
self.graph = graph
1439
class WritingCompleted(BzrError):
1441
_fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1442
"called upon it - accept bytes may not be called anymore.")
1444
internal_error = True
1446
def __init__(self, request):
1447
self.request = request
1450
class WritingNotComplete(BzrError):
1452
_fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1453
"called upon it - until the write phase is complete no "
1454
"data may be read.")
1456
internal_error = True
1458
def __init__(self, request):
1459
self.request = request
1462
class NotConflicted(BzrError):
1464
_fmt = "File %(filename)s is not conflicted."
879
class NotConflicted(BzrNewError):
880
"""File %(filename)s is not conflicted."""
1466
882
def __init__(self, filename):
1467
BzrError.__init__(self)
883
BzrNewError.__init__(self)
1468
884
self.filename = filename
1471
class MediumNotConnected(BzrError):
1473
_fmt = """The medium '%(medium)s' is not connected."""
1475
internal_error = True
1477
def __init__(self, medium):
1478
self.medium = medium
1481
887
class MustUseDecorated(Exception):
1483
_fmt = "A decorating function has requested its original command be used."
1486
class NoBundleFound(BzrError):
1488
_fmt = "No bundle was found in %(filename)s"
888
"""A decorating function has requested its original command be used.
890
This should never escape bzr, so does not need to be printable.
894
class NoBundleFound(BzrNewError):
895
"""No bundle was found in %(filename)s"""
1490
896
def __init__(self, filename):
1491
BzrError.__init__(self)
897
BzrNewError.__init__(self)
1492
898
self.filename = filename
1495
class BundleNotSupported(BzrError):
1497
_fmt = "Unable to handle bundle version %(version)s: %(msg)s"
901
class BundleNotSupported(BzrNewError):
902
"""Unable to handle bundle version %(version)s: %(msg)s"""
1499
903
def __init__(self, version, msg):
1500
BzrError.__init__(self)
904
BzrNewError.__init__(self)
1501
905
self.version = version
1505
class MissingText(BzrError):
1507
_fmt = ("Branch %(base)s is missing revision"
1508
" %(text_revision)s of %(file_id)s")
909
class MissingText(BzrNewError):
910
"""Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"""
1510
912
def __init__(self, branch, text_revision, file_id):
1511
BzrError.__init__(self)
913
BzrNewError.__init__(self)
1512
914
self.branch = branch
1513
915
self.base = branch.base
1514
916
self.text_revision = text_revision
1515
917
self.file_id = file_id
1518
class DuplicateFileId(BzrError):
1520
_fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
1522
def __init__(self, file_id, entry):
1523
BzrError.__init__(self)
1524
self.file_id = file_id
1528
class DuplicateKey(BzrError):
1530
_fmt = "Key %(key)s is already present in map"
1533
class MalformedTransform(BzrError):
1535
_fmt = "Tree transform is malformed %(conflicts)r"
1538
class NoFinalPath(BzrError):
1540
_fmt = ("No final name for trans_id %(trans_id)r\n"
1541
"file-id: %(file_id)r\n"
1542
"root trans-id: %(root_trans_id)r\n")
1544
def __init__(self, trans_id, transform):
1545
self.trans_id = trans_id
1546
self.file_id = transform.final_file_id(trans_id)
1547
self.root_trans_id = transform.root
1550
class BzrBadParameter(BzrError):
1552
_fmt = "Bad parameter: %(param)r"
1554
# This exception should never be thrown, but it is a base class for all
1555
# parameter-to-function errors.
920
class DuplicateKey(BzrNewError):
921
"""Key %(key)s is already present in map"""
924
class MalformedTransform(BzrNewError):
925
"""Tree transform is malformed %(conflicts)r"""
928
class BzrBadParameter(BzrNewError):
929
"""A bad parameter : %(param)s is not usable.
931
This exception should never be thrown, but it is a base class for all
932
parameter-to-function errors.
1557
934
def __init__(self, param):
1558
BzrError.__init__(self)
935
BzrNewError.__init__(self)
1559
936
self.param = param
1562
939
class BzrBadParameterNotUnicode(BzrBadParameter):
1564
_fmt = "Parameter %(param)s is neither unicode nor utf8."
1567
class ReusingTransform(BzrError):
1569
_fmt = "Attempt to reuse a transform that has already been applied."
1572
class CantMoveRoot(BzrError):
1574
_fmt = "Moving the root directory is not supported at this time"
1577
class BzrMoveFailedError(BzrError):
1579
_fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1581
def __init__(self, from_path='', to_path='', extra=None):
1582
BzrError.__init__(self)
1584
self.extra = ': ' + str(extra)
1588
has_from = len(from_path) > 0
1589
has_to = len(to_path) > 0
1591
self.from_path = osutils.splitpath(from_path)[-1]
1596
self.to_path = osutils.splitpath(to_path)[-1]
1601
if has_from and has_to:
1602
self.operator = " =>"
1604
self.from_path = "from " + from_path
1606
self.operator = "to"
1608
self.operator = "file"
1611
class BzrRenameFailedError(BzrMoveFailedError):
1613
_fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
1615
def __init__(self, from_path, to_path, extra=None):
1616
BzrMoveFailedError.__init__(self, from_path, to_path, extra)
940
"""Parameter %(param)s is neither unicode nor utf8."""
943
class ReusingTransform(BzrNewError):
944
"""Attempt to reuse a transform that has already been applied."""
947
class CantMoveRoot(BzrNewError):
948
"""Moving the root directory is not supported at this time"""
1619
951
class BzrBadParameterNotString(BzrBadParameter):
1621
_fmt = "Parameter %(param)s is not a string or unicode string."
952
"""Parameter %(param)s is not a string or unicode string."""
1624
955
class BzrBadParameterMissing(BzrBadParameter):
1626
_fmt = "Parameter $(param)s is required but not present."
956
"""Parameter $(param)s is required but not present."""
1629
959
class BzrBadParameterUnicode(BzrBadParameter):
1631
_fmt = ("Parameter %(param)s is unicode but"
1632
" only byte-strings are permitted.")
960
"""Parameter %(param)s is unicode but only byte-strings are permitted."""
1635
963
class BzrBadParameterContainsNewline(BzrBadParameter):
1637
_fmt = "Parameter %(param)s contains a newline."
1640
class DependencyNotPresent(BzrError):
1642
_fmt = 'Unable to import library "%(library)s": %(error)s'
964
"""Parameter %(param)s contains a newline."""
967
class DependencyNotPresent(BzrNewError):
968
"""Unable to import library "%(library)s": %(error)s"""
1644
970
def __init__(self, library, error):
1645
BzrError.__init__(self, library=library, error=error)
971
BzrNewError.__init__(self, library=library, error=error)
1648
974
class ParamikoNotPresent(DependencyNotPresent):
1650
_fmt = "Unable to import paramiko (required for sftp support): %(error)s"
975
"""Unable to import paramiko (required for sftp support): %(error)s"""
1652
977
def __init__(self, error):
1653
978
DependencyNotPresent.__init__(self, 'paramiko', error)
1656
class PointlessMerge(BzrError):
1658
_fmt = "Nothing to merge."
1661
class UninitializableFormat(BzrError):
1663
_fmt = "Format %(format)s cannot be initialised by this version of bzr."
981
class PointlessMerge(BzrNewError):
982
"""Nothing to merge."""
985
class UninitializableFormat(BzrNewError):
986
"""Format %(format)s cannot be initialised by this version of bzr."""
1665
988
def __init__(self, format):
1666
BzrError.__init__(self)
989
BzrNewError.__init__(self)
1667
990
self.format = format
1670
class BadConversionTarget(BzrError):
1672
_fmt = "Cannot convert to format %(format)s. %(problem)s"
993
class BadConversionTarget(BzrNewError):
994
"""Cannot convert to format %(format)s. %(problem)s"""
1674
996
def __init__(self, problem, format):
1675
BzrError.__init__(self)
997
BzrNewError.__init__(self)
1676
998
self.problem = problem
1677
999
self.format = format
1680
class NoDiff(BzrError):
1682
_fmt = "Diff is not installed on this machine: %(msg)s"
1002
class NoDiff(BzrNewError):
1003
"""Diff is not installed on this machine: %(msg)s"""
1684
1005
def __init__(self, msg):
1685
BzrError.__init__(self, msg=msg)
1688
class NoDiff3(BzrError):
1690
_fmt = "Diff3 is not installed on this machine."
1693
class ExistingLimbo(BzrError):
1695
_fmt = """This tree contains left-over files from a failed operation.
1696
Please examine %(limbo_dir)s to see if it contains any files you wish to
1697
keep, and delete it when you are done."""
1699
def __init__(self, limbo_dir):
1700
BzrError.__init__(self)
1701
self.limbo_dir = limbo_dir
1704
class ImmortalLimbo(BzrError):
1706
_fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
1707
Please examine %(limbo_dir)s to see if it contains any files you wish to
1708
keep, and delete it when you are done."""
1710
def __init__(self, limbo_dir):
1711
BzrError.__init__(self)
1712
self.limbo_dir = limbo_dir
1715
class OutOfDateTree(BzrError):
1717
_fmt = "Working tree is out of date, please run 'bzr update'."
1006
BzrNewError.__init__(self, msg=msg)
1009
class NoDiff3(BzrNewError):
1010
"""Diff3 is not installed on this machine."""
1013
class ExistingLimbo(BzrNewError):
1014
"""This tree contains left-over files from a failed operation.
1015
Please examine %(limbo_dir)s to see if it contains any files you wish to
1016
keep, and delete it when you are done.
1018
def __init__(self, limbo_dir):
1019
BzrNewError.__init__(self)
1020
self.limbo_dir = limbo_dir
1023
class ImmortalLimbo(BzrNewError):
1024
"""Unable to delete transform temporary directory $(limbo_dir)s.
1025
Please examine %(limbo_dir)s to see if it contains any files you wish to
1026
keep, and delete it when you are done.
1028
def __init__(self, limbo_dir):
1029
BzrNewError.__init__(self)
1030
self.limbo_dir = limbo_dir
1033
class OutOfDateTree(BzrNewError):
1034
"""Working tree is out of date, please run 'bzr update'."""
1719
1036
def __init__(self, tree):
1720
BzrError.__init__(self)
1037
BzrNewError.__init__(self)
1721
1038
self.tree = tree
1724
class PublicBranchOutOfDate(BzrError):
1726
_fmt = 'Public branch "%(public_location)s" lacks revision '\
1729
def __init__(self, public_location, revstring):
1730
import bzrlib.urlutils as urlutils
1731
public_location = urlutils.unescape_for_display(public_location,
1733
BzrError.__init__(self, public_location=public_location,
1734
revstring=revstring)
1737
class MergeModifiedFormatError(BzrError):
1739
_fmt = "Error in merge modified format"
1742
class ConflictFormatError(BzrError):
1744
_fmt = "Format error in conflict listings"
1747
class CorruptRepository(BzrError):
1749
_fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1750
"Please run bzr reconcile on this repository.")
1041
class MergeModifiedFormatError(BzrNewError):
1042
"""Error in merge modified format"""
1045
class ConflictFormatError(BzrNewError):
1046
"""Format error in conflict listings"""
1049
class CorruptRepository(BzrNewError):
1050
"""An error has been detected in the repository %(repo_path)s.
1051
Please run bzr reconcile on this repository."""
1752
1053
def __init__(self, repo):
1753
BzrError.__init__(self)
1054
BzrNewError.__init__(self)
1754
1055
self.repo_path = repo.bzrdir.root_transport.base
1757
class UpgradeRequired(BzrError):
1759
_fmt = "To use this feature you must upgrade your branch at %(path)s."
1058
class UpgradeRequired(BzrNewError):
1059
"""To use this feature you must upgrade your branch at %(path)s."""
1761
1061
def __init__(self, path):
1762
BzrError.__init__(self)
1062
BzrNewError.__init__(self)
1763
1063
self.path = path
1766
class LocalRequiresBoundBranch(BzrError):
1768
_fmt = "Cannot perform local-only commits on unbound branches."
1771
class MissingProgressBarFinish(BzrError):
1773
_fmt = "A nested progress bar was not 'finished' correctly."
1776
class InvalidProgressBarType(BzrError):
1778
_fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
1779
" is not a supported type Select one of: %(valid_types)s")
1066
class LocalRequiresBoundBranch(BzrNewError):
1067
"""Cannot perform local-only commits on unbound branches."""
1070
class MissingProgressBarFinish(BzrNewError):
1071
"""A nested progress bar was not 'finished' correctly."""
1074
class InvalidProgressBarType(BzrNewError):
1075
"""Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
1076
Select one of: %(valid_types)s"""
1781
1078
def __init__(self, bar_type, valid_types):
1782
BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1785
class UnsupportedOperation(BzrError):
1787
_fmt = ("The method %(mname)s is not supported on"
1788
" objects of type %(tname)s.")
1079
BzrNewError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1082
class UnsupportedOperation(BzrNewError):
1083
"""The method %(mname)s is not supported on objects of type %(tname)s."""
1790
1084
def __init__(self, method, method_self):
1791
1085
self.method = method
1792
1086
self.mname = method.__name__
1793
1087
self.tname = type(method_self).__name__
1796
class CannotSetRevisionId(UnsupportedOperation):
1797
"""Raised when a commit is attempting to set a revision id but cant."""
1800
class NonAsciiRevisionId(UnsupportedOperation):
1801
"""Raised when a commit is attempting to set a non-ascii revision id
1806
class BinaryFile(BzrError):
1808
_fmt = "File is binary but should be text."
1811
class IllegalPath(BzrError):
1813
_fmt = "The path %(path)s is not permitted on this platform"
1090
class BinaryFile(BzrNewError):
1091
"""File is binary but should be text."""
1094
class IllegalPath(BzrNewError):
1095
"""The path %(path)s is not permitted on this platform"""
1815
1097
def __init__(self, path):
1816
BzrError.__init__(self)
1098
BzrNewError.__init__(self)
1817
1099
self.path = path
1820
class TestamentMismatch(BzrError):
1822
_fmt = """Testament did not match expected value.
1823
For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
1102
class TestamentMismatch(BzrNewError):
1103
"""Testament did not match expected value.
1104
For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
1826
1107
def __init__(self, revision_id, expected, measured):
1827
1108
self.revision_id = revision_id
1828
1109
self.expected = expected
1829
1110
self.measured = measured
1832
class NotABundle(BzrError):
1834
_fmt = "Not a bzr revision-bundle: %(text)r"
1113
class NotABundle(BzrNewError):
1114
"""Not a bzr revision-bundle: %(text)r"""
1836
1116
def __init__(self, text):
1837
BzrError.__init__(self)
1117
BzrNewError.__init__(self)
1838
1118
self.text = text
1841
class BadBundle(BzrError):
1843
_fmt = "Bad bzr revision-bundle: %(text)r"
1121
class BadBundle(BzrNewError):
1122
"""Bad bzr revision-bundle: %(text)r"""
1845
1124
def __init__(self, text):
1846
BzrError.__init__(self)
1125
BzrNewError.__init__(self)
1847
1126
self.text = text
1850
1129
class MalformedHeader(BadBundle):
1852
_fmt = "Malformed bzr revision-bundle header: %(text)r"
1130
"""Malformed bzr revision-bundle header: %(text)r"""
1132
def __init__(self, text):
1133
BzrNewError.__init__(self)
1855
1137
class MalformedPatches(BadBundle):
1857
_fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1138
"""Malformed patches in bzr revision-bundle: %(text)r"""
1140
def __init__(self, text):
1141
BzrNewError.__init__(self)
1860
1145
class MalformedFooter(BadBundle):
1862
_fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1146
"""Malformed footer in bzr revision-bundle: %(text)r"""
1148
def __init__(self, text):
1149
BzrNewError.__init__(self)
1865
1153
class UnsupportedEOLMarker(BadBundle):
1867
_fmt = "End of line marker was not \\n in bzr revision-bundle"
1154
"""End of line marker was not \\n in bzr revision-bundle"""
1869
1156
def __init__(self):
1870
# XXX: BadBundle's constructor assumes there's explanatory text,
1871
# but for this there is not
1872
BzrError.__init__(self)
1875
class IncompatibleBundleFormat(BzrError):
1877
_fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1879
def __init__(self, bundle_format, other):
1880
BzrError.__init__(self)
1881
self.bundle_format = bundle_format
1885
class BadInventoryFormat(BzrError):
1887
_fmt = "Root class for inventory serialization errors"
1157
BzrNewError.__init__(self)
1160
class BadInventoryFormat(BzrNewError):
1161
"""Root class for inventory serialization errors"""
1890
1164
class UnexpectedInventoryFormat(BadInventoryFormat):
1892
_fmt = "The inventory was not in the expected format:\n %(msg)s"
1165
"""The inventory was not in the expected format:\n %(msg)s"""
1894
1167
def __init__(self, msg):
1895
1168
BadInventoryFormat.__init__(self, msg=msg)
1898
class RootNotRich(BzrError):
1900
_fmt = """This operation requires rich root data storage"""
1903
class NoSmartMedium(BzrError):
1905
_fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
1907
internal_error = True
1909
def __init__(self, transport):
1910
self.transport = transport
1913
class NoSmartServer(NotBranchError):
1915
_fmt = "No smart server available at %(url)s"
1917
def __init__(self, url):
1921
class UnknownSSH(BzrError):
1923
_fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1171
class UnknownSSH(BzrNewError):
1172
"""Unrecognised value for BZR_SSH environment variable: %(vendor)s"""
1925
1174
def __init__(self, vendor):
1926
BzrError.__init__(self)
1175
BzrNewError.__init__(self)
1927
1176
self.vendor = vendor
1930
class SSHVendorNotFound(BzrError):
1932
_fmt = ("Don't know how to handle SSH connections."
1933
" Please set BZR_SSH environment variable.")
1936
class GhostRevisionUnusableHere(BzrError):
1938
_fmt = "Ghost revision {%(revision_id)s} cannot be used here."
1179
class GhostRevisionUnusableHere(BzrNewError):
1180
"""Ghost revision {%(revision_id)s} cannot be used here."""
1940
1182
def __init__(self, revision_id):
1941
BzrError.__init__(self)
1183
BzrNewError.__init__(self)
1942
1184
self.revision_id = revision_id
1945
class IllegalUseOfScopeReplacer(BzrError):
1947
_fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
1948
" %(msg)s%(extra)s")
1950
internal_error = True
1187
class IllegalUseOfScopeReplacer(BzrNewError):
1188
"""ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"""
1190
is_user_error = False
1952
1192
def __init__(self, name, msg, extra=None):
1953
BzrError.__init__(self)
1193
BzrNewError.__init__(self)
1954
1194
self.name = name