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"
230
250
_fmt = "The branch '%(branch)s' is not stacked."
253
class InventoryModified(InternalBzrError):
255
_fmt = ("The current inventory for the tree %(tree)r has been modified,"
256
" so a clean inventory cannot be read without data loss.")
258
def __init__(self, tree):
233
262
class NoWorkingTree(BzrError):
235
264
_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):
287
class BzrCommandError(BzrError):
266
288
"""Error from user command"""
268
290
# Error from malformed user command; please avoid raising this as a
271
293
# I think it's a waste of effort to differentiate between errors that
272
294
# 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
295
# BzrCommandError, and non-UI code should not throw a subclass of
296
# BzrCommandError. ADHB 20051211
281
299
class NotWriteLocked(BzrError):
377
395
_fmt = 'Permission denied: "%(path)s"%(extra)s'
398
class UnavailableRepresentation(InternalBzrError):
400
_fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
401
"is encoded as '%(native)s'.")
403
def __init__(self, key, wanted, native):
404
InternalBzrError.__init__(self)
380
410
class UnsupportedProtocol(PathError):
382
412
_fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
398
428
class UnstackableRepositoryFormat(BzrError):
400
430
_fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
401
"You will need to upgrade the repository to permit branch stacking.")
431
"You will need to upgrade the repository to permit branch stacking.")
403
433
def __init__(self, format, url):
404
434
BzrError.__init__(self)
454
484
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
456
486
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)
487
from . import urlutils
488
path = urlutils.unescape_for_display(path, 'ascii')
489
if detail is not None:
490
detail = ': ' + detail
492
self.controldir = controldir
493
PathError.__init__(self, path=path)
465
495
def __repr__(self):
466
496
return '<%s %r>' % (self.__class__.__name__, self.__dict__)
468
498
def _get_format_string(self):
469
499
# GZ 2017-06-08: Not the best place to lazy fill detail in.
470
500
if self.detail is None:
471
self.detail = self._get_detail()
501
self.detail = self._get_detail()
472
502
return super(NotBranchError, self)._get_format_string()
474
504
def _get_detail(self):
496
526
_fmt = 'No submit branch available for branch "%(path)s"'
498
528
def __init__(self, branch):
499
from . import urlutils
500
self.path = urlutils.unescape_for_display(branch.base, 'ascii')
529
from . import urlutils
530
self.path = urlutils.unescape_for_display(branch.base, 'ascii')
503
533
class AlreadyControlDirError(PathError):
530
560
(use brz checkout if you wish to build a working tree): "%(path)s"'
563
class AtomicFileAlreadyClosed(PathError):
565
_fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
568
def __init__(self, path, function):
569
PathError.__init__(self, path=path, extra=None)
570
self.function = function
533
573
class InaccessibleParent(PathError):
535
575
_fmt = ('Parent not accessible given base "%(base)s" and'
543
583
class NoRepositoryPresent(BzrError):
545
585
_fmt = 'No repository present: "%(path)s"'
547
586
def __init__(self, controldir):
548
587
BzrError.__init__(self)
549
588
self.path = controldir.transport.clone('..').base
596
635
_fmt = "%(target)s\n" \
597
"is not compatible with\n" \
636
"is not compatible with\n" \
601
640
def __init__(self, source, target, details=None):
602
641
if details is None:
930
969
self.revision_id = revision_id
972
class InvalidRevisionSpec(BzrError):
974
_fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
975
" %(branch_url)s%(extra)s")
977
def __init__(self, spec, branch, extra=None):
978
BzrError.__init__(self, branch=branch, spec=spec)
979
self.branch_url = getattr(branch, 'user_url', str(branch))
981
self.extra = '\n' + str(extra)
933
986
class AppendRevisionsOnlyViolation(BzrError):
935
988
_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".')
989
' which is not permitted by the append_revisions_only setting on'
990
' branch "%(location)s".')
939
992
def __init__(self, location):
940
import breezy.urlutils as urlutils
941
location = urlutils.unescape_for_display(location, 'ascii')
942
BzrError.__init__(self, location=location)
993
import breezy.urlutils as urlutils
994
location = urlutils.unescape_for_display(location, 'ascii')
995
BzrError.__init__(self, location=location)
945
998
class DivergedBranches(BzrError):
985
1038
class NoCommonRoot(BzrError):
987
1040
_fmt = ("Revisions are not derived from the same root: "
988
"%(revision_a)s %(revision_b)s.")
1041
"%(revision_a)s %(revision_b)s.")
990
1043
def __init__(self, revision_a, revision_b):
991
1044
BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
998
1051
def __init__(self, rev_id, not_ancestor_id):
999
1052
BzrError.__init__(self, rev_id=rev_id,
1000
not_ancestor_id=not_ancestor_id)
1053
not_ancestor_id=not_ancestor_id)
1003
1056
class NoCommits(BranchError):
1209
1263
self.exc_type, self.exc_value, self.exc_tb = exc_info
1210
1264
self.exc_info = exc_info
1211
1265
traceback_strings = traceback.format_exception(
1212
self.exc_type, self.exc_value, self.exc_tb)
1266
self.exc_type, self.exc_value, self.exc_tb)
1213
1267
self.traceback_text = ''.join(traceback_strings)
1280
1334
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
1337
class InvalidHttpRange(InvalidHttpResponse):
1310
1339
_fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1378
1407
BzrError.__init__(self, basedir=tree.basedir)
1410
class CantReprocessAndShowBase(BzrError):
1412
_fmt = ("Can't reprocess and show base, because reprocessing obscures "
1413
"the relationship of conflicting lines to the base")
1381
1416
class GraphCycleError(BzrError):
1383
1418
_fmt = "Cycle in graph %(graph)r"
1460
1495
self.file_id = file_id
1498
class DuplicateFileId(BzrError):
1500
_fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
1502
def __init__(self, file_id, entry):
1503
BzrError.__init__(self)
1504
self.file_id = file_id
1463
1508
class DuplicateKey(BzrError):
1465
1510
_fmt = "Key %(key)s is already present in map"
1473
1518
self.prefix = prefix
1521
class MalformedTransform(InternalBzrError):
1523
_fmt = "Tree transform is malformed %(conflicts)r"
1526
class NoFinalPath(BzrError):
1528
_fmt = ("No final name for trans_id %(trans_id)r\n"
1529
"file-id: %(file_id)r\n"
1530
"root trans-id: %(root_trans_id)r\n")
1532
def __init__(self, trans_id, transform):
1533
self.trans_id = trans_id
1534
self.file_id = transform.final_file_id(trans_id)
1535
self.root_trans_id = transform.root
1476
1538
class BzrBadParameter(InternalBzrError):
1478
1540
_fmt = "Bad parameter: %(param)r"
1490
1552
_fmt = "Parameter %(param)s is neither unicode nor utf8."
1555
class ReusingTransform(BzrError):
1557
_fmt = "Attempt to reuse a transform that has already been applied."
1560
class CantMoveRoot(BzrError):
1562
_fmt = "Moving the root directory is not supported at this time"
1565
class TransformRenameFailed(BzrError):
1567
_fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
1569
def __init__(self, from_path, to_path, why, errno):
1570
self.from_path = from_path
1571
self.to_path = to_path
1493
1576
class BzrMoveFailedError(BzrError):
1495
1578
_fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1496
"%(_has_extra)s%(extra)s")
1579
"%(_has_extra)s%(extra)s")
1498
1581
def __init__(self, from_path='', to_path='', extra=None):
1499
1582
from breezy.osutils import splitpath
1529
1612
class BzrRenameFailedError(BzrMoveFailedError):
1531
1614
_fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1532
"%(_has_extra)s%(extra)s")
1615
"%(_has_extra)s%(extra)s")
1534
1617
def __init__(self, from_path, to_path, extra=None):
1535
1618
BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1581
1664
class BadConversionTarget(BzrError):
1583
1666
_fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1586
1669
def __init__(self, problem, format, from_format=None):
1587
1670
BzrError.__init__(self)
1619
1702
_fmt = "Diff3 is not installed on this machine."
1705
class ExistingContent(BzrError):
1706
# Added in breezy 0.92, used by VersionedFile.add_lines.
1708
_fmt = "The content being inserted is already present."
1622
1711
class ExistingLimbo(BzrError):
1624
1713
_fmt = """This tree contains left-over files from a failed operation.
1626
1715
keep, and delete it when you are done."""
1628
1717
def __init__(self, limbo_dir):
1629
BzrError.__init__(self)
1630
self.limbo_dir = limbo_dir
1718
BzrError.__init__(self)
1719
self.limbo_dir = limbo_dir
1633
1722
class ExistingPendingDeletion(BzrError):
1637
1726
wish to keep, and delete it when you are done."""
1639
1728
def __init__(self, pending_deletion):
1640
BzrError.__init__(self, pending_deletion=pending_deletion)
1729
BzrError.__init__(self, pending_deletion=pending_deletion)
1732
class ImmortalLimbo(BzrError):
1734
_fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
1735
Please examine %(limbo_dir)s to see if it contains any files you wish to
1736
keep, and delete it when you are done."""
1738
def __init__(self, limbo_dir):
1739
BzrError.__init__(self)
1740
self.limbo_dir = limbo_dir
1643
1743
class ImmortalPendingDeletion(BzrError):
1645
1745
_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.")
1746
"%(pending_deletion)s. Please examine %(pending_deletion)s to see if it "
1747
"contains any files you wish to keep, and delete it when you are done.")
1649
1749
def __init__(self, pending_deletion):
1650
BzrError.__init__(self, pending_deletion=pending_deletion)
1750
BzrError.__init__(self, pending_deletion=pending_deletion)
1653
1753
class OutOfDateTree(BzrError):
1739
1839
class RichRootUpgradeRequired(UpgradeRequired):
1741
1841
_fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1742
" a format which supports rich roots.")
1842
" a format which supports rich roots.")
1745
1845
class LocalRequiresBoundBranch(BzrError):
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
1875
class GhostTagsNotSupported(BzrError):
1784
1877
_fmt = "Ghost tags not supported by format %(format)r."
1866
1959
self.other = other
1962
class BadInventoryFormat(BzrError):
1964
_fmt = "Root class for inventory serialization errors"
1967
class UnexpectedInventoryFormat(BadInventoryFormat):
1969
_fmt = "The inventory was not in the expected format:\n %(msg)s"
1971
def __init__(self, msg):
1972
BadInventoryFormat.__init__(self, msg=msg)
1869
1975
class RootNotRich(BzrError):
1871
1977
_fmt = """This operation requires rich root data storage"""
1914
2020
self.revision_id = revision_id
2023
class IllegalUseOfScopeReplacer(InternalBzrError):
2025
_fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2026
" %(msg)s%(extra)s")
2028
def __init__(self, name, msg, extra=None):
2029
BzrError.__init__(self)
2033
self.extra = ': ' + str(extra)
2038
class InvalidImportLine(InternalBzrError):
2040
_fmt = "Not a valid import statement: %(msg)\n%(text)s"
2042
def __init__(self, text, msg):
2043
BzrError.__init__(self)
2048
class ImportNameCollision(InternalBzrError):
2050
_fmt = ("Tried to import an object to the same name as"
2051
" an existing object. %(name)s")
2053
def __init__(self, name):
2054
BzrError.__init__(self)
1917
2058
class NotAMergeDirective(BzrError):
1918
2059
"""File starting with %(firstline)r is not a merge directive"""
1920
2060
def __init__(self, firstline):
1921
2061
BzrError.__init__(self, firstline=firstline)
1928
2068
" branch location."
2071
class IllegalMergeDirectivePayload(BzrError):
2072
"""A merge directive contained something other than a patch or bundle"""
2074
_fmt = "Bad merge directive payload %(start)r"
2076
def __init__(self, start):
1931
2081
class PatchVerificationFailed(BzrError):
1932
2082
"""A patch from a merge directive could not be verified"""
1957
2107
self.location = location
2110
class UnsupportedInventoryKind(BzrError):
2112
_fmt = """Unsupported entry kind %(kind)s"""
2114
def __init__(self, kind):
1960
2118
class BadSubsumeSource(BzrError):
1962
2120
_fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
1986
2144
class TagsNotSupported(BzrError):
1988
2146
_fmt = ("Tags not supported by %(branch)s;"
1989
" you may be able to use 'brz upgrade %(branch_url)s'.")
2147
" you may be able to use brz upgrade.")
1991
2149
def __init__(self, branch):
1992
2150
self.branch = branch
1993
self.branch_url = branch.user_url
1996
2153
class TagAlreadyExists(BzrError):
2152
2309
' (See brz shelve --list).%(more)s')
2312
class UnableCreateSymlink(BzrError):
2314
_fmt = 'Unable to create symlink %(path_str)son this platform'
2316
def __init__(self, path=None):
2320
path_str = repr(str(path))
2321
except UnicodeEncodeError:
2322
path_str = repr(path)
2324
self.path_str = path_str
2155
2327
class UnableEncodePath(BzrError):
2157
2329
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2179
2351
def __init__(self, host, port, orig_error):
2180
2352
# nb: in python2.4 socket.error doesn't have a useful repr
2181
2353
BzrError.__init__(self, host=host, port=port,
2182
orig_error=repr(orig_error.args))
2354
orig_error=repr(orig_error.args))
2185
2357
class TipChangeRejected(BzrError):
2264
2436
class RecursiveBind(BzrError):
2266
2438
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2267
'Please use `brz unbind` to fix.')
2439
'Please use `brz unbind` to fix.')
2269
2441
def __init__(self, branch_url):
2270
2442
self.branch_url = branch_url
2282
2454
self.format = format
2285
class ChangesAlreadyStored(CommandError):
2457
class ChangesAlreadyStored(BzrCommandError):
2287
2459
_fmt = ('Cannot store uncommitted changes because this branch already'
2288
2460
' 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])