93
93
for key, value in kwds.items():
94
94
setattr(self, key, value)
97
97
s = getattr(self, '_preformatted_string', None)
99
# contains a preformatted message
99
# contains a preformatted message; must be cast to plain str
102
102
fmt = self._get_format_string()
104
104
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')
106
109
# __str__() should always return a 'str' object
107
110
# never a 'unicode' object.
111
if isinstance(s, unicode):
112
return s.encode('utf8')
109
114
except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
110
115
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
113
118
getattr(self, '_fmt', None),
116
def __unicode__(self):
118
if isinstance(u, str):
119
# Try decoding the str using the default encoding.
121
elif not isinstance(u, unicode):
122
# Try to make a unicode object from it, because __unicode__ must
123
# return a unicode object.
129
if isinstance(s, unicode):
132
# __str__ must return a str.
137
return '%s(%s)' % (self.__class__.__name__, str(self))
139
121
def _get_format_string(self):
140
122
"""Return format string for this exception or None"""
141
123
fmt = getattr(self, '_fmt', None)
206
183
class AlreadyBuilding(BzrError):
208
185
_fmt = "The tree builder is already building a tree."
211
class BranchError(BzrError):
212
"""Base class for concrete 'errors about a branch'."""
214
def __init__(self, branch):
215
BzrError.__init__(self, branch=branch)
218
188
class BzrCheckError(InternalBzrError):
220
_fmt = "Internal check failed: %(msg)s"
222
def __init__(self, msg):
223
BzrError.__init__(self)
227
class DirstateCorrupt(BzrError):
229
_fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
231
def __init__(self, state, msg):
232
BzrError.__init__(self)
190
_fmt = "Internal check failed: %(message)s"
192
def __init__(self, message):
193
BzrError.__init__(self)
194
self.message = message
237
197
class DisabledMethod(InternalBzrError):
577
542
class InvalidURLJoin(PathError):
579
_fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
581
def __init__(self, reason, base, join_args):
584
self.join_args = join_args
585
PathError.__init__(self, base, reason)
588
class InvalidRebaseURLs(PathError):
590
_fmt = "URLs differ by more than path: %(from_)r and %(to)r"
592
def __init__(self, from_, to):
595
PathError.__init__(self, from_, 'URLs differ by more than path.')
598
class UnavailableRepresentation(InternalBzrError):
600
_fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
601
"is encoded as '%(native)s'.")
603
def __init__(self, key, wanted, native):
604
InternalBzrError.__init__(self)
544
_fmt = 'Invalid URL join request: "%(args)s"%(extra)s'
546
def __init__(self, msg, base, args):
547
PathError.__init__(self, base, msg)
548
self.args = [base] + list(args)
610
551
class UnknownHook(BzrError):
1115
1026
BzrError.__init__(self, branch=branch, revision=revision)
1029
# zero_ninetyone: this exception is no longer raised and should be removed
1030
class NotLeftParentDescendant(InternalBzrError):
1032
_fmt = ("Revision %(old_revision)s is not the left parent of"
1033
" %(new_revision)s, but branch %(branch_location)s expects this")
1035
def __init__(self, branch, old_revision, new_revision):
1036
BzrError.__init__(self, branch_location=branch.base,
1037
old_revision=old_revision,
1038
new_revision=new_revision)
1118
1041
class RangeInChangeOption(BzrError):
1120
1043
_fmt = "Option --change does not accept revision ranges"
1485
1396
self.options = options
1488
class RetryWithNewPacks(BzrError):
1489
"""Raised when we realize that the packs on disk have changed.
1491
This is meant as more of a signaling exception, to trap between where a
1492
local error occurred and the code that can actually handle the error and
1493
code that can retry appropriately.
1496
internal_error = True
1498
_fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1501
def __init__(self, context, reload_occurred, exc_info):
1502
"""create a new RetryWithNewPacks 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
1521
class RetryAutopack(RetryWithNewPacks):
1522
"""Raised when we are autopacking and we find a missing file.
1524
Meant as a signaling exception, to tell the autopack code it should try
1528
internal_error = True
1530
_fmt = ("Pack files have changed, reload and try autopack again."
1531
" context: %(context)s %(orig_error)s")
1534
1399
class NoSuchExportFormat(BzrError):
1536
1401
_fmt = "Export format %(format)r not supported"
1574
1439
self.details = details
1577
class UnexpectedProtocolVersionMarker(TransportError):
1579
_fmt = "Received bad protocol version marker: %(marker)r"
1581
def __init__(self, marker):
1582
self.marker = marker
1585
class UnknownSmartMethod(InternalBzrError):
1587
_fmt = "The server does not recognise the '%(verb)s' request."
1589
def __init__(self, verb):
1593
class SmartMessageHandlerError(InternalBzrError):
1595
_fmt = ("The message handler raised an exception:\n"
1596
"%(traceback_text)s")
1598
def __init__(self, exc_info):
1600
self.exc_type, self.exc_value, self.exc_tb = exc_info
1601
self.exc_info = exc_info
1602
traceback_strings = traceback.format_exception(
1603
self.exc_type, self.exc_value, self.exc_tb)
1604
self.traceback_text = ''.join(traceback_strings)
1607
1442
# A set of semi-meaningful errors which can be thrown
1608
1443
class TransportNotPossible(TransportError):
1681
1516
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1683
def __init__(self, source, target, is_permanent=False):
1518
def __init__(self, source, target, is_permanent=False, qual_proto=None):
1684
1519
self.source = source
1685
1520
self.target = target
1686
1521
if is_permanent:
1687
1522
self.permanently = ' permanently'
1689
1524
self.permanently = ''
1525
self._qualified_proto = qual_proto
1690
1526
TransportError.__init__(self)
1528
def _requalify_url(self, url):
1529
"""Restore the qualified proto in front of the url"""
1530
# When this exception is raised, source and target are in
1531
# user readable format. But some transports may use a
1532
# different proto (http+urllib:// will present http:// to
1533
# the user. If a qualified proto is specified, the code
1534
# trapping the exception can get the qualified urls to
1535
# properly handle the redirection themself (creating a
1536
# new transport object from the target url for example).
1537
# But checking that the scheme of the original and
1538
# redirected urls are the same can be tricky. (see the
1539
# FIXME in BzrDir.open_from_transport for the unique use
1541
if self._qualified_proto is None:
1544
# The TODO related to NotBranchError mention that doing
1545
# that kind of manipulation on the urls may not be the
1546
# exception object job. On the other hand, this object is
1547
# the interface between the code and the user so
1548
# presenting the urls in different ways is indeed its
1551
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1552
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1555
def get_source_url(self):
1556
return self._requalify_url(self.source)
1558
def get_target_url(self):
1559
return self._requalify_url(self.target)
1693
1562
class TooManyRedirections(TransportError):
2536
2379
self.response_tuple = response_tuple
2539
class ErrorFromSmartServer(BzrError):
2540
"""An error was received from a smart server.
2542
:seealso: UnknownErrorFromSmartServer
2545
_fmt = "Error received from smart server: %(error_tuple)r"
2547
internal_error = True
2549
def __init__(self, error_tuple):
2550
self.error_tuple = error_tuple
2552
self.error_verb = error_tuple[0]
2554
self.error_verb = None
2555
self.error_args = error_tuple[1:]
2558
class UnknownErrorFromSmartServer(BzrError):
2559
"""An ErrorFromSmartServer could not be translated into a typical bzrlib
2562
This is distinct from ErrorFromSmartServer so that it is possible to
2563
distinguish between the following two cases:
2564
- ErrorFromSmartServer was uncaught. This is logic error in the client
2565
and so should provoke a traceback to the user.
2566
- ErrorFromSmartServer was caught but its error_tuple could not be
2567
translated. This is probably because the server sent us garbage, and
2568
should not provoke a traceback.
2571
_fmt = "Server sent an unexpected error: %(error_tuple)r"
2573
internal_error = False
2575
def __init__(self, error_from_smart_server):
2578
:param error_from_smart_server: An ErrorFromSmartServer instance.
2580
self.error_from_smart_server = error_from_smart_server
2581
self.error_tuple = error_from_smart_server.error_tuple
2584
2382
class ContainerError(BzrError):
2585
2383
"""Base class of container errors."""
2813
2577
def __init__(self, timezone):
2814
2578
self.timezone = timezone
2817
class CommandAvailableInPlugin(StandardError):
2819
internal_error = False
2821
def __init__(self, cmd_name, plugin_metadata, provider):
2823
self.plugin_metadata = plugin_metadata
2824
self.cmd_name = cmd_name
2825
self.provider = provider
2829
_fmt = ('"%s" is not a standard bzr command. \n'
2830
'However, the following official plugin provides this command: %s\n'
2831
'You can install it by going to: %s'
2832
% (self.cmd_name, self.plugin_metadata['name'],
2833
self.plugin_metadata['url']))
2838
class NoPluginAvailable(BzrError):
2842
class NotATerminal(BzrError):
2844
_fmt = 'Unable to ask for a password without real terminal.'
2847
class UnableEncodePath(BzrError):
2849
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2850
'user encoding %(user_encoding)s')
2852
def __init__(self, path, kind):
2853
from bzrlib.osutils import get_user_encoding
2856
self.user_encoding = osutils.get_user_encoding()
2859
class NoSuchAlias(BzrError):
2861
_fmt = ('The alias "%(alias_name)s" does not exist.')
2863
def __init__(self, alias_name):
2864
BzrError.__init__(self, alias_name=alias_name)
2867
class DirectoryLookupFailure(BzrError):
2868
"""Base type for lookup errors."""
2873
class InvalidLocationAlias(DirectoryLookupFailure):
2875
_fmt = '"%(alias_name)s" is not a valid location alias.'
2877
def __init__(self, alias_name):
2878
DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2881
class UnsetLocationAlias(DirectoryLookupFailure):
2883
_fmt = 'No %(alias_name)s location assigned.'
2885
def __init__(self, alias_name):
2886
DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2889
class CannotBindAddress(BzrError):
2891
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2893
def __init__(self, host, port, orig_error):
2894
BzrError.__init__(self, host=host, port=port,
2895
orig_error=orig_error[1])
2898
class UnknownRules(BzrError):
2900
_fmt = ('Unknown rules detected: %(unknowns_str)s.')
2902
def __init__(self, unknowns):
2903
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2906
class HookFailed(BzrError):
2907
"""Raised when a pre_change_branch_tip hook function fails anything other
2908
than TipChangeRejected.
2911
_fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2912
"%(traceback_text)s%(exc_value)s")
2914
def __init__(self, hook_stage, hook_name, exc_info):
2916
self.hook_stage = hook_stage
2917
self.hook_name = hook_name
2918
self.exc_info = exc_info
2919
self.exc_type = exc_info[0]
2920
self.exc_value = exc_info[1]
2921
self.exc_tb = exc_info[2]
2922
self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2925
class TipChangeRejected(BzrError):
2926
"""A pre_change_branch_tip hook function may raise this to cleanly and
2927
explicitly abort a change to a branch tip.
2930
_fmt = u"Tip change rejected: %(msg)s"
2932
def __init__(self, msg):
2936
class ShelfCorrupt(BzrError):
2938
_fmt = "Shelf corrupt."
2941
class NoSuchShelfId(BzrError):
2943
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
2945
def __init__(self, shelf_id):
2946
BzrError.__init__(self, shelf_id=shelf_id)
2949
class InvalidShelfId(BzrError):
2951
_fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
2953
def __init__(self, invalid_id):
2954
BzrError.__init__(self, invalid_id=invalid_id)
2957
class UserAbort(BzrError):
2959
_fmt = 'The user aborted the operation.'
2962
class MustHaveWorkingTree(BzrError):
2964
_fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
2966
def __init__(self, format, url):
2967
BzrError.__init__(self, format=format, url=url)