83
83
:param msg: If given, this is the literal complete text for the error,
84
not subject to expansion.
84
not subject to expansion. 'msg' is used instead of 'message' because
85
python evolved and, in 2.6, forbids the use of 'message'.
86
87
StandardError.__init__(self)
87
88
if msg is not None:
102
103
fmt = self._get_format_string()
104
105
d = dict(self.__dict__)
105
# special case: python2.5 puts the 'message' attribute in a
106
# slot, so it isn't seen in __dict__
107
d['message'] = getattr(self, 'message', 'no message')
109
107
# __str__() should always return a 'str' object
110
108
# never a 'unicode' object.
138
return '%s(%s)' % (self.__class__.__name__, str(self))
139
140
def _get_format_string(self):
140
141
"""Return format string for this exception or None"""
141
142
fmt = getattr(self, '_fmt', None)
218
219
class BzrCheckError(InternalBzrError):
220
_fmt = "Internal check failed: %(message)s"
222
def __init__(self, message):
223
BzrError.__init__(self)
224
self.message = message
221
_fmt = "Internal check failed: %(msg)s"
223
def __init__(self, msg):
224
BzrError.__init__(self)
228
class DirstateCorrupt(BzrError):
230
_fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
232
def __init__(self, state, msg):
233
BzrError.__init__(self)
227
238
class DisabledMethod(InternalBzrError):
1301
1312
class WeaveError(BzrError):
1303
_fmt = "Error in processing weave: %(message)s"
1314
_fmt = "Error in processing weave: %(msg)s"
1305
def __init__(self, message=None):
1316
def __init__(self, msg=None):
1306
1317
BzrError.__init__(self)
1307
self.message = message
1310
1321
class WeaveRevisionAlreadyPresent(WeaveError):
1430
class SHA1KnitCorrupt(KnitCorrupt):
1432
_fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
1433
"match expected sha-1. key %(key)s expected sha %(expected)s actual "
1436
def __init__(self, filename, actual, expected, key, content):
1437
KnitError.__init__(self)
1438
self.filename = filename
1439
self.actual = actual
1440
self.expected = expected
1442
self.content = content
1419
1445
class KnitDataStreamIncompatible(KnitError):
1420
1446
# Not raised anymore, as we can convert data streams. In future we may
1421
1447
# need it again for more exotic cases, so we're keeping it around for now.
1460
1486
self.options = options
1489
class RetryWithNewPacks(BzrError):
1490
"""Raised when we realize that the packs on disk have changed.
1492
This is meant as more of a signaling exception, to trap between where a
1493
local error occurred and the code that can actually handle the error and
1494
code that can retry appropriately.
1497
internal_error = True
1499
_fmt = ("Pack files have changed, reload and retry. %(orig_error)s")
1501
def __init__(self, reload_occurred, exc_info):
1502
"""create a new RestartWithNewPacks error.
1504
:param reload_occurred: Set to True if we know that the packs have
1505
already been reloaded, and we are failing because of an in-memory
1506
cache miss. If set to True then we will ignore if a reload says
1507
nothing has changed, because we assume it has already reloaded. If
1508
False, then a reload with nothing changed will force an error.
1509
:param exc_info: The original exception traceback, so if there is a
1510
problem we can raise the original error (value from sys.exc_info())
1512
BzrError.__init__(self)
1513
self.reload_occurred = reload_occurred
1514
self.exc_info = exc_info
1515
self.orig_error = exc_info[1]
1516
# TODO: The global error handler should probably treat this by
1517
# raising/printing the original exception with a bit about
1518
# RetryWithNewPacks also not being caught
1463
1521
class NoSuchExportFormat(BzrError):
1465
1523
_fmt = "Export format %(format)r not supported"
1604
1662
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1606
def __init__(self, source, target, is_permanent=False, qual_proto=None):
1664
def __init__(self, source, target, is_permanent=False):
1607
1665
self.source = source
1608
1666
self.target = target
1609
1667
if is_permanent:
1610
1668
self.permanently = ' permanently'
1612
1670
self.permanently = ''
1613
self._qualified_proto = qual_proto
1614
1671
TransportError.__init__(self)
1616
def _requalify_url(self, url):
1617
"""Restore the qualified proto in front of the url"""
1618
# When this exception is raised, source and target are in
1619
# user readable format. But some transports may use a
1620
# different proto (http+urllib:// will present http:// to
1621
# the user. If a qualified proto is specified, the code
1622
# trapping the exception can get the qualified urls to
1623
# properly handle the redirection themself (creating a
1624
# new transport object from the target url for example).
1625
# But checking that the scheme of the original and
1626
# redirected urls are the same can be tricky. (see the
1627
# FIXME in BzrDir.open_from_transport for the unique use
1629
if self._qualified_proto is None:
1632
# The TODO related to NotBranchError mention that doing
1633
# that kind of manipulation on the urls may not be the
1634
# exception object job. On the other hand, this object is
1635
# the interface between the code and the user so
1636
# presenting the urls in different ways is indeed its
1639
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1640
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1643
def get_source_url(self):
1644
return self._requalify_url(self.source)
1646
def get_target_url(self):
1647
return self._requalify_url(self.target)
1650
1674
class TooManyRedirections(TransportError):
1663
1687
if filename is None:
1665
1689
message = "Error(s) parsing config file %s:\n%s" % \
1666
(filename, ('\n'.join(e.message for e in errors)))
1690
(filename, ('\n'.join(e.msg for e in errors)))
1667
1691
BzrError.__init__(self, message)
1854
1878
_fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1856
1880
def __init__(self, from_path='', to_path='', extra=None):
1881
from bzrlib.osutils import splitpath
1857
1882
BzrError.__init__(self)
1859
1884
self.extra = ': ' + str(extra)
1863
1888
has_from = len(from_path) > 0
1864
1889
has_to = len(to_path) > 0
1866
self.from_path = osutils.splitpath(from_path)[-1]
1891
self.from_path = splitpath(from_path)[-1]
1868
1893
self.from_path = ''
1871
self.to_path = osutils.splitpath(to_path)[-1]
1896
self.to_path = splitpath(to_path)[-1]
1873
1898
self.to_path = ''
2512
2541
self.error_args = error_tuple[1:]
2544
class UnknownErrorFromSmartServer(BzrError):
2545
"""An ErrorFromSmartServer could not be translated into a typical bzrlib
2548
This is distinct from ErrorFromSmartServer so that it is possible to
2549
distinguish between the following two cases:
2550
- ErrorFromSmartServer was uncaught. This is logic error in the client
2551
and so should provoke a traceback to the user.
2552
- ErrorFromSmartServer was caught but its error_tuple could not be
2553
translated. This is probably because the server sent us garbage, and
2554
should not provoke a traceback.
2557
_fmt = "Server sent an unexpected error: %(error_tuple)r"
2559
internal_error = False
2561
def __init__(self, error_from_smart_server):
2564
:param error_from_smart_server: An ErrorFromSmartServer instance.
2566
self.error_from_smart_server = error_from_smart_server
2567
self.error_tuple = error_from_smart_server.error_tuple
2515
2570
class ContainerError(BzrError):
2516
2571
"""Base class of container errors."""
2769
2824
'user encoding %(user_encoding)s')
2771
2826
def __init__(self, path, kind):
2827
from bzrlib.osutils import get_user_encoding
2772
2828
self.path = path
2773
2829
self.kind = kind
2774
2830
self.user_encoding = osutils.get_user_encoding()
2850
2906
def __init__(self, msg):
2909
class ShelfCorrupt(BzrError):
2911
_fmt = "Shelf corrupt."
2914
class NoSuchShelfId(BzrError):
2916
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
2918
def __init__(self, shelf_id):
2919
BzrError.__init__(self, shelf_id=shelf_id)
2922
class UserAbort(BzrError):
2924
_fmt = 'The user aborted the operation.'
2854
2927
class NoSuchView(BzrError):
2855
2928
"""A view does not exist.