17
17
"""Exceptions for bzr, and reporting of them.
20
from __future__ import absolute_import
26
21
# TODO: is there any value in providing the .args field used by standard
27
22
# python exceptions? A list of values with no names seems less useful
108
103
getattr(self, '_fmt', None),
115
return self._format().encode('utf-8')
117
__unicode__ = _format
119
108
def __repr__(self):
120
109
return '%s(%s)' % (self.__class__.__name__, str(self))
124
113
fmt = getattr(self, '_fmt', None)
125
114
if fmt is not None:
126
115
from breezy.i18n import gettext
127
return gettext(fmt) # _fmt strings should be ascii
116
return gettext(fmt) # _fmt strings should be ascii
129
118
def __eq__(self, other):
130
119
if self.__class__ is not other.__class__:
182
171
self.transport = transport
185
class InvalidEntryName(InternalBzrError):
187
_fmt = "Invalid entry name: %(name)s"
189
def __init__(self, name):
190
BzrError.__init__(self)
194
174
class InvalidRevisionNumber(BzrError):
196
176
_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)
257
228
class NotStacked(BranchError):
259
230
_fmt = "The branch '%(branch)s' is not stacked."
267
class NoWhoami(BzrError):
269
_fmt = ('Unable to determine your name.\n'
270
"Please, set your name with the 'whoami' command.\n"
271
'E.g. brz whoami "Your Name <name@example.com>"')
296
274
class BzrCommandError(BzrError):
297
275
"""Error from user command"""
407
385
class UnavailableRepresentation(InternalBzrError):
409
387
_fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
410
"is encoded as '%(native)s'.")
388
"is encoded as '%(native)s'.")
412
390
def __init__(self, key, wanted, native):
413
391
InternalBzrError.__init__(self)
437
415
class UnstackableRepositoryFormat(BzrError):
439
417
_fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
440
"You will need to upgrade the repository to permit branch stacking.")
418
"You will need to upgrade the repository to permit branch stacking.")
442
420
def __init__(self, format, url):
443
421
BzrError.__init__(self)
493
471
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
495
473
def __init__(self, path, detail=None, controldir=None):
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)
474
from . import urlutils
475
path = urlutils.unescape_for_display(path, 'ascii')
476
if detail is not None:
477
detail = ': ' + detail
479
self.controldir = controldir
480
PathError.__init__(self, path=path)
504
482
def __repr__(self):
505
483
return '<%s %r>' % (self.__class__.__name__, self.__dict__)
507
485
def _get_format_string(self):
508
486
# GZ 2017-06-08: Not the best place to lazy fill detail in.
509
487
if self.detail is None:
510
self.detail = self._get_detail()
488
self.detail = self._get_detail()
511
489
return super(NotBranchError, self)._get_format_string()
513
491
def _get_detail(self):
535
513
_fmt = 'No submit branch available for branch "%(path)s"'
537
515
def __init__(self, branch):
538
from . import urlutils
539
self.path = urlutils.unescape_for_display(branch.base, 'ascii')
516
from . import urlutils
517
self.path = urlutils.unescape_for_display(branch.base, 'ascii')
542
520
class AlreadyControlDirError(PathError):
569
547
(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
582
550
class InaccessibleParent(PathError):
584
552
_fmt = ('Parent not accessible given base "%(base)s" and'
592
560
class NoRepositoryPresent(BzrError):
594
562
_fmt = 'No repository present: "%(path)s"'
595
564
def __init__(self, controldir):
596
565
BzrError.__init__(self)
597
566
self.path = controldir.transport.clone('..').base
611
580
self.format = format
583
class LineEndingError(BzrError):
585
_fmt = ("Line ending corrupted for file: %(file)s; "
586
"Maybe your files got corrupted in transport?")
588
def __init__(self, file):
614
592
class IncompatibleFormat(BzrError):
616
594
_fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
644
622
_fmt = "%(target)s\n" \
645
"is not compatible with\n" \
623
"is not compatible with\n" \
649
627
def __init__(self, source, target, details=None):
650
628
if details is None:
978
956
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)
995
959
class AppendRevisionsOnlyViolation(BzrError):
997
961
_fmt = ('Operation denied because it would change the main history,'
998
' which is not permitted by the append_revisions_only setting on'
999
' branch "%(location)s".')
962
' which is not permitted by the append_revisions_only setting on'
963
' branch "%(location)s".')
1001
965
def __init__(self, location):
1002
import breezy.urlutils as urlutils
1003
location = urlutils.unescape_for_display(location, 'ascii')
1004
BzrError.__init__(self, location=location)
966
import breezy.urlutils as urlutils
967
location = urlutils.unescape_for_display(location, 'ascii')
968
BzrError.__init__(self, location=location)
1007
971
class DivergedBranches(BzrError):
1047
1011
class NoCommonRoot(BzrError):
1049
1013
_fmt = ("Revisions are not derived from the same root: "
1050
"%(revision_a)s %(revision_b)s.")
1014
"%(revision_a)s %(revision_b)s.")
1052
1016
def __init__(self, revision_a, revision_b):
1053
1017
BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
1060
1024
def __init__(self, rev_id, not_ancestor_id):
1061
1025
BzrError.__init__(self, rev_id=rev_id,
1062
not_ancestor_id=not_ancestor_id)
1026
not_ancestor_id=not_ancestor_id)
1065
1029
class NoCommits(BranchError):
1272
1235
self.exc_type, self.exc_value, self.exc_tb = exc_info
1273
1236
self.exc_info = exc_info
1274
1237
traceback_strings = traceback.format_exception(
1275
self.exc_type, self.exc_value, self.exc_tb)
1238
self.exc_type, self.exc_value, self.exc_tb)
1276
1239
self.traceback_text = ''.join(traceback_strings)
1416
1379
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")
1425
1382
class GraphCycleError(BzrError):
1427
1384
_fmt = "Cycle in graph %(graph)r"
1585
1542
class BzrMoveFailedError(BzrError):
1587
1544
_fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1588
"%(_has_extra)s%(extra)s")
1545
"%(_has_extra)s%(extra)s")
1590
1547
def __init__(self, from_path='', to_path='', extra=None):
1591
1548
from breezy.osutils import splitpath
1621
1578
class BzrRenameFailedError(BzrMoveFailedError):
1623
1580
_fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1624
"%(_has_extra)s%(extra)s")
1581
"%(_has_extra)s%(extra)s")
1626
1583
def __init__(self, from_path, to_path, extra=None):
1627
1584
BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1673
1630
class BadConversionTarget(BzrError):
1675
1632
_fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1678
1635
def __init__(self, problem, format, from_format=None):
1679
1636
BzrError.__init__(self)
1724
1681
keep, and delete it when you are done."""
1726
1683
def __init__(self, limbo_dir):
1727
BzrError.__init__(self)
1728
self.limbo_dir = limbo_dir
1684
BzrError.__init__(self)
1685
self.limbo_dir = limbo_dir
1731
1688
class ExistingPendingDeletion(BzrError):
1735
1692
wish to keep, and delete it when you are done."""
1737
1694
def __init__(self, pending_deletion):
1738
BzrError.__init__(self, pending_deletion=pending_deletion)
1695
BzrError.__init__(self, pending_deletion=pending_deletion)
1741
1698
class ImmortalLimbo(BzrError):
1745
1702
keep, and delete it when you are done."""
1747
1704
def __init__(self, limbo_dir):
1748
BzrError.__init__(self)
1749
self.limbo_dir = limbo_dir
1705
BzrError.__init__(self)
1706
self.limbo_dir = limbo_dir
1752
1709
class ImmortalPendingDeletion(BzrError):
1754
1711
_fmt = ("Unable to delete transform temporary directory "
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.")
1712
"%(pending_deletion)s. Please examine %(pending_deletion)s to see if it "
1713
"contains any files you wish to keep, and delete it when you are done.")
1758
1715
def __init__(self, pending_deletion):
1759
BzrError.__init__(self, pending_deletion=pending_deletion)
1716
BzrError.__init__(self, pending_deletion=pending_deletion)
1762
1719
class OutOfDateTree(BzrError):
1848
1805
class RichRootUpgradeRequired(UpgradeRequired):
1850
1807
_fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1851
" a format which supports rich roots.")
1808
" a format which supports rich roots.")
1854
1811
class LocalRequiresBoundBranch(BzrError):
1867
1824
self.tname = type(method_self).__name__
1827
class FetchLimitUnsupported(UnsupportedOperation):
1829
fmt = ("InterBranch %(interbranch)r does not support fetching limits.")
1831
def __init__(self, interbranch):
1832
BzrError.__init__(self, interbranch=interbranch)
1870
1835
class NonAsciiRevisionId(UnsupportedOperation):
1871
1836
"""Raised when a commit is attempting to set a non-ascii revision id
1841
class SharedRepositoriesUnsupported(UnsupportedOperation):
1842
_fmt = "Shared repositories are not supported by %(format)r."
1844
def __init__(self, format):
1845
BzrError.__init__(self, format=format)
1876
1848
class GhostTagsNotSupported(BzrError):
1878
1850
_fmt = "Ghost tags not supported by format %(format)r."
2021
1993
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)
2059
1996
class NotAMergeDirective(BzrError):
2060
1997
"""File starting with %(firstline)r is not a merge directive"""
2061
1999
def __init__(self, firstline):
2062
2000
BzrError.__init__(self, firstline=firstline)
2145
2083
class TagsNotSupported(BzrError):
2147
2085
_fmt = ("Tags not supported by %(branch)s;"
2148
" you may be able to use brz upgrade.")
2086
" you may be able to use 'brz upgrade %(branch_url)s'.")
2150
2088
def __init__(self, branch):
2151
2089
self.branch = branch
2090
self.branch_url = branch.user_url
2154
2093
class TagAlreadyExists(BzrError):
2310
2249
' (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
2328
2252
class UnableEncodePath(BzrError):
2330
2254
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2352
2276
def __init__(self, host, port, orig_error):
2353
2277
# nb: in python2.4 socket.error doesn't have a useful repr
2354
2278
BzrError.__init__(self, host=host, port=port,
2355
orig_error=repr(orig_error.args))
2279
orig_error=repr(orig_error.args))
2358
2282
class TipChangeRejected(BzrError):
2437
2361
class RecursiveBind(BzrError):
2439
2363
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2440
'Please use `brz unbind` to fix.')
2364
'Please use `brz unbind` to fix.')
2442
2366
def __init__(self, branch_url):
2443
2367
self.branch_url = branch_url
2460
2384
_fmt = ('Cannot store uncommitted changes because this branch already'
2461
2385
' stores uncommitted changes.')
2388
class RevnoOutOfBounds(InternalBzrError):
2390
_fmt = ("The requested revision number %(revno)d is outside of the "
2391
"expected boundaries (%(minimum)d <= %(maximum)d).")
2393
def __init__(self, revno, bounds):
2394
InternalBzrError.__init__(
2395
self, revno=revno, minimum=bounds[0], maximum=bounds[1])