97
102
return s.encode('utf8')
99
104
except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
100
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
105
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
101
106
% (self.__class__.__name__,
103
108
getattr(self, '_fmt', None),
106
111
def _get_format_string(self):
107
112
"""Return format string for this exception or None"""
127
132
# readable explanation
129
134
def __init__(self, *args, **kwds):
130
# XXX: Use the underlying BzrError to always generate the args attribute
131
# if it doesn't exist. We can't use super here, because exceptions are
132
# old-style classes in python2.4 (but new in 2.5). --bmc, 20060426
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).
133
139
symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
134
'please convert %s to use BzrError instead'
140
'please convert %s to use BzrError instead'
135
141
% self.__class__.__name__,
136
142
DeprecationWarning,
199
216
self.revision_id = revision_id
200
217
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
227
class NoHelpTopic(BzrError):
229
_fmt = ("No help could be found for '%(topic)s'. "
230
"Please use 'bzr help topics' to obtain a list of topics.")
232
def __init__(self, topic):
203
236
class NoSuchId(BzrError):
319
360
_fmt = "File exists: %(path)r%(extra)s"
363
class RenameFailedFilesExist(BzrError):
364
"""Used when renaming and both source and dest exist."""
366
_fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
369
def __init__(self, source, dest, extra=None):
370
BzrError.__init__(self)
371
self.source = str(source)
372
self.dest = str(dest)
374
self.extra = ' ' + str(extra)
379
class NotADirectory(PathError):
381
_fmt = "%(path)r is not a directory %(extra)s"
384
class NotInWorkingDirectory(PathError):
386
_fmt = "%(path)r is not in the working directory %(extra)s"
322
389
class DirectoryNotEmpty(PathError):
324
391
_fmt = "Directory not empty: %(path)r%(extra)s"
414
492
self.path = urlutils.unescape_for_display(path, 'ascii')
495
class NoSubmitBranch(PathError):
497
_fmt = 'No submit branch available for branch "%(path)s"'
499
def __init__(self, branch):
500
import bzrlib.urlutils as urlutils
501
self.path = urlutils.unescape_for_display(branch.base, 'ascii')
417
504
class AlreadyBranchError(PathError):
419
506
_fmt = "Already a branch: %(path)s."
491
589
self.repo_format = repo_format
592
class AlreadyVersionedError(BzrError):
593
"""Used when a path is expected not to be versioned, but it is."""
595
_fmt = "%(context_info)s%(path)s is already versioned"
597
def __init__(self, path, context_info=None):
598
"""Construct a new AlreadyVersionedError.
600
:param path: This is the path which is versioned,
601
which should be in a user friendly form.
602
:param context_info: If given, this is information about the context,
603
which could explain why this is expected to not be versioned.
605
BzrError.__init__(self)
607
if context_info is None:
608
self.context_info = ''
610
self.context_info = context_info + ". "
494
613
class NotVersionedError(BzrError):
496
_fmt = "%(path)s is not versioned"
498
def __init__(self, path):
614
"""Used when a path is expected to be versioned, but it is not."""
616
_fmt = "%(context_info)s%(path)s is not versioned"
618
def __init__(self, path, context_info=None):
619
"""Construct a new NotVersionedError.
621
:param path: This is the path which is not versioned,
622
which should be in a user friendly form.
623
:param context_info: If given, this is information about the context,
624
which could explain why this is expected to be versioned.
499
626
BzrError.__init__(self)
628
if context_info is None:
629
self.context_info = ''
631
self.context_info = context_info + ". "
503
634
class PathsNotVersionedError(BzrError):
504
# used when reporting several paths are not versioned
635
"""Used when reporting several paths which are not versioned"""
506
637
_fmt = "Path(s) are not versioned: %(paths_as_string)s"
515
646
class PathsDoNotExist(BzrError):
517
_fmt = "Path(s) do not exist: %(paths_as_string)s"
648
_fmt = "Path(s) do not exist: %(paths_as_string)s%(extra)s"
519
650
# used when reporting that paths are neither versioned nor in the working
522
def __init__(self, paths):
653
def __init__(self, paths, extra=None):
523
654
# circular import
524
655
from bzrlib.osutils import quotefn
525
656
BzrError.__init__(self)
526
657
self.paths = paths
527
658
self.paths_as_string = ' '.join([quotefn(p) for p in paths])
660
self.extra = ': ' + str(extra)
530
665
class BadFileKindError(BzrError):
532
_fmt = "Cannot operate on %(filename)s of unsupported kind %(kind)s"
667
_fmt = 'Cannot operate on "%(filename)s" of unsupported kind "%(kind)s"'
669
def __init__(self, filename, kind):
670
BzrError.__init__(self, filename=filename, kind=kind)
535
673
class ForbiddenControlFileError(BzrError):
548
688
# New code should prefer to raise specific subclasses
549
689
def __init__(self, message):
550
self.message = message
690
# Python 2.5 uses a slot for StandardError.message,
691
# so use a different variable name
692
# so it is exposed in self.__dict__
696
class LockActive(LockError):
698
_fmt = "The lock for '%(lock_description)s' is in use and cannot be broken."
700
internal_error = False
702
def __init__(self, lock_description):
703
self.lock_description = lock_description
553
706
class CommitNotPossible(LockError):
571
724
_fmt = "A write attempt was made in a read only transaction on %(obj)s"
726
# TODO: There should also be an error indicating that you need a write
727
# lock and don't have any lock at all... mbp 20070226
573
729
def __init__(self, obj):
733
class ReadOnlyLockError(LockError):
735
_fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
737
def __init__(self, fname, msg):
738
LockError.__init__(self, '')
577
743
class OutSideTransaction(BzrError):
579
_fmt = "A transaction related operation was attempted after the transaction finished."
745
_fmt = ("A transaction related operation was attempted after"
746
" the transaction finished.")
582
749
class ObjectNotLocked(LockError):
584
751
_fmt = "%(obj)r is not locked"
586
internal_error = True
588
753
# this can indicate that any particular object is not locked; see also
589
754
# LockNotHeld which means that a particular *lock* object is not held by
590
755
# the caller -- perhaps they should be unified.
611
776
class LockContention(LockError):
613
778
_fmt = "Could not acquire lock %(lock)s"
614
# TODO: show full url for lock, combining the transport and relative bits?
779
# TODO: show full url for lock, combining the transport and relative
782
internal_error = False
616
784
def __init__(self, lock):
620
788
class LockBroken(LockError):
622
_fmt = "Lock was broken while still open: %(lock)s - check storage consistency!"
790
_fmt = ("Lock was broken while still open: %(lock)s"
791
" - check storage consistency!")
793
internal_error = False
624
795
def __init__(self, lock):
640
814
_fmt = "Lock not held: %(lock)s"
816
internal_error = False
642
818
def __init__(self, lock):
822
class TokenLockingNotSupported(LockError):
824
_fmt = "The object %(obj)s does not support token specifying a token when locking."
826
internal_error = True
828
def __init__(self, obj):
832
class TokenMismatch(LockBroken):
834
_fmt = "The lock token %(given_token)r does not match lock token %(lock_token)r."
836
internal_error = True
838
def __init__(self, given_token, lock_token):
839
self.given_token = given_token
840
self.lock_token = lock_token
646
843
class PointlessCommit(BzrError):
648
845
_fmt = "No changes to commit"
677
874
BzrError.__init__(self, branch=branch, revision=revision)
877
class NotLeftParentDescendant(BzrError):
879
_fmt = ("Revision %(old_revision)s is not the left parent of"
880
" %(new_revision)s, but branch %(branch_location)s expects this")
882
internal_error = True
884
def __init__(self, branch, old_revision, new_revision):
885
BzrError.__init__(self, branch_location=branch.base,
886
old_revision=old_revision,
887
new_revision=new_revision)
680
890
class NoSuchRevisionSpec(BzrError):
682
892
_fmt = "No namespace registered for string: %(spec)r"
685
895
BzrError.__init__(self, spec=spec)
898
class NoSuchRevisionInTree(NoSuchRevision):
899
"""When using Tree.revision_tree, and the revision is not accessible."""
901
_fmt = "The revision id %(revision_id)s is not present in the tree %(tree)s."
903
def __init__(self, tree, revision_id):
904
BzrError.__init__(self)
906
self.revision_id = revision_id
688
909
class InvalidRevisionSpec(BzrError):
690
_fmt = "Requested revision: %(spec)r does not exist in branch: %(branch)s%(extra)s"
911
_fmt = ("Requested revision: %(spec)r does not exist in branch:"
912
" %(branch)s%(extra)s")
692
914
def __init__(self, spec, branch, extra=None):
693
915
BzrError.__init__(self, branch=branch, spec=spec)
702
924
_fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
927
class AppendRevisionsOnlyViolation(BzrError):
929
_fmt = ('Operation denied because it would change the main history,'
930
' which is not permitted by the append_revisions_only setting on'
931
' branch "%(location)s".')
933
def __init__(self, location):
934
import bzrlib.urlutils as urlutils
935
location = urlutils.unescape_for_display(location, 'ascii')
936
BzrError.__init__(self, location=location)
705
939
class DivergedBranches(BzrError):
707
_fmt = "These branches have diverged. Use the merge command to reconcile them."""
941
_fmt = ("These branches have diverged."
942
" Use the merge command to reconcile them.")
709
944
internal_error = False
713
948
self.branch2 = branch2
951
class NotLefthandHistory(BzrError):
953
_fmt = "Supplied history does not follow left-hand parents"
955
internal_error = True
957
def __init__(self, history):
958
BzrError.__init__(self, history=history)
716
961
class UnrelatedBranches(BzrError):
718
_fmt = "Branches have no common ancestor, and no merge base revision was specified."
963
_fmt = ("Branches have no common ancestor, and"
964
" no merge base revision was specified.")
720
966
internal_error = False
881
1130
class WeaveTextDiffers(WeaveError):
883
_fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
1132
_fmt = ("Weaves differ on text content. Revision:"
1133
" {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
885
1135
def __init__(self, revision_id, weave_a, weave_b):
886
1136
WeaveError.__init__(self)
892
1142
class WeaveTextDiffers(WeaveError):
894
_fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
1144
_fmt = ("Weaves differ on text content. Revision:"
1145
" {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
896
1147
def __init__(self, revision_id, weave_a, weave_b):
897
1148
WeaveError.__init__(self)
1068
1336
InvalidHttpResponse.__init__(self, path, msg)
1339
class RedirectRequested(TransportError):
1341
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1343
def __init__(self, source, target, is_permament=False, qual_proto=None):
1344
self.source = source
1345
self.target = target
1347
self.permanently = ' permanently'
1349
self.permanently = ''
1350
self.is_permament = is_permament
1351
self._qualified_proto = qual_proto
1352
TransportError.__init__(self)
1354
def _requalify_url(self, url):
1355
"""Restore the qualified proto in front of the url"""
1356
# When this exception is raised, source and target are in
1357
# user readable format. But some transports may use a
1358
# different proto (http+urllib:// will present http:// to
1359
# the user. If a qualified proto is specified, the code
1360
# trapping the exception can get the qualified urls to
1361
# properly handle the redirection themself (creating a
1362
# new transport object from the target url for example).
1363
# But checking that the scheme of the original and
1364
# redirected urls are the same can be tricky. (see the
1365
# FIXME in BzrDir.open_from_transport for the unique use
1367
if self._qualified_proto is None:
1370
# The TODO related to NotBranchError mention that doing
1371
# that kind of manipulation on the urls may not be the
1372
# exception object job. On the other hand, this object is
1373
# the interface between the code and the user so
1374
# presenting the urls in different ways is indeed its
1377
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1378
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1381
def get_source_url(self):
1382
return self._requalify_url(self.source)
1384
def get_target_url(self):
1385
return self._requalify_url(self.target)
1388
class TooManyRedirections(TransportError):
1390
_fmt = "Too many redirections"
1071
1392
class ConflictsInTree(BzrError):
1073
1394
_fmt = "Working tree has conflicts."
1203
1525
self.file_id = file_id
1528
class DuplicateFileId(BzrError):
1530
_fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
1532
def __init__(self, file_id, entry):
1533
BzrError.__init__(self)
1534
self.file_id = file_id
1206
1538
class DuplicateKey(BzrError):
1208
1540
_fmt = "Key %(key)s is already present in map"
1543
class DuplicateHelpPrefix(BzrError):
1545
_fmt = "The prefix %(prefix)s is in the help search path twice."
1547
def __init__(self, prefix):
1548
self.prefix = prefix
1211
1551
class MalformedTransform(BzrError):
1213
1553
_fmt = "Tree transform is malformed %(conflicts)r"
1252
1592
_fmt = "Moving the root directory is not supported at this time"
1595
class BzrMoveFailedError(BzrError):
1597
_fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1599
def __init__(self, from_path='', to_path='', extra=None):
1600
BzrError.__init__(self)
1602
self.extra = ': ' + str(extra)
1606
has_from = len(from_path) > 0
1607
has_to = len(to_path) > 0
1609
self.from_path = osutils.splitpath(from_path)[-1]
1614
self.to_path = osutils.splitpath(to_path)[-1]
1619
if has_from and has_to:
1620
self.operator = " =>"
1622
self.from_path = "from " + from_path
1624
self.operator = "to"
1626
self.operator = "file"
1629
class BzrRenameFailedError(BzrMoveFailedError):
1631
_fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
1633
def __init__(self, from_path, to_path, extra=None):
1634
BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1636
class BzrRemoveChangedFilesError(BzrError):
1637
"""Used when user is trying to remove changed files."""
1639
_fmt = ("Can't remove changed or unknown files:\n%(changes_as_text)s"
1640
"Use --keep to not delete them, or --force to delete them regardless.")
1642
def __init__(self, tree_delta):
1643
BzrError.__init__(self)
1644
self.changes_as_text = tree_delta.get_changes_as_text()
1645
#self.paths_as_string = '\n'.join(changed_files)
1646
#self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
1255
1649
class BzrBadParameterNotString(BzrBadParameter):
1257
1651
_fmt = "Parameter %(param)s is not a string or unicode string."
1356
1751
self.tree = tree
1754
class PublicBranchOutOfDate(BzrError):
1756
_fmt = 'Public branch "%(public_location)s" lacks revision '\
1759
def __init__(self, public_location, revstring):
1760
import bzrlib.urlutils as urlutils
1761
public_location = urlutils.unescape_for_display(public_location,
1763
BzrError.__init__(self, public_location=public_location,
1764
revstring=revstring)
1359
1767
class MergeModifiedFormatError(BzrError):
1361
1769
_fmt = "Error in merge modified format"
1439
1850
class TestamentMismatch(BzrError):
1441
_fmt = """Testament did not match expected value.
1442
For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
1852
_fmt = """Testament did not match expected value.
1853
For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
1443
1854
{%(measured)s}"""
1445
1856
def __init__(self, revision_id, expected, measured):
1579
2004
class ImportNameCollision(BzrError):
1581
_fmt = "Tried to import an object to the same name as an existing object. %(name)s"
2006
_fmt = ("Tried to import an object to the same name as"
2007
" an existing object. %(name)s")
1583
2009
internal_error = True
1585
2011
def __init__(self, name):
1586
2012
BzrError.__init__(self)
1587
2013
self.name = name
2016
class NotAMergeDirective(BzrError):
2017
"""File starting with %(firstline)r is not a merge directive"""
2018
def __init__(self, firstline):
2019
BzrError.__init__(self, firstline=firstline)
2022
class NoMergeSource(BzrError):
2023
"""Raise if no merge source was specified for a merge directive"""
2025
_fmt = "A merge directive must provide either a bundle or a public"\
2029
class PatchMissing(BzrError):
2030
"""Raise a patch type was specified but no patch supplied"""
2032
_fmt = "patch_type was %(patch_type)s, but no patch was supplied."
2034
def __init__(self, patch_type):
2035
BzrError.__init__(self)
2036
self.patch_type = patch_type
2039
class UnsupportedInventoryKind(BzrError):
2041
_fmt = """Unsupported entry kind %(kind)s"""
2043
def __init__(self, kind):
2047
class BadSubsumeSource(BzrError):
2049
_fmt = """Can't subsume %(other_tree)s into %(tree)s. %(reason)s"""
2051
def __init__(self, tree, other_tree, reason):
2053
self.other_tree = other_tree
2054
self.reason = reason
2057
class SubsumeTargetNeedsUpgrade(BzrError):
2059
_fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2061
def __init__(self, other_tree):
2062
self.other_tree = other_tree
2065
class BadReferenceTarget(BzrError):
2067
_fmt = "Can't add reference to %(other_tree)s into %(tree)s. %(reason)s"
2069
internal_error = True
2071
def __init__(self, tree, other_tree, reason):
2073
self.other_tree = other_tree
2074
self.reason = reason
2077
class NoSuchTag(BzrError):
2079
_fmt = "No such tag: %(tag_name)s"
2081
def __init__(self, tag_name):
2082
self.tag_name = tag_name
2085
class TagsNotSupported(BzrError):
2087
_fmt = ("Tags not supported by %(branch)s;"
2088
" you may be able to use bzr upgrade --dirstate-tags.")
2090
def __init__(self, branch):
2091
self.branch = branch
2094
class TagAlreadyExists(BzrError):
2096
_fmt = "Tag %(tag_name)s already exists."
2098
def __init__(self, tag_name):
2099
self.tag_name = tag_name
2102
class MalformedBugIdentifier(BzrError):
2104
_fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2106
def __init__(self, bug_id, reason):
2107
self.bug_id = bug_id
2108
self.reason = reason
2111
class UnknownBugTrackerAbbreviation(BzrError):
2113
_fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
2116
def __init__(self, abbreviation, branch):
2117
self.abbreviation = abbreviation
2118
self.branch = branch
2121
class UnexpectedSmartServerResponse(BzrError):
2123
_fmt = "Could not understand response from smart server: %(response_tuple)r"
2125
def __init__(self, response_tuple):
2126
self.response_tuple = response_tuple