87
82
for key, value in kwds.items():
88
83
setattr(self, key, value)
91
86
s = getattr(self, '_preformatted_string', None)
93
# contains a preformatted message; must be cast to plain str
88
# contains a preformatted message
96
91
fmt = self._get_format_string()
98
s = fmt % self.__dict__
93
d = dict(self.__dict__)
99
95
# __str__() should always return a 'str' object
100
96
# never a 'unicode' object.
101
if isinstance(s, unicode):
102
return s.encode('utf8')
104
except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
105
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
106
% (self.__class__.__name__,
108
getattr(self, '_fmt', None),
99
pass # just bind to 'e' for formatting below
102
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
103
% (self.__class__.__name__,
105
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))
111
131
def _get_format_string(self):
112
132
"""Return format string for this exception or None"""
113
133
fmt = getattr(self, '_fmt', None)
114
134
if fmt is not None:
116
fmt = getattr(self, '__doc__', None)
118
symbol_versioning.warn("%s uses its docstring as a format, "
119
"it should use _fmt instead" % self.__class__.__name__,
122
return 'Unprintable exception %s: dict=%r, fmt=%r' \
123
% (self.__class__.__name__,
125
getattr(self, '_fmt', None),
129
class BzrNewError(BzrError):
130
"""Deprecated error base class."""
131
# base classes should override the docstring with their human-
132
# readable explanation
134
def __init__(self, *args, **kwds):
135
# XXX: Use the underlying BzrError to always generate the args
136
# attribute if it doesn't exist. We can't use super here, because
137
# exceptions are old-style classes in python2.4 (but new in 2.5).
139
symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
140
'please convert %s to use BzrError instead'
141
% self.__class__.__name__,
144
BzrError.__init__(self, *args)
145
for key, value in kwds.items():
146
setattr(self, key, value)
150
# __str__() should always return a 'str' object
151
# never a 'unicode' object.
152
s = self.__doc__ % self.__dict__
153
if isinstance(s, unicode):
154
return s.encode('utf8')
156
except (TypeError, NameError, ValueError, KeyError), e:
157
return 'Unprintable exception %s(%r): %r' \
158
% (self.__class__.__name__,
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
class InternalBzrError(BzrError):
145
"""Base class for errors that are internal in nature.
147
This is a convenience class for errors that are internal. The
148
internal_error attribute can still be altered in subclasses, if needed.
149
Using this class is simply an easy way to get internal errors.
152
internal_error = True
162
155
class AlreadyBuilding(BzrError):
164
157
_fmt = "The tree builder is already building a tree."
167
class BzrCheckError(BzrError):
169
_fmt = "Internal check failed: %(message)s"
171
internal_error = True
173
def __init__(self, message):
174
BzrError.__init__(self)
175
self.message = message
178
class DisabledMethod(BzrError):
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
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)
186
class DisabledMethod(InternalBzrError):
180
188
_fmt = "The smart server method '%(class_name)s' is disabled."
182
internal_error = True
184
190
def __init__(self, class_name):
185
191
BzrError.__init__(self)
186
192
self.class_name = class_name
1381
1721
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1383
def __init__(self, source, target, is_permament=False, qual_proto=None):
1723
def __init__(self, source, target, is_permanent=False):
1384
1724
self.source = source
1385
1725
self.target = target
1387
1727
self.permanently = ' permanently'
1389
1729
self.permanently = ''
1390
self.is_permament = is_permament
1391
self._qualified_proto = qual_proto
1392
1730
TransportError.__init__(self)
1394
def _requalify_url(self, url):
1395
"""Restore the qualified proto in front of the url"""
1396
# When this exception is raised, source and target are in
1397
# user readable format. But some transports may use a
1398
# different proto (http+urllib:// will present http:// to
1399
# the user. If a qualified proto is specified, the code
1400
# trapping the exception can get the qualified urls to
1401
# properly handle the redirection themself (creating a
1402
# new transport object from the target url for example).
1403
# But checking that the scheme of the original and
1404
# redirected urls are the same can be tricky. (see the
1405
# FIXME in BzrDir.open_from_transport for the unique use
1407
if self._qualified_proto is None:
1410
# The TODO related to NotBranchError mention that doing
1411
# that kind of manipulation on the urls may not be the
1412
# exception object job. On the other hand, this object is
1413
# the interface between the code and the user so
1414
# presenting the urls in different ways is indeed its
1417
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1418
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1421
def get_source_url(self):
1422
return self._requalify_url(self.source)
1424
def get_target_url(self):
1425
return self._requalify_url(self.target)
1428
1733
class TooManyRedirections(TransportError):
1430
1735
_fmt = "Too many redirections"
1432
1738
class ConflictsInTree(BzrError):
1434
1740
_fmt = "Working tree has conflicts."
1743
class ConfigContentError(BzrError):
1745
_fmt = "Config file %(filename)s is not UTF-8 encoded\n"
1747
def __init__(self, filename):
1748
BzrError.__init__(self)
1749
self.filename = filename
1437
1752
class ParseConfigError(BzrError):
1754
_fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
1439
1756
def __init__(self, errors, filename):
1440
if filename is None:
1442
message = "Error(s) parsing config file %s:\n%s" % \
1443
(filename, ('\n'.join(e.message for e in errors)))
1444
BzrError.__init__(self, message)
1757
BzrError.__init__(self)
1758
self.filename = filename
1759
self.errors = '\n'.join(e.msg for e in errors)
1762
class ConfigOptionValueError(BzrError):
1764
_fmt = ('Bad value "%(value)s" for option "%(name)s".\n'
1765
'See ``bzr help %(name)s``')
1767
def __init__(self, name, value):
1768
BzrError.__init__(self, name=name, value=value)
1447
1771
class NoEmailInUsername(BzrError):
2233
2757
def __init__(self, error):
2234
2758
self.error = error
2761
class NoMessageSupplied(BzrError):
2763
_fmt = "No message supplied."
2766
class NoMailAddressSpecified(BzrError):
2768
_fmt = "No mail-to address (--mail-to) or output (-o) specified."
2771
class MailClientNotFound(BzrError):
2773
_fmt = "Unable to find mail client with the following names:"\
2774
" %(mail_command_list_string)s"
2776
def __init__(self, mail_command_list):
2777
mail_command_list_string = ', '.join(mail_command_list)
2778
BzrError.__init__(self, mail_command_list=mail_command_list,
2779
mail_command_list_string=mail_command_list_string)
2781
class SMTPConnectionRefused(SMTPError):
2783
_fmt = "SMTP connection to %(host)s refused"
2785
def __init__(self, error, host):
2790
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2792
_fmt = "Please specify smtp_server. No server at default %(host)s."
2795
class BzrDirError(BzrError):
2797
def __init__(self, bzrdir):
2798
import bzrlib.urlutils as urlutils
2799
display_url = urlutils.unescape_for_display(bzrdir.user_url,
2801
BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2804
class UnsyncedBranches(BzrDirError):
2806
_fmt = ("'%(display_url)s' is not in sync with %(target_url)s. See"
2807
" bzr help sync-for-reconfigure.")
2809
def __init__(self, bzrdir, target_branch):
2810
BzrDirError.__init__(self, bzrdir)
2811
import bzrlib.urlutils as urlutils
2812
self.target_url = urlutils.unescape_for_display(target_branch.base,
2816
class AlreadyBranch(BzrDirError):
2818
_fmt = "'%(display_url)s' is already a branch."
2821
class AlreadyTree(BzrDirError):
2823
_fmt = "'%(display_url)s' is already a tree."
2826
class AlreadyCheckout(BzrDirError):
2828
_fmt = "'%(display_url)s' is already a checkout."
2831
class AlreadyLightweightCheckout(BzrDirError):
2833
_fmt = "'%(display_url)s' is already a lightweight checkout."
2836
class AlreadyUsingShared(BzrDirError):
2838
_fmt = "'%(display_url)s' is already using a shared repository."
2841
class AlreadyStandalone(BzrDirError):
2843
_fmt = "'%(display_url)s' is already standalone."
2846
class AlreadyWithTrees(BzrDirError):
2848
_fmt = ("Shared repository '%(display_url)s' already creates "
2852
class AlreadyWithNoTrees(BzrDirError):
2854
_fmt = ("Shared repository '%(display_url)s' already doesn't create "
2858
class ReconfigurationNotSupported(BzrDirError):
2860
_fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2863
class NoBindLocation(BzrDirError):
2865
_fmt = "No location could be found to bind to at %(display_url)s."
2868
class UncommittedChanges(BzrError):
2870
_fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2871
' (See bzr status).%(more)s')
2873
def __init__(self, tree, more=None):
2878
import bzrlib.urlutils as urlutils
2879
user_url = getattr(tree, "user_url", None)
2880
if user_url is None:
2881
display_url = str(tree)
2883
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2884
BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2887
class ShelvedChanges(UncommittedChanges):
2889
_fmt = ('Working tree "%(display_url)s" has shelved changes'
2890
' (See bzr shelve --list).%(more)s')
2893
class MissingTemplateVariable(BzrError):
2895
_fmt = 'Variable {%(name)s} is not available.'
2897
def __init__(self, name):
2901
class NoTemplate(BzrError):
2903
_fmt = 'No template specified.'
2906
class UnableCreateSymlink(BzrError):
2908
_fmt = 'Unable to create symlink %(path_str)son this platform'
2910
def __init__(self, path=None):
2914
path_str = repr(str(path))
2915
except UnicodeEncodeError:
2916
path_str = repr(path)
2918
self.path_str = path_str
2921
class UnsupportedTimezoneFormat(BzrError):
2923
_fmt = ('Unsupported timezone format "%(timezone)s", '
2924
'options are "utc", "original", "local".')
2926
def __init__(self, timezone):
2927
self.timezone = timezone
2930
class CommandAvailableInPlugin(StandardError):
2932
internal_error = False
2934
def __init__(self, cmd_name, plugin_metadata, provider):
2936
self.plugin_metadata = plugin_metadata
2937
self.cmd_name = cmd_name
2938
self.provider = provider
2942
_fmt = ('"%s" is not a standard bzr command. \n'
2943
'However, the following official plugin provides this command: %s\n'
2944
'You can install it by going to: %s'
2945
% (self.cmd_name, self.plugin_metadata['name'],
2946
self.plugin_metadata['url']))
2951
class NoPluginAvailable(BzrError):
2955
class UnableEncodePath(BzrError):
2957
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2958
'user encoding %(user_encoding)s')
2960
def __init__(self, path, kind):
2961
from bzrlib.osutils import get_user_encoding
2964
self.user_encoding = get_user_encoding()
2967
class NoSuchConfig(BzrError):
2969
_fmt = ('The "%(config_id)s" configuration does not exist.')
2971
def __init__(self, config_id):
2972
BzrError.__init__(self, config_id=config_id)
2975
class NoSuchConfigOption(BzrError):
2977
_fmt = ('The "%(option_name)s" configuration option does not exist.')
2979
def __init__(self, option_name):
2980
BzrError.__init__(self, option_name=option_name)
2983
class NoSuchAlias(BzrError):
2985
_fmt = ('The alias "%(alias_name)s" does not exist.')
2987
def __init__(self, alias_name):
2988
BzrError.__init__(self, alias_name=alias_name)
2991
class DirectoryLookupFailure(BzrError):
2992
"""Base type for lookup errors."""
2997
class InvalidLocationAlias(DirectoryLookupFailure):
2999
_fmt = '"%(alias_name)s" is not a valid location alias.'
3001
def __init__(self, alias_name):
3002
DirectoryLookupFailure.__init__(self, alias_name=alias_name)
3005
class UnsetLocationAlias(DirectoryLookupFailure):
3007
_fmt = 'No %(alias_name)s location assigned.'
3009
def __init__(self, alias_name):
3010
DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
3013
class CannotBindAddress(BzrError):
3015
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
3017
def __init__(self, host, port, orig_error):
3018
# nb: in python2.4 socket.error doesn't have a useful repr
3019
BzrError.__init__(self, host=host, port=port,
3020
orig_error=repr(orig_error.args))
3023
class UnknownRules(BzrError):
3025
_fmt = ('Unknown rules detected: %(unknowns_str)s.')
3027
def __init__(self, unknowns):
3028
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
3031
class TipChangeRejected(BzrError):
3032
"""A pre_change_branch_tip hook function may raise this to cleanly and
3033
explicitly abort a change to a branch tip.
3036
_fmt = u"Tip change rejected: %(msg)s"
3038
def __init__(self, msg):
3042
class ShelfCorrupt(BzrError):
3044
_fmt = "Shelf corrupt."
3047
class DecompressCorruption(BzrError):
3049
_fmt = "Corruption while decompressing repository file%(orig_error)s"
3051
def __init__(self, orig_error=None):
3052
if orig_error is not None:
3053
self.orig_error = ", %s" % (orig_error,)
3055
self.orig_error = ""
3056
BzrError.__init__(self)
3059
class NoSuchShelfId(BzrError):
3061
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
3063
def __init__(self, shelf_id):
3064
BzrError.__init__(self, shelf_id=shelf_id)
3067
class InvalidShelfId(BzrError):
3069
_fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3071
def __init__(self, invalid_id):
3072
BzrError.__init__(self, invalid_id=invalid_id)
3075
class JailBreak(BzrError):
3077
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3079
def __init__(self, url):
3080
BzrError.__init__(self, url=url)
3083
class UserAbort(BzrError):
3085
_fmt = 'The user aborted the operation.'
3088
class MustHaveWorkingTree(BzrError):
3090
_fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3092
def __init__(self, format, url):
3093
BzrError.__init__(self, format=format, url=url)
3096
class NoSuchView(BzrError):
3097
"""A view does not exist.
3100
_fmt = u"No such view: %(view_name)s."
3102
def __init__(self, view_name):
3103
self.view_name = view_name
3106
class ViewsNotSupported(BzrError):
3107
"""Views are not supported by a tree format.
3110
_fmt = ("Views are not supported by %(tree)s;"
3111
" use 'bzr upgrade' to change your tree to a later format.")
3113
def __init__(self, tree):
3117
class FileOutsideView(BzrError):
3119
_fmt = ('Specified file "%(file_name)s" is outside the current view: '
3122
def __init__(self, file_name, view_files):
3123
self.file_name = file_name
3124
self.view_str = ", ".join(view_files)
3127
class UnresumableWriteGroup(BzrError):
3129
_fmt = ("Repository %(repository)s cannot resume write group "
3130
"%(write_groups)r: %(reason)s")
3132
internal_error = True
3134
def __init__(self, repository, write_groups, reason):
3135
self.repository = repository
3136
self.write_groups = write_groups
3137
self.reason = reason
3140
class UnsuspendableWriteGroup(BzrError):
3142
_fmt = ("Repository %(repository)s cannot suspend a write group.")
3144
internal_error = True
3146
def __init__(self, repository):
3147
self.repository = repository
3150
class LossyPushToSameVCS(BzrError):
3152
_fmt = ("Lossy push not possible between %(source_branch)r and "
3153
"%(target_branch)r that are in the same VCS.")
3155
internal_error = True
3157
def __init__(self, source_branch, target_branch):
3158
self.source_branch = source_branch
3159
self.target_branch = target_branch
3162
class NoRoundtrippingSupport(BzrError):
3164
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
3165
"%(target_branch)r.")
3167
internal_error = True
3169
def __init__(self, source_branch, target_branch):
3170
self.source_branch = source_branch
3171
self.target_branch = target_branch
3174
class FileTimestampUnavailable(BzrError):
3176
_fmt = "The filestamp for %(path)s is not available."
3178
internal_error = True
3180
def __init__(self, path):
3184
class NoColocatedBranchSupport(BzrError):
3186
_fmt = ("%(bzrdir)r does not support co-located branches.")
3188
def __init__(self, bzrdir):
3189
self.bzrdir = bzrdir
3192
class NoWhoami(BzrError):
3194
_fmt = ('Unable to determine your name.\n'
3195
"Please, set your name with the 'whoami' command.\n"
3196
'E.g. bzr whoami "Your Name <name@example.com>"')
3199
class InvalidPattern(BzrError):
3201
_fmt = ('Invalid pattern(s) found. %(msg)s')
3203
def __init__(self, msg):
3207
class RecursiveBind(BzrError):
3209
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3210
'Please use `bzr unbind` to fix.')
3212
def __init__(self, branch_url):
3213
self.branch_url = branch_url
3216
# FIXME: I would prefer to define the config related exception classes in
3217
# config.py but the lazy import mechanism proscribes this -- vila 20101222
3218
class OptionExpansionLoop(BzrError):
3220
_fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3222
def __init__(self, string, refs):
3223
self.string = string
3224
self.refs = '->'.join(refs)
3227
class ExpandingUnknownOption(BzrError):
3229
_fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
3231
def __init__(self, name, string):
3233
self.string = string
3236
class NoCompatibleInter(BzrError):
3238
_fmt = ('No compatible object available for operations from %(source)r '
3241
def __init__(self, source, target):
3242
self.source = source
3243
self.target = target
3246
class HpssVfsRequestNotAllowed(BzrError):
3248
_fmt = ("VFS requests over the smart server are not allowed. Encountered: "
3249
"%(method)s, %(arguments)s.")
3251
def __init__(self, method, arguments):
3252
self.method = method
3253
self.arguments = arguments
3256
class UnsupportedKindChange(BzrError):
3258
_fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
3259
"%(path)s not supported by format %(format)r")
3261
def __init__(self, path, from_kind, to_kind, format):
3263
self.from_kind = from_kind
3264
self.to_kind = to_kind
3265
self.format = format
3268
class MissingFeature(BzrError):
3270
_fmt = ("Missing feature %(feature)s not provided by this "
3271
"version of Bazaar or any plugin.")
3273
def __init__(self, feature):
3274
self.feature = feature
3277
class PatchSyntax(BzrError):
3278
"""Base class for patch syntax errors."""
3281
class BinaryFiles(BzrError):
3283
_fmt = 'Binary files section encountered.'
3285
def __init__(self, orig_name, mod_name):
3286
self.orig_name = orig_name
3287
self.mod_name = mod_name
3290
class MalformedPatchHeader(PatchSyntax):
3292
_fmt = "Malformed patch header. %(desc)s\n%(line)r"
3294
def __init__(self, desc, line):
3299
class MalformedHunkHeader(PatchSyntax):
3301
_fmt = "Malformed hunk header. %(desc)s\n%(line)r"
3303
def __init__(self, desc, line):
3308
class MalformedLine(PatchSyntax):
3310
_fmt = "Malformed line. %(desc)s\n%(line)r"
3312
def __init__(self, desc, line):
3317
class PatchConflict(BzrError):
3319
_fmt = ('Text contents mismatch at line %(line_no)d. Original has '
3320
'"%(orig_line)s", but patch says it should be "%(patch_line)s"')
3322
def __init__(self, line_no, orig_line, patch_line):
3323
self.line_no = line_no
3324
self.orig_line = orig_line.rstrip('\n')
3325
self.patch_line = patch_line.rstrip('\n')
3328
class FeatureAlreadyRegistered(BzrError):
3330
_fmt = 'The feature %(feature)s has already been registered.'
3332
def __init__(self, feature):
3333
self.feature = feature