92
93
for key, value in kwds.items():
93
94
setattr(self, key, value)
96
97
s = getattr(self, '_preformatted_string', None)
98
# contains a preformatted message; must be cast to plain str
99
# contains a preformatted message
101
102
fmt = self._get_format_string()
108
109
# __str__() should always return a 'str' object
109
110
# never a 'unicode' object.
110
if isinstance(s, unicode):
111
return s.encode('utf8')
113
112
except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
114
113
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
117
116
getattr(self, '_fmt', None),
119
def __unicode__(self):
121
if isinstance(u, str):
122
# Try decoding the str using the default encoding.
124
elif not isinstance(u, unicode):
125
# Try to make a unicode object from it, because __unicode__ must
126
# return a unicode object.
132
if isinstance(s, unicode):
135
# __str__ must return a str.
120
139
def _get_format_string(self):
121
140
"""Return format string for this exception or None"""
122
141
fmt = getattr(self, '_fmt', None)
365
399
# are not intended to be caught anyway. UI code need not subclass
366
400
# BzrCommandError, and non-UI code should not throw a subclass of
367
401
# BzrCommandError. ADHB 20051211
368
def __init__(self, msg):
369
# Object.__str__() must return a real string
370
# returning a Unicode string is a python error.
371
if isinstance(msg, unicode):
372
self.msg = msg.encode('utf8')
380
404
class NotWriteLocked(BzrError):
561
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)
564
610
class UnknownHook(BzrError):
566
612
_fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
739
785
class IncompatibleRepositories(BzrError):
741
_fmt = "Repository %(target)s is not compatible with repository"\
787
_fmt = "%(target)s\n" \
788
"is not compatible with\n" \
744
def __init__(self, source, target):
745
BzrError.__init__(self, target=target, source=source)
792
def __init__(self, source, target, details=None):
794
details = "(no details)"
795
BzrError.__init__(self, target=target, source=source, details=details)
748
798
class IncompatibleRevision(BzrError):
835
885
BzrError.__init__(self, filename=filename, kind=kind)
888
class BadFilenameEncoding(BzrError):
890
_fmt = ('Filename %(filename)r is not valid in your current filesystem'
891
' encoding %(fs_encoding)s')
893
def __init__(self, filename, fs_encoding):
894
BzrError.__init__(self)
895
self.filename = filename
896
self.fs_encoding = fs_encoding
838
899
class ForbiddenControlFileError(BzrError):
840
901
_fmt = 'Cannot operate on "%(filename)s" because it is a control file'
896
class ReadOnlyLockError(LockError):
898
_fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
900
@symbol_versioning.deprecated_method(symbol_versioning.zero_ninetytwo)
901
def __init__(self, fname, msg):
902
LockError.__init__(self, '')
907
957
class LockFailed(LockError):
909
959
internal_error = False
1065
1115
BzrError.__init__(self, branch=branch, revision=revision)
1068
# zero_ninetyone: this exception is no longer raised and should be removed
1069
class NotLeftParentDescendant(InternalBzrError):
1071
_fmt = ("Revision %(old_revision)s is not the left parent of"
1072
" %(new_revision)s, but branch %(branch_location)s expects this")
1074
def __init__(self, branch, old_revision, new_revision):
1075
BzrError.__init__(self, branch_location=branch.base,
1076
old_revision=old_revision,
1077
new_revision=new_revision)
1080
1118
class RangeInChangeOption(BzrError):
1082
1120
_fmt = "Option --change does not accept revision ranges"
1475
1513
self.details = details
1516
class UnexpectedProtocolVersionMarker(TransportError):
1518
_fmt = "Received bad protocol version marker: %(marker)r"
1520
def __init__(self, marker):
1521
self.marker = marker
1524
class UnknownSmartMethod(InternalBzrError):
1526
_fmt = "The server does not recognise the '%(verb)s' request."
1528
def __init__(self, verb):
1532
class SmartMessageHandlerError(InternalBzrError):
1534
_fmt = "The message handler raised an exception: %(exc_value)s."
1536
def __init__(self, exc_info):
1537
self.exc_type, self.exc_value, self.tb = exc_info
1478
1540
# A set of semi-meaningful errors which can be thrown
1479
1541
class TransportNotPossible(TransportError):
2235
2302
" Please set BZR_SSH environment variable.")
2305
class GhostRevisionsHaveNoRevno(BzrError):
2306
"""When searching for revnos, if we encounter a ghost, we are stuck"""
2308
_fmt = ("Could not determine revno for {%(revision_id)s} because"
2309
" its ancestry shows a ghost at {%(ghost_revision_id)s}")
2311
def __init__(self, revision_id, ghost_revision_id):
2312
self.revision_id = revision_id
2313
self.ghost_revision_id = ghost_revision_id
2238
2316
class GhostRevisionUnusableHere(BzrError):
2240
2318
_fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2318
2396
self.patch_type = patch_type
2399
class TargetNotBranch(BzrError):
2400
"""A merge directive's target branch is required, but isn't a branch"""
2402
_fmt = ("Your branch does not have all of the revisions required in "
2403
"order to merge this merge directive and the target "
2404
"location specified in the merge directive is not a branch: "
2407
def __init__(self, location):
2408
BzrError.__init__(self)
2409
self.location = location
2321
2412
class UnsupportedInventoryKind(BzrError):
2323
2414
_fmt = """Unsupported entry kind %(kind)s"""
2417
2508
self.response_tuple = response_tuple
2511
class ErrorFromSmartServer(BzrError):
2512
"""An error was received from a smart server.
2514
:seealso: UnknownErrorFromSmartServer
2517
_fmt = "Error received from smart server: %(error_tuple)r"
2519
internal_error = True
2521
def __init__(self, error_tuple):
2522
self.error_tuple = error_tuple
2524
self.error_verb = error_tuple[0]
2526
self.error_verb = None
2527
self.error_args = error_tuple[1:]
2530
class UnknownErrorFromSmartServer(BzrError):
2531
"""An ErrorFromSmartServer could not be translated into a typical bzrlib
2534
This is distinct from ErrorFromSmartServer so that it is possible to
2535
distinguish between the following two cases:
2536
- ErrorFromSmartServer was uncaught. This is logic error in the client
2537
and so should provoke a traceback to the user.
2538
- ErrorFromSmartServer was caught but its error_tuple could not be
2539
translated. This is probably because the server sent us garbage, and
2540
should not provoke a traceback.
2543
_fmt = "Server sent an unexpected error: %(error_tuple)r"
2545
internal_error = False
2547
def __init__(self, error_from_smart_server):
2550
:param error_from_smart_server: An ErrorFromSmartServer instance.
2552
self.error_from_smart_server = error_from_smart_server
2553
self.error_tuple = error_from_smart_server.error_tuple
2420
2556
class ContainerError(BzrError):
2421
2557
"""Base class of container errors."""
2538
2674
BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2677
class UnsyncedBranches(BzrDirError):
2679
_fmt = ("'%(display_url)s' is not in sync with %(target_url)s. See"
2680
" bzr help sync-for-reconfigure.")
2682
def __init__(self, bzrdir, target_branch):
2683
BzrDirError.__init__(self, bzrdir)
2684
import bzrlib.urlutils as urlutils
2685
self.target_url = urlutils.unescape_for_display(target_branch.base,
2541
2689
class AlreadyBranch(BzrDirError):
2543
2691
_fmt = "'%(display_url)s' is already a branch."
2558
2706
_fmt = "'%(display_url)s' is already a lightweight checkout."
2709
class AlreadyUsingShared(BzrDirError):
2711
_fmt = "'%(display_url)s' is already using a shared repository."
2714
class AlreadyStandalone(BzrDirError):
2716
_fmt = "'%(display_url)s' is already standalone."
2561
2719
class ReconfigurationNotSupported(BzrDirError):
2563
2721
_fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2616
2774
self.timezone = timezone
2777
class CommandAvailableInPlugin(StandardError):
2779
internal_error = False
2781
def __init__(self, cmd_name, plugin_metadata, provider):
2783
self.plugin_metadata = plugin_metadata
2784
self.cmd_name = cmd_name
2785
self.provider = provider
2789
_fmt = ('"%s" is not a standard bzr command. \n'
2790
'However, the following official plugin provides this command: %s\n'
2791
'You can install it by going to: %s'
2792
% (self.cmd_name, self.plugin_metadata['name'],
2793
self.plugin_metadata['url']))
2798
class NoPluginAvailable(BzrError):
2619
2802
class NotATerminal(BzrError):
2621
2804
_fmt = 'Unable to ask for a password without real terminal.'
2630
2813
from bzrlib.osutils import get_user_encoding
2631
2814
self.path = path
2632
2815
self.kind = kind
2633
self.user_encoding = get_user_encoding()
2816
self.user_encoding = osutils.get_user_encoding()
2819
class NoSuchAlias(BzrError):
2821
_fmt = ('The alias "%(alias_name)s" does not exist.')
2823
def __init__(self, alias_name):
2824
BzrError.__init__(self, alias_name=alias_name)
2827
class DirectoryLookupFailure(BzrError):
2828
"""Base type for lookup errors."""
2833
class InvalidLocationAlias(DirectoryLookupFailure):
2835
_fmt = '"%(alias_name)s" is not a valid location alias.'
2837
def __init__(self, alias_name):
2838
DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2841
class UnsetLocationAlias(DirectoryLookupFailure):
2843
_fmt = 'No %(alias_name)s location assigned.'
2845
def __init__(self, alias_name):
2846
DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2849
class CannotBindAddress(BzrError):
2851
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2853
def __init__(self, host, port, orig_error):
2854
BzrError.__init__(self, host=host, port=port,
2855
orig_error=orig_error[1])
2858
class UnknownRules(BzrError):
2860
_fmt = ('Unknown rules detected: %(unknowns_str)s.')
2862
def __init__(self, unknowns):
2863
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2866
class HookFailed(BzrError):
2867
"""Raised when a pre_change_branch_tip hook function fails anything other
2868
than TipChangeRejected.
2871
_fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2872
"%(traceback_text)s%(exc_value)s")
2874
def __init__(self, hook_stage, hook_name, exc_info):
2876
self.hook_stage = hook_stage
2877
self.hook_name = hook_name
2878
self.exc_info = exc_info
2879
self.exc_type = exc_info[0]
2880
self.exc_value = exc_info[1]
2881
self.exc_tb = exc_info[2]
2882
self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2885
class TipChangeRejected(BzrError):
2886
"""A pre_change_branch_tip hook function may raise this to cleanly and
2887
explicitly abort a change to a branch tip.
2890
_fmt = u"Tip change rejected: %(msg)s"
2892
def __init__(self, msg):