17
17
"""Exceptions for bzr, and reporting of them.
20
from __future__ import absolute_import
21
26
# TODO: is there any value in providing the .args field used by standard
22
27
# python exceptions? A list of values with no names seems less useful
103
108
getattr(self, '_fmt', None),
115
return self._format().encode('utf-8')
117
__unicode__ = _format
108
119
def __repr__(self):
109
120
return '%s(%s)' % (self.__class__.__name__, str(self))
113
124
fmt = getattr(self, '_fmt', None)
114
125
if fmt is not None:
115
126
from breezy.i18n import gettext
116
return gettext(fmt) # _fmt strings should be ascii
127
return gettext(fmt) # _fmt strings should be ascii
118
129
def __eq__(self, other):
119
130
if self.__class__ is not other.__class__:
171
182
self.transport = transport
185
class InvalidEntryName(InternalBzrError):
187
_fmt = "Invalid entry name: %(name)s"
189
def __init__(self, name):
190
BzrError.__init__(self)
174
194
class InvalidRevisionNumber(BzrError):
176
196
_fmt = "Invalid revision number %(revno)s"
248
class NoSuchIdInRepository(NoSuchId):
250
_fmt = ('The file id "%(file_id)s" is not present in the repository'
253
def __init__(self, repository, file_id):
254
BzrError.__init__(self, repository=repository, file_id=file_id)
228
257
class NotStacked(BranchError):
230
259
_fmt = "The branch '%(branch)s' is not stacked."
262
class InventoryModified(InternalBzrError):
264
_fmt = ("The current inventory for the tree %(tree)r has been modified,"
265
" so a clean inventory cannot be read without data loss.")
267
def __init__(self, tree):
233
271
class NoWorkingTree(BzrError):
235
273
_fmt = 'No WorkingTree exists for "%(base)s".'
258
class NoWhoami(BzrError):
260
_fmt = ('Unable to determine your name.\n'
261
"Please, set your name with the 'whoami' command.\n"
262
'E.g. brz whoami "Your Name <name@example.com>"')
265
class CommandError(BzrError):
296
class BzrCommandError(BzrError):
266
297
"""Error from user command"""
268
299
# Error from malformed user command; please avoid raising this as a
271
302
# I think it's a waste of effort to differentiate between errors that
272
303
# are not intended to be caught anyway. UI code need not subclass
273
# CommandError, and non-UI code should not throw a subclass of
274
# CommandError. ADHB 20051211
277
# Provide the old name as backup, for the moment.
278
BzrCommandError = CommandError
304
# BzrCommandError, and non-UI code should not throw a subclass of
305
# BzrCommandError. ADHB 20051211
281
308
class NotWriteLocked(BzrError):
377
404
_fmt = 'Permission denied: "%(path)s"%(extra)s'
407
class UnavailableRepresentation(InternalBzrError):
409
_fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
410
"is encoded as '%(native)s'.")
412
def __init__(self, key, wanted, native):
413
InternalBzrError.__init__(self)
380
419
class UnsupportedProtocol(PathError):
382
421
_fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
398
437
class UnstackableRepositoryFormat(BzrError):
400
439
_fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
401
"You will need to upgrade the repository to permit branch stacking.")
440
"You will need to upgrade the repository to permit branch stacking.")
403
442
def __init__(self, format, url):
404
443
BzrError.__init__(self)
454
493
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
456
495
def __init__(self, path, detail=None, controldir=None):
457
from . import urlutils
458
path = urlutils.unescape_for_display(path, 'ascii')
459
if detail is not None:
460
detail = ': ' + detail
462
self.controldir = controldir
463
PathError.__init__(self, path=path)
496
from . import urlutils
497
path = urlutils.unescape_for_display(path, 'ascii')
498
if detail is not None:
499
detail = ': ' + detail
501
self.controldir = controldir
502
PathError.__init__(self, path=path)
465
504
def __repr__(self):
466
505
return '<%s %r>' % (self.__class__.__name__, self.__dict__)
468
507
def _get_format_string(self):
469
508
# GZ 2017-06-08: Not the best place to lazy fill detail in.
470
509
if self.detail is None:
471
self.detail = self._get_detail()
510
self.detail = self._get_detail()
472
511
return super(NotBranchError, self)._get_format_string()
474
513
def _get_detail(self):
496
535
_fmt = 'No submit branch available for branch "%(path)s"'
498
537
def __init__(self, branch):
499
from . import urlutils
500
self.path = urlutils.unescape_for_display(branch.base, 'ascii')
538
from . import urlutils
539
self.path = urlutils.unescape_for_display(branch.base, 'ascii')
503
542
class AlreadyControlDirError(PathError):
530
569
(use brz checkout if you wish to build a working tree): "%(path)s"'
572
class AtomicFileAlreadyClosed(PathError):
574
_fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
577
def __init__(self, path, function):
578
PathError.__init__(self, path=path, extra=None)
579
self.function = function
533
582
class InaccessibleParent(PathError):
535
584
_fmt = ('Parent not accessible given base "%(base)s" and'
543
592
class NoRepositoryPresent(BzrError):
545
594
_fmt = 'No repository present: "%(path)s"'
547
595
def __init__(self, controldir):
548
596
BzrError.__init__(self)
549
597
self.path = controldir.transport.clone('..').base
596
644
_fmt = "%(target)s\n" \
597
"is not compatible with\n" \
645
"is not compatible with\n" \
601
649
def __init__(self, source, target, details=None):
602
650
if details is None:
930
978
self.revision_id = revision_id
981
class InvalidRevisionSpec(BzrError):
983
_fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
984
" %(branch_url)s%(extra)s")
986
def __init__(self, spec, branch, extra=None):
987
BzrError.__init__(self, branch=branch, spec=spec)
988
self.branch_url = getattr(branch, 'user_url', str(branch))
990
self.extra = '\n' + str(extra)
933
995
class AppendRevisionsOnlyViolation(BzrError):
935
997
_fmt = ('Operation denied because it would change the main history,'
936
' which is not permitted by the append_revisions_only setting on'
937
' branch "%(location)s".')
998
' which is not permitted by the append_revisions_only setting on'
999
' branch "%(location)s".')
939
1001
def __init__(self, location):
940
import breezy.urlutils as urlutils
941
location = urlutils.unescape_for_display(location, 'ascii')
942
BzrError.__init__(self, location=location)
1002
import breezy.urlutils as urlutils
1003
location = urlutils.unescape_for_display(location, 'ascii')
1004
BzrError.__init__(self, location=location)
945
1007
class DivergedBranches(BzrError):
985
1047
class NoCommonRoot(BzrError):
987
1049
_fmt = ("Revisions are not derived from the same root: "
988
"%(revision_a)s %(revision_b)s.")
1050
"%(revision_a)s %(revision_b)s.")
990
1052
def __init__(self, revision_a, revision_b):
991
1053
BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
998
1060
def __init__(self, rev_id, not_ancestor_id):
999
1061
BzrError.__init__(self, rev_id=rev_id,
1000
not_ancestor_id=not_ancestor_id)
1062
not_ancestor_id=not_ancestor_id)
1003
1065
class NoCommits(BranchError):
1209
1272
self.exc_type, self.exc_value, self.exc_tb = exc_info
1210
1273
self.exc_info = exc_info
1211
1274
traceback_strings = traceback.format_exception(
1212
self.exc_type, self.exc_value, self.exc_tb)
1275
self.exc_type, self.exc_value, self.exc_tb)
1213
1276
self.traceback_text = ''.join(traceback_strings)
1280
1343
TransportError.__init__(self, msg, orig_error=orig_error)
1283
class UnexpectedHttpStatus(InvalidHttpResponse):
1285
_fmt = "Unexpected HTTP status %(code)d for %(path)s"
1287
def __init__(self, path, code, msg=None):
1291
full_msg = 'status code %d unexpected' % code
1293
full_msg += ': ' + msg
1294
InvalidHttpResponse.__init__(
1295
self, path, full_msg)
1298
class BadHttpRequest(UnexpectedHttpStatus):
1300
_fmt = "Bad http request for %(path)s: %(reason)s"
1302
def __init__(self, path, reason):
1304
self.reason = reason
1305
TransportError.__init__(self, reason)
1308
1346
class InvalidHttpRange(InvalidHttpResponse):
1310
1348
_fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1378
1416
BzrError.__init__(self, basedir=tree.basedir)
1419
class CantReprocessAndShowBase(BzrError):
1421
_fmt = ("Can't reprocess and show base, because reprocessing obscures "
1422
"the relationship of conflicting lines to the base")
1381
1425
class GraphCycleError(BzrError):
1383
1427
_fmt = "Cycle in graph %(graph)r"
1460
1504
self.file_id = file_id
1507
class DuplicateFileId(BzrError):
1509
_fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
1511
def __init__(self, file_id, entry):
1512
BzrError.__init__(self)
1513
self.file_id = file_id
1463
1517
class DuplicateKey(BzrError):
1465
1519
_fmt = "Key %(key)s is already present in map"
1473
1527
self.prefix = prefix
1530
class MalformedTransform(InternalBzrError):
1532
_fmt = "Tree transform is malformed %(conflicts)r"
1535
class NoFinalPath(BzrError):
1537
_fmt = ("No final name for trans_id %(trans_id)r\n"
1538
"file-id: %(file_id)r\n"
1539
"root trans-id: %(root_trans_id)r\n")
1541
def __init__(self, trans_id, transform):
1542
self.trans_id = trans_id
1543
self.file_id = transform.final_file_id(trans_id)
1544
self.root_trans_id = transform.root
1476
1547
class BzrBadParameter(InternalBzrError):
1478
1549
_fmt = "Bad parameter: %(param)r"
1490
1561
_fmt = "Parameter %(param)s is neither unicode nor utf8."
1564
class ReusingTransform(BzrError):
1566
_fmt = "Attempt to reuse a transform that has already been applied."
1569
class CantMoveRoot(BzrError):
1571
_fmt = "Moving the root directory is not supported at this time"
1574
class TransformRenameFailed(BzrError):
1576
_fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
1578
def __init__(self, from_path, to_path, why, errno):
1579
self.from_path = from_path
1580
self.to_path = to_path
1493
1585
class BzrMoveFailedError(BzrError):
1495
1587
_fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1496
"%(_has_extra)s%(extra)s")
1588
"%(_has_extra)s%(extra)s")
1498
1590
def __init__(self, from_path='', to_path='', extra=None):
1499
1591
from breezy.osutils import splitpath
1529
1621
class BzrRenameFailedError(BzrMoveFailedError):
1531
1623
_fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1532
"%(_has_extra)s%(extra)s")
1624
"%(_has_extra)s%(extra)s")
1534
1626
def __init__(self, from_path, to_path, extra=None):
1535
1627
BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1581
1673
class BadConversionTarget(BzrError):
1583
1675
_fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1586
1678
def __init__(self, problem, format, from_format=None):
1587
1679
BzrError.__init__(self)
1619
1711
_fmt = "Diff3 is not installed on this machine."
1714
class ExistingContent(BzrError):
1715
# Added in breezy 0.92, used by VersionedFile.add_lines.
1717
_fmt = "The content being inserted is already present."
1622
1720
class ExistingLimbo(BzrError):
1624
1722
_fmt = """This tree contains left-over files from a failed operation.
1626
1724
keep, and delete it when you are done."""
1628
1726
def __init__(self, limbo_dir):
1629
BzrError.__init__(self)
1630
self.limbo_dir = limbo_dir
1727
BzrError.__init__(self)
1728
self.limbo_dir = limbo_dir
1633
1731
class ExistingPendingDeletion(BzrError):
1637
1735
wish to keep, and delete it when you are done."""
1639
1737
def __init__(self, pending_deletion):
1640
BzrError.__init__(self, pending_deletion=pending_deletion)
1738
BzrError.__init__(self, pending_deletion=pending_deletion)
1741
class ImmortalLimbo(BzrError):
1743
_fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
1744
Please examine %(limbo_dir)s to see if it contains any files you wish to
1745
keep, and delete it when you are done."""
1747
def __init__(self, limbo_dir):
1748
BzrError.__init__(self)
1749
self.limbo_dir = limbo_dir
1643
1752
class ImmortalPendingDeletion(BzrError):
1645
1754
_fmt = ("Unable to delete transform temporary directory "
1646
"%(pending_deletion)s. Please examine %(pending_deletion)s to see if it "
1647
"contains any files you wish to keep, and delete it when you are done.")
1755
"%(pending_deletion)s. Please examine %(pending_deletion)s to see if it "
1756
"contains any files you wish to keep, and delete it when you are done.")
1649
1758
def __init__(self, pending_deletion):
1650
BzrError.__init__(self, pending_deletion=pending_deletion)
1759
BzrError.__init__(self, pending_deletion=pending_deletion)
1653
1762
class OutOfDateTree(BzrError):
1739
1848
class RichRootUpgradeRequired(UpgradeRequired):
1741
1850
_fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1742
" a format which supports rich roots.")
1851
" a format which supports rich roots.")
1745
1854
class LocalRequiresBoundBranch(BzrError):
1758
1867
self.tname = type(method_self).__name__
1761
class FetchLimitUnsupported(UnsupportedOperation):
1763
fmt = ("InterBranch %(interbranch)r does not support fetching limits.")
1765
def __init__(self, interbranch):
1766
BzrError.__init__(self, interbranch=interbranch)
1769
1870
class NonAsciiRevisionId(UnsupportedOperation):
1770
1871
"""Raised when a commit is attempting to set a non-ascii revision id
1775
class SharedRepositoriesUnsupported(UnsupportedOperation):
1776
_fmt = "Shared repositories are not supported by %(format)r."
1778
def __init__(self, format):
1779
BzrError.__init__(self, format=format)
1782
1876
class GhostTagsNotSupported(BzrError):
1784
1878
_fmt = "Ghost tags not supported by format %(format)r."
1866
1960
self.other = other
1963
class BadInventoryFormat(BzrError):
1965
_fmt = "Root class for inventory serialization errors"
1968
class UnexpectedInventoryFormat(BadInventoryFormat):
1970
_fmt = "The inventory was not in the expected format:\n %(msg)s"
1972
def __init__(self, msg):
1973
BadInventoryFormat.__init__(self, msg=msg)
1869
1976
class RootNotRich(BzrError):
1871
1978
_fmt = """This operation requires rich root data storage"""
1914
2021
self.revision_id = revision_id
2024
class IllegalUseOfScopeReplacer(InternalBzrError):
2026
_fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2027
" %(msg)s%(extra)s")
2029
def __init__(self, name, msg, extra=None):
2030
BzrError.__init__(self)
2034
self.extra = ': ' + str(extra)
2039
class InvalidImportLine(InternalBzrError):
2041
_fmt = "Not a valid import statement: %(msg)\n%(text)s"
2043
def __init__(self, text, msg):
2044
BzrError.__init__(self)
2049
class ImportNameCollision(InternalBzrError):
2051
_fmt = ("Tried to import an object to the same name as"
2052
" an existing object. %(name)s")
2054
def __init__(self, name):
2055
BzrError.__init__(self)
1917
2059
class NotAMergeDirective(BzrError):
1918
2060
"""File starting with %(firstline)r is not a merge directive"""
1920
2061
def __init__(self, firstline):
1921
2062
BzrError.__init__(self, firstline=firstline)
1928
2069
" branch location."
2072
class IllegalMergeDirectivePayload(BzrError):
2073
"""A merge directive contained something other than a patch or bundle"""
2075
_fmt = "Bad merge directive payload %(start)r"
2077
def __init__(self, start):
1931
2082
class PatchVerificationFailed(BzrError):
1932
2083
"""A patch from a merge directive could not be verified"""
1957
2108
self.location = location
2111
class UnsupportedInventoryKind(BzrError):
2113
_fmt = """Unsupported entry kind %(kind)s"""
2115
def __init__(self, kind):
1960
2119
class BadSubsumeSource(BzrError):
1962
2121
_fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
1986
2145
class TagsNotSupported(BzrError):
1988
2147
_fmt = ("Tags not supported by %(branch)s;"
1989
" you may be able to use 'brz upgrade %(branch_url)s'.")
2148
" you may be able to use brz upgrade.")
1991
2150
def __init__(self, branch):
1992
2151
self.branch = branch
1993
self.branch_url = branch.user_url
1996
2154
class TagAlreadyExists(BzrError):
2152
2310
' (See brz shelve --list).%(more)s')
2313
class UnableCreateSymlink(BzrError):
2315
_fmt = 'Unable to create symlink %(path_str)son this platform'
2317
def __init__(self, path=None):
2321
path_str = repr(str(path))
2322
except UnicodeEncodeError:
2323
path_str = repr(path)
2325
self.path_str = path_str
2155
2328
class UnableEncodePath(BzrError):
2157
2330
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2179
2352
def __init__(self, host, port, orig_error):
2180
2353
# nb: in python2.4 socket.error doesn't have a useful repr
2181
2354
BzrError.__init__(self, host=host, port=port,
2182
orig_error=repr(orig_error.args))
2355
orig_error=repr(orig_error.args))
2185
2358
class TipChangeRejected(BzrError):
2264
2437
class RecursiveBind(BzrError):
2266
2439
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2267
'Please use `brz unbind` to fix.')
2440
'Please use `brz unbind` to fix.')
2269
2442
def __init__(self, branch_url):
2270
2443
self.branch_url = branch_url
2282
2455
self.format = format
2285
class ChangesAlreadyStored(CommandError):
2458
class ChangesAlreadyStored(BzrCommandError):
2287
2460
_fmt = ('Cannot store uncommitted changes because this branch already'
2288
2461
' stores uncommitted changes.')
2291
class RevnoOutOfBounds(InternalBzrError):
2293
_fmt = ("The requested revision number %(revno)d is outside of the "
2294
"expected boundaries (%(minimum)d <= %(maximum)d).")
2296
def __init__(self, revno, bounds):
2297
InternalBzrError.__init__(
2298
self, revno=revno, minimum=bounds[0], maximum=bounds[1])