49
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
51
:cvar internal_error: if True this was probably caused by a bzr bug and
52
should be displayed with a traceback; if False (or absent) this was
53
53
probably a user or environment error and they don't need the gory details.
54
54
(That can be overridden by -Derror on the command line.)
102
102
return s.encode('utf8')
104
104
except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
105
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
105
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
106
106
% (self.__class__.__name__,
108
108
getattr(self, '_fmt', None),
111
111
def _get_format_string(self):
112
112
"""Return format string for this exception or None"""
132
132
# readable explanation
134
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
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).
138
139
symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
139
'please convert %s to use BzrError instead'
140
'please convert %s to use BzrError instead'
140
141
% self.__class__.__name__,
141
142
DeprecationWarning,
153
154
return s.encode('utf8')
155
156
except (TypeError, NameError, ValueError, KeyError), e:
156
return 'Unprintable exception %s(%r): %s' \
157
return 'Unprintable exception %s(%r): %r' \
157
158
% (self.__class__.__name__,
158
self.__dict__, str(e))
161
162
class AlreadyBuilding(BzrError):
211
223
def __init__(self, revision_id):
212
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):
214
236
class NoSuchId(BzrError):
216
238
_fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
469
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')
472
504
class AlreadyBranchError(PathError):
474
506
_fmt = "Already a branch: %(path)s."
483
515
class AtomicFileAlreadyClosed(PathError):
485
_fmt = "'%(function)s' called on an AtomicFile after it was closed: %(path)s"
517
_fmt = ("'%(function)s' called on an AtomicFile after it was closed:"
487
520
def __init__(self, path, function):
488
521
PathError.__init__(self, path=path, extra=None)
492
525
class InaccessibleParent(PathError):
494
_fmt = "Parent not accessible given base %(base)s and relative path %(path)s"
527
_fmt = ("Parent not accessible given base %(base)s and"
528
" relative path %(path)s")
496
530
def __init__(self, path, base):
497
531
PathError.__init__(self, path)
537
571
self.bzrdir = bzrdir_format
574
class IncompatibleRepositories(BzrError):
576
_fmt = "Repository %(target)s is not compatible with repository"\
579
def __init__(self, source, target):
580
BzrError.__init__(self, target=target, source=source)
540
583
class IncompatibleRevision(BzrError):
542
585
_fmt = "Revision is not compatible with %(repo_format)s"
552
595
_fmt = "%(context_info)s%(path)s is already versioned"
554
597
def __init__(self, path, context_info=None):
555
"""Construct a new NotVersionedError.
598
"""Construct a new AlreadyVersionedError.
557
600
:param path: This is the path which is versioned,
558
601
which should be in a user friendly form.
622
665
class BadFileKindError(BzrError):
624
_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)
627
673
class ForbiddenControlFileError(BzrError):
642
688
# New code should prefer to raise specific subclasses
643
689
def __init__(self, message):
644
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
647
706
class CommitNotPossible(LockError):
665
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
667
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, '')
671
743
class OutSideTransaction(BzrError):
673
_fmt = "A transaction related operation was attempted after the transaction finished."
745
_fmt = ("A transaction related operation was attempted after"
746
" the transaction finished.")
676
749
class ObjectNotLocked(LockError):
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
747
843
class PointlessCommit(BzrError):
749
845
_fmt = "No changes to commit"
848
class CannotCommitSelectedFileMerge(BzrError):
850
_fmt = 'Selected-file commit of merges is not supported yet:'\
851
' files %(files_str)s'
853
def __init__(self, files):
854
files_str = ', '.join(files)
855
BzrError.__init__(self, files=files, files_str=files_str)
752
858
class UpgradeReadonly(BzrError):
754
860
_fmt = "Upgrade URL cannot work with readonly URLs."
799
905
BzrError.__init__(self, spec=spec)
908
class NoSuchRevisionInTree(NoSuchRevision):
909
"""When using Tree.revision_tree, and the revision is not accessible."""
911
_fmt = "The revision id %(revision_id)s is not present in the tree %(tree)s."
913
def __init__(self, tree, revision_id):
914
BzrError.__init__(self)
916
self.revision_id = revision_id
802
919
class InvalidRevisionSpec(BzrError):
804
_fmt = "Requested revision: %(spec)r does not exist in branch: %(branch)s%(extra)s"
921
_fmt = ("Requested revision: %(spec)r does not exist in branch:"
922
" %(branch)s%(extra)s")
806
924
def __init__(self, spec, branch, extra=None):
807
925
BzrError.__init__(self, branch=branch, spec=spec)
819
937
class AppendRevisionsOnlyViolation(BzrError):
821
_fmt = 'Operation denied because it would change the main history, '\
822
'which is not permitted by the append_revisions_only setting on'\
823
' branch "%(location)s".'
939
_fmt = ('Operation denied because it would change the main history,'
940
' which is not permitted by the append_revisions_only setting on'
941
' branch "%(location)s".')
825
943
def __init__(self, location):
826
944
import bzrlib.urlutils as urlutils
868
988
class NoCommonRoot(BzrError):
870
_fmt = "Revisions are not derived from the same root: " \
871
"%(revision_a)s %(revision_b)s."
990
_fmt = ("Revisions are not derived from the same root: "
991
"%(revision_a)s %(revision_b)s.")
873
993
def __init__(self, revision_a, revision_b):
874
994
BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
897
1017
def __init__(self, bases):
898
1018
warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
899
1019
DeprecationWarning)
900
msg = "The correct base is unclear, because %s are all equally close" %\
1020
msg = ("The correct base is unclear, because %s are all equally close"
902
1022
BzrError.__init__(self, msg)
903
1023
self.bases = bases
937
1058
class CommitToDoubleBoundBranch(BzrError):
939
_fmt = "Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."
1060
_fmt = ("Cannot commit to branch %(branch)s."
1061
" It is bound to %(master)s, which is bound to %(remote)s.")
941
1063
def __init__(self, branch, master, remote):
942
1064
BzrError.__init__(self)
1017
1140
class WeaveTextDiffers(WeaveError):
1019
_fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
1142
_fmt = ("Weaves differ on text content. Revision:"
1143
" {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
1021
1145
def __init__(self, revision_id, weave_a, weave_b):
1022
1146
WeaveError.__init__(self)
1028
1152
class WeaveTextDiffers(WeaveError):
1030
_fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
1154
_fmt = ("Weaves differ on text content. Revision:"
1155
" {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
1032
1157
def __init__(self, revision_id, weave_a, weave_b):
1033
1158
WeaveError.__init__(self)
1131
1256
class TooManyConcurrentRequests(BzrError):
1133
_fmt = ("The medium '%(medium)s' has reached its concurrent request limit. "
1134
"Be sure to finish_writing and finish_reading on the "
1135
"current request that is open.")
1258
_fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
1259
" Be sure to finish_writing and finish_reading on the"
1260
" currently open request.")
1137
1262
internal_error = True
1221
1346
InvalidHttpResponse.__init__(self, path, msg)
1349
class RedirectRequested(TransportError):
1351
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1353
def __init__(self, source, target, is_permament=False, qual_proto=None):
1354
self.source = source
1355
self.target = target
1357
self.permanently = ' permanently'
1359
self.permanently = ''
1360
self.is_permament = is_permament
1361
self._qualified_proto = qual_proto
1362
TransportError.__init__(self)
1364
def _requalify_url(self, url):
1365
"""Restore the qualified proto in front of the url"""
1366
# When this exception is raised, source and target are in
1367
# user readable format. But some transports may use a
1368
# different proto (http+urllib:// will present http:// to
1369
# the user. If a qualified proto is specified, the code
1370
# trapping the exception can get the qualified urls to
1371
# properly handle the redirection themself (creating a
1372
# new transport object from the target url for example).
1373
# But checking that the scheme of the original and
1374
# redirected urls are the same can be tricky. (see the
1375
# FIXME in BzrDir.open_from_transport for the unique use
1377
if self._qualified_proto is None:
1380
# The TODO related to NotBranchError mention that doing
1381
# that kind of manipulation on the urls may not be the
1382
# exception object job. On the other hand, this object is
1383
# the interface between the code and the user so
1384
# presenting the urls in different ways is indeed its
1387
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1388
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1391
def get_source_url(self):
1392
return self._requalify_url(self.source)
1394
def get_target_url(self):
1395
return self._requalify_url(self.target)
1398
class TooManyRedirections(TransportError):
1400
_fmt = "Too many redirections"
1224
1402
class ConflictsInTree(BzrError):
1226
1404
_fmt = "Working tree has conflicts."
1266
1444
class CantReprocessAndShowBase(BzrError):
1268
_fmt = "Can't reprocess and show base, because reprocessing obscures " \
1269
"the relationship of conflicting lines to the base"
1446
_fmt = ("Can't reprocess and show base, because reprocessing obscures "
1447
"the relationship of conflicting lines to the base")
1272
1450
class GraphCycleError(BzrError):
1356
1535
self.file_id = file_id
1538
class DuplicateFileId(BzrError):
1540
_fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
1542
def __init__(self, file_id, entry):
1543
BzrError.__init__(self)
1544
self.file_id = file_id
1359
1548
class DuplicateKey(BzrError):
1361
1550
_fmt = "Key %(key)s is already present in map"
1553
class DuplicateHelpPrefix(BzrError):
1555
_fmt = "The prefix %(prefix)s is in the help search path twice."
1557
def __init__(self, prefix):
1558
self.prefix = prefix
1364
1561
class MalformedTransform(BzrError):
1366
1563
_fmt = "Tree transform is malformed %(conflicts)r"
1446
1645
def __init__(self, from_path, to_path, extra=None):
1447
1646
BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1648
class BzrRemoveChangedFilesError(BzrError):
1649
"""Used when user is trying to remove changed files."""
1651
_fmt = ("Can't remove changed or unknown files:\n%(changes_as_text)s"
1652
"Use --keep to not delete them, or --force to delete them regardless.")
1654
def __init__(self, tree_delta):
1655
BzrError.__init__(self)
1656
self.changes_as_text = tree_delta.get_changes_as_text()
1657
#self.paths_as_string = '\n'.join(changed_files)
1658
#self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
1450
1661
class BzrBadParameterNotString(BzrBadParameter):
1551
1763
self.tree = tree
1766
class PublicBranchOutOfDate(BzrError):
1768
_fmt = 'Public branch "%(public_location)s" lacks revision '\
1771
def __init__(self, public_location, revstring):
1772
import bzrlib.urlutils as urlutils
1773
public_location = urlutils.unescape_for_display(public_location,
1775
BzrError.__init__(self, public_location=public_location,
1776
revstring=revstring)
1554
1779
class MergeModifiedFormatError(BzrError):
1556
1781
_fmt = "Error in merge modified format"
1593
1818
class InvalidProgressBarType(BzrError):
1595
_fmt = """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
1596
Select one of: %(valid_types)s"""
1820
_fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
1821
" is not a supported type Select one of: %(valid_types)s")
1598
1823
def __init__(self, bar_type, valid_types):
1599
1824
BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1634
1862
class TestamentMismatch(BzrError):
1636
_fmt = """Testament did not match expected value.
1637
For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
1864
_fmt = """Testament did not match expected value.
1865
For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
1638
1866
{%(measured)s}"""
1640
1868
def __init__(self, revision_id, expected, measured):
1709
1937
BadInventoryFormat.__init__(self, msg=msg)
1940
class RootNotRich(BzrError):
1942
_fmt = """This operation requires rich root data storage"""
1712
1945
class NoSmartMedium(BzrError):
1714
1947
_fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
1715
1949
internal_error = True
1717
1951
def __init__(self, transport):
1783
2025
self.name = name
2028
class NotAMergeDirective(BzrError):
2029
"""File starting with %(firstline)r is not a merge directive"""
2030
def __init__(self, firstline):
2031
BzrError.__init__(self, firstline=firstline)
1786
2034
class NoMergeSource(BzrError):
1787
2035
"""Raise if no merge source was specified for a merge directive"""
1789
2037
_fmt = "A merge directive must provide either a bundle or a public"\
1793
2041
class PatchMissing(BzrError):
1798
2046
def __init__(self, patch_type):
1799
2047
BzrError.__init__(self)
1800
2048
self.patch_type = patch_type
2051
class UnsupportedInventoryKind(BzrError):
2053
_fmt = """Unsupported entry kind %(kind)s"""
2055
def __init__(self, kind):
2059
class BadSubsumeSource(BzrError):
2061
_fmt = """Can't subsume %(other_tree)s into %(tree)s. %(reason)s"""
2063
def __init__(self, tree, other_tree, reason):
2065
self.other_tree = other_tree
2066
self.reason = reason
2069
class SubsumeTargetNeedsUpgrade(BzrError):
2071
_fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2073
def __init__(self, other_tree):
2074
self.other_tree = other_tree
2077
class BadReferenceTarget(BzrError):
2079
_fmt = "Can't add reference to %(other_tree)s into %(tree)s. %(reason)s"
2081
internal_error = True
2083
def __init__(self, tree, other_tree, reason):
2085
self.other_tree = other_tree
2086
self.reason = reason
2089
class NoSuchTag(BzrError):
2091
_fmt = "No such tag: %(tag_name)s"
2093
def __init__(self, tag_name):
2094
self.tag_name = tag_name
2097
class TagsNotSupported(BzrError):
2099
_fmt = ("Tags not supported by %(branch)s;"
2100
" you may be able to use bzr upgrade --dirstate-tags.")
2102
def __init__(self, branch):
2103
self.branch = branch
2106
class TagAlreadyExists(BzrError):
2108
_fmt = "Tag %(tag_name)s already exists."
2110
def __init__(self, tag_name):
2111
self.tag_name = tag_name
2114
class MalformedBugIdentifier(BzrError):
2116
_fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2118
def __init__(self, bug_id, reason):
2119
self.bug_id = bug_id
2120
self.reason = reason
2123
class UnknownBugTrackerAbbreviation(BzrError):
2125
_fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
2128
def __init__(self, abbreviation, branch):
2129
self.abbreviation = abbreviation
2130
self.branch = branch
2133
class UnexpectedSmartServerResponse(BzrError):
2135
_fmt = "Could not understand response from smart server: %(response_tuple)r"
2137
def __init__(self, response_tuple):
2138
self.response_tuple = response_tuple
2141
class NoDestinationAddress(BzrError):
2143
_fmt = "Message does not have a destination address."
2145
internal_error = True
2148
class SMTPError(BzrError):
2150
_fmt = "SMTP error: %(error)s"
2152
def __init__(self, error):