82
93
for key, value in kwds.items():
83
94
setattr(self, key, value)
86
97
s = getattr(self, '_preformatted_string', None)
88
# contains a preformatted message
99
# contains a preformatted message; must be cast to plain str
91
102
fmt = self._get_format_string()
93
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')
95
109
# __str__() should always return a 'str' object
96
110
# never a 'unicode' object.
111
if isinstance(s, unicode):
112
return s.encode('utf8')
99
pass # just bind to 'e' for formatting below
102
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
114
except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
115
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
116
% (self.__class__.__name__,
118
getattr(self, '_fmt', None),
121
def _get_format_string(self):
122
"""Return format string for this exception or None"""
123
fmt = getattr(self, '_fmt', None)
126
fmt = getattr(self, '__doc__', None)
128
symbol_versioning.warn("%s uses its docstring as a format, "
129
"it should use _fmt instead" % self.__class__.__name__,
132
return 'Unprintable exception %s: dict=%r, fmt=%r' \
103
133
% (self.__class__.__name__,
105
135
getattr(self, '_fmt', None),
108
def __unicode__(self):
110
if isinstance(u, str):
111
# Try decoding the str using the default encoding.
113
elif not isinstance(u, unicode):
114
# Try to make a unicode object from it, because __unicode__ must
115
# return a unicode object.
121
if isinstance(s, unicode):
124
# __str__ must return a str.
129
return '%s(%s)' % (self.__class__.__name__, str(self))
131
def _get_format_string(self):
132
"""Return format string for this exception or None"""
133
fmt = getattr(self, '_fmt', None)
135
from bzrlib.i18n import gettext
136
return gettext(unicode(fmt)) # _fmt strings should be ascii
138
def __eq__(self, other):
139
if self.__class__ is not other.__class__:
140
return NotImplemented
141
return self.__dict__ == other.__dict__
144
139
class InternalBzrError(BzrError):
152
147
internal_error = True
150
class BzrNewError(BzrError):
151
"""Deprecated error base class."""
152
# base classes should override the docstring with their human-
153
# readable explanation
155
def __init__(self, *args, **kwds):
156
# XXX: Use the underlying BzrError to always generate the args
157
# attribute if it doesn't exist. We can't use super here, because
158
# exceptions are old-style classes in python2.4 (but new in 2.5).
160
symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
161
'please convert %s to use BzrError instead'
162
% self.__class__.__name__,
165
BzrError.__init__(self, *args)
166
for key, value in kwds.items():
167
setattr(self, key, value)
171
# __str__() should always return a 'str' object
172
# never a 'unicode' object.
173
s = self.__doc__ % self.__dict__
174
if isinstance(s, unicode):
175
return s.encode('utf8')
177
except (TypeError, NameError, ValueError, KeyError), e:
178
return 'Unprintable exception %s(%r): %r' \
179
% (self.__class__.__name__,
155
183
class AlreadyBuilding(BzrError):
157
185
_fmt = "The tree builder is already building a tree."
160
class BranchError(BzrError):
161
"""Base class for concrete 'errors about a branch'."""
163
def __init__(self, branch):
164
BzrError.__init__(self, branch=branch)
167
188
class BzrCheckError(InternalBzrError):
169
_fmt = "Internal check failed: %(msg)s"
171
def __init__(self, msg):
172
BzrError.__init__(self)
176
class DirstateCorrupt(BzrError):
178
_fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
180
def __init__(self, state, msg):
181
BzrError.__init__(self)
190
_fmt = "Internal check failed: %(message)s"
192
def __init__(self, message):
193
BzrError.__init__(self)
194
self.message = message
186
197
class DisabledMethod(InternalBzrError):
1649
1437
self.port = ':%s' % port
1652
# XXX: This is also used for unexpected end of file, which is different at the
1653
# TCP level from "connection reset".
1654
1440
class ConnectionReset(TransportError):
1656
1442
_fmt = "Connection closed: %(msg)s %(orig_error)s"
1659
class ConnectionTimeout(ConnectionError):
1661
_fmt = "Connection Timeout: %(msg)s%(orig_error)s"
1664
1445
class InvalidRange(TransportError):
1666
_fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1668
def __init__(self, path, offset, msg=None):
1669
TransportError.__init__(self, msg)
1447
_fmt = "Invalid range access in %(path)s at %(offset)s."
1449
def __init__(self, path, offset):
1450
TransportError.__init__(self, ("Invalid range access in %s at %d"
1670
1452
self.path = path
1671
1453
self.offset = offset
1674
1456
class InvalidHttpResponse(TransportError):
1676
_fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
1458
_fmt = "Invalid http response for %(path)s: %(msg)s"
1678
1460
def __init__(self, path, msg, orig_error=None):
1679
1461
self.path = path
1680
if orig_error is None:
1683
# This is reached for obscure and unusual errors so we want to
1684
# preserve as much info as possible to ease debug.
1685
orig_error = ': %r' % (orig_error,)
1686
1462
TransportError.__init__(self, msg, orig_error=orig_error)
1689
1465
class InvalidHttpRange(InvalidHttpResponse):
1691
1467
_fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1693
1469
def __init__(self, path, range, msg):
1694
1470
self.range = range
1695
1471
InvalidHttpResponse.__init__(self, path, msg)
1698
class HttpBoundaryMissing(InvalidHttpResponse):
1699
"""A multipart response ends with no boundary marker.
1701
This is a special case caused by buggy proxies, described in
1702
<https://bugs.launchpad.net/bzr/+bug/198646>.
1705
_fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
1707
def __init__(self, path, msg):
1708
InvalidHttpResponse.__init__(self, path, msg)
1711
1474
class InvalidHttpContentType(InvalidHttpResponse):
1713
1476
_fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1715
1478
def __init__(self, path, ctype, msg):
1716
1479
self.ctype = ctype
1717
1480
InvalidHttpResponse.__init__(self, path, msg)
2932
2463
path_str = repr(path)
2933
2464
path_str += ' '
2934
2465
self.path_str = path_str
2937
class UnsupportedTimezoneFormat(BzrError):
2939
_fmt = ('Unsupported timezone format "%(timezone)s", '
2940
'options are "utc", "original", "local".')
2942
def __init__(self, timezone):
2943
self.timezone = timezone
2946
class CommandAvailableInPlugin(StandardError):
2948
internal_error = False
2950
def __init__(self, cmd_name, plugin_metadata, provider):
2952
self.plugin_metadata = plugin_metadata
2953
self.cmd_name = cmd_name
2954
self.provider = provider
2958
_fmt = ('"%s" is not a standard bzr command. \n'
2959
'However, the following official plugin provides this command: %s\n'
2960
'You can install it by going to: %s'
2961
% (self.cmd_name, self.plugin_metadata['name'],
2962
self.plugin_metadata['url']))
2967
class NoPluginAvailable(BzrError):
2971
class UnableEncodePath(BzrError):
2973
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2974
'user encoding %(user_encoding)s')
2976
def __init__(self, path, kind):
2977
from bzrlib.osutils import get_user_encoding
2980
self.user_encoding = get_user_encoding()
2983
class NoSuchConfig(BzrError):
2985
_fmt = ('The "%(config_id)s" configuration does not exist.')
2987
def __init__(self, config_id):
2988
BzrError.__init__(self, config_id=config_id)
2991
class NoSuchConfigOption(BzrError):
2993
_fmt = ('The "%(option_name)s" configuration option does not exist.')
2995
def __init__(self, option_name):
2996
BzrError.__init__(self, option_name=option_name)
2999
class NoSuchAlias(BzrError):
3001
_fmt = ('The alias "%(alias_name)s" does not exist.')
3003
def __init__(self, alias_name):
3004
BzrError.__init__(self, alias_name=alias_name)
3007
class DirectoryLookupFailure(BzrError):
3008
"""Base type for lookup errors."""
3013
class InvalidLocationAlias(DirectoryLookupFailure):
3015
_fmt = '"%(alias_name)s" is not a valid location alias.'
3017
def __init__(self, alias_name):
3018
DirectoryLookupFailure.__init__(self, alias_name=alias_name)
3021
class UnsetLocationAlias(DirectoryLookupFailure):
3023
_fmt = 'No %(alias_name)s location assigned.'
3025
def __init__(self, alias_name):
3026
DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
3029
class CannotBindAddress(BzrError):
3031
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
3033
def __init__(self, host, port, orig_error):
3034
# nb: in python2.4 socket.error doesn't have a useful repr
3035
BzrError.__init__(self, host=host, port=port,
3036
orig_error=repr(orig_error.args))
3039
class UnknownRules(BzrError):
3041
_fmt = ('Unknown rules detected: %(unknowns_str)s.')
3043
def __init__(self, unknowns):
3044
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
3047
class TipChangeRejected(BzrError):
3048
"""A pre_change_branch_tip hook function may raise this to cleanly and
3049
explicitly abort a change to a branch tip.
3052
_fmt = u"Tip change rejected: %(msg)s"
3054
def __init__(self, msg):
3058
class ShelfCorrupt(BzrError):
3060
_fmt = "Shelf corrupt."
3063
class DecompressCorruption(BzrError):
3065
_fmt = "Corruption while decompressing repository file%(orig_error)s"
3067
def __init__(self, orig_error=None):
3068
if orig_error is not None:
3069
self.orig_error = ", %s" % (orig_error,)
3071
self.orig_error = ""
3072
BzrError.__init__(self)
3075
class NoSuchShelfId(BzrError):
3077
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
3079
def __init__(self, shelf_id):
3080
BzrError.__init__(self, shelf_id=shelf_id)
3083
class InvalidShelfId(BzrError):
3085
_fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3087
def __init__(self, invalid_id):
3088
BzrError.__init__(self, invalid_id=invalid_id)
3091
class JailBreak(BzrError):
3093
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3095
def __init__(self, url):
3096
BzrError.__init__(self, url=url)
3099
class UserAbort(BzrError):
3101
_fmt = 'The user aborted the operation.'
3104
class MustHaveWorkingTree(BzrError):
3106
_fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3108
def __init__(self, format, url):
3109
BzrError.__init__(self, format=format, url=url)
3112
class NoSuchView(BzrError):
3113
"""A view does not exist.
3116
_fmt = u"No such view: %(view_name)s."
3118
def __init__(self, view_name):
3119
self.view_name = view_name
3122
class ViewsNotSupported(BzrError):
3123
"""Views are not supported by a tree format.
3126
_fmt = ("Views are not supported by %(tree)s;"
3127
" use 'bzr upgrade' to change your tree to a later format.")
3129
def __init__(self, tree):
3133
class FileOutsideView(BzrError):
3135
_fmt = ('Specified file "%(file_name)s" is outside the current view: '
3138
def __init__(self, file_name, view_files):
3139
self.file_name = file_name
3140
self.view_str = ", ".join(view_files)
3143
class UnresumableWriteGroup(BzrError):
3145
_fmt = ("Repository %(repository)s cannot resume write group "
3146
"%(write_groups)r: %(reason)s")
3148
internal_error = True
3150
def __init__(self, repository, write_groups, reason):
3151
self.repository = repository
3152
self.write_groups = write_groups
3153
self.reason = reason
3156
class UnsuspendableWriteGroup(BzrError):
3158
_fmt = ("Repository %(repository)s cannot suspend a write group.")
3160
internal_error = True
3162
def __init__(self, repository):
3163
self.repository = repository
3166
class LossyPushToSameVCS(BzrError):
3168
_fmt = ("Lossy push not possible between %(source_branch)r and "
3169
"%(target_branch)r that are in the same VCS.")
3171
internal_error = True
3173
def __init__(self, source_branch, target_branch):
3174
self.source_branch = source_branch
3175
self.target_branch = target_branch
3178
class NoRoundtrippingSupport(BzrError):
3180
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
3181
"%(target_branch)r.")
3183
internal_error = True
3185
def __init__(self, source_branch, target_branch):
3186
self.source_branch = source_branch
3187
self.target_branch = target_branch
3190
class FileTimestampUnavailable(BzrError):
3192
_fmt = "The filestamp for %(path)s is not available."
3194
internal_error = True
3196
def __init__(self, path):
3200
class NoColocatedBranchSupport(BzrError):
3202
_fmt = ("%(bzrdir)r does not support co-located branches.")
3204
def __init__(self, bzrdir):
3205
self.bzrdir = bzrdir
3208
class NoWhoami(BzrError):
3210
_fmt = ('Unable to determine your name.\n'
3211
"Please, set your name with the 'whoami' command.\n"
3212
'E.g. bzr whoami "Your Name <name@example.com>"')
3215
class InvalidPattern(BzrError):
3217
_fmt = ('Invalid pattern(s) found. %(msg)s')
3219
def __init__(self, msg):
3223
class RecursiveBind(BzrError):
3225
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3226
'Please use `bzr unbind` to fix.')
3228
def __init__(self, branch_url):
3229
self.branch_url = branch_url
3232
# FIXME: I would prefer to define the config related exception classes in
3233
# config.py but the lazy import mechanism proscribes this -- vila 20101222
3234
class OptionExpansionLoop(BzrError):
3236
_fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3238
def __init__(self, string, refs):
3239
self.string = string
3240
self.refs = '->'.join(refs)
3243
class ExpandingUnknownOption(BzrError):
3245
_fmt = 'Option "%(name)s" is not defined while expanding "%(string)s".'
3247
def __init__(self, name, string):
3249
self.string = string
3252
class IllegalOptionName(BzrError):
3254
_fmt = 'Option "%(name)s" is not allowed.'
3256
def __init__(self, name):
3260
class NoCompatibleInter(BzrError):
3262
_fmt = ('No compatible object available for operations from %(source)r '
3265
def __init__(self, source, target):
3266
self.source = source
3267
self.target = target
3270
class HpssVfsRequestNotAllowed(BzrError):
3272
_fmt = ("VFS requests over the smart server are not allowed. Encountered: "
3273
"%(method)s, %(arguments)s.")
3275
def __init__(self, method, arguments):
3276
self.method = method
3277
self.arguments = arguments
3280
class UnsupportedKindChange(BzrError):
3282
_fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
3283
"%(path)s not supported by format %(format)r")
3285
def __init__(self, path, from_kind, to_kind, format):
3287
self.from_kind = from_kind
3288
self.to_kind = to_kind
3289
self.format = format
3292
class MissingFeature(BzrError):
3294
_fmt = ("Missing feature %(feature)s not provided by this "
3295
"version of Bazaar or any plugin.")
3297
def __init__(self, feature):
3298
self.feature = feature
3301
class PatchSyntax(BzrError):
3302
"""Base class for patch syntax errors."""
3305
class BinaryFiles(BzrError):
3307
_fmt = 'Binary files section encountered.'
3309
def __init__(self, orig_name, mod_name):
3310
self.orig_name = orig_name
3311
self.mod_name = mod_name
3314
class MalformedPatchHeader(PatchSyntax):
3316
_fmt = "Malformed patch header. %(desc)s\n%(line)r"
3318
def __init__(self, desc, line):
3323
class MalformedHunkHeader(PatchSyntax):
3325
_fmt = "Malformed hunk header. %(desc)s\n%(line)r"
3327
def __init__(self, desc, line):
3332
class MalformedLine(PatchSyntax):
3334
_fmt = "Malformed line. %(desc)s\n%(line)r"
3336
def __init__(self, desc, line):
3341
class PatchConflict(BzrError):
3343
_fmt = ('Text contents mismatch at line %(line_no)d. Original has '
3344
'"%(orig_line)s", but patch says it should be "%(patch_line)s"')
3346
def __init__(self, line_no, orig_line, patch_line):
3347
self.line_no = line_no
3348
self.orig_line = orig_line.rstrip('\n')
3349
self.patch_line = patch_line.rstrip('\n')
3352
class FeatureAlreadyRegistered(BzrError):
3354
_fmt = 'The feature %(feature)s has already been registered.'
3356
def __init__(self, feature):
3357
self.feature = feature
3360
class ChangesAlreadyStored(BzrCommandError):
3362
_fmt = ('Cannot store uncommitted changes because this branch already'
3363
' stores uncommitted changes.')