82
87
for key, value in kwds.items():
83
88
setattr(self, key, value)
86
91
s = getattr(self, '_preformatted_string', None)
88
# contains a preformatted message
93
# contains a preformatted message; must be cast to plain str
91
96
fmt = self._get_format_string()
93
d = dict(self.__dict__)
98
s = fmt % self.__dict__
95
99
# __str__() should always return a 'str' object
96
100
# never a 'unicode' object.
101
if isinstance(s, unicode):
102
return s.encode('utf8')
99
pass # just bind to 'e' for formatting below
102
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
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),
111
def _get_format_string(self):
112
"""Return format string for this exception or None"""
113
fmt = getattr(self, '_fmt', 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' \
103
123
% (self.__class__.__name__,
105
125
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.
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)
119
148
def __str__(self):
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
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
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__,
155
162
class AlreadyBuilding(BzrError):
157
164
_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
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):
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):
188
180
_fmt = "The smart server method '%(class_name)s' is disabled."
182
internal_error = True
190
184
def __init__(self, class_name):
191
185
BzrError.__init__(self)
192
186
self.class_name = class_name
1691
1433
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1693
def __init__(self, source, target, is_permanent=False):
1435
def __init__(self, source, target, is_permament=False, qual_proto=None):
1694
1436
self.source = source
1695
1437
self.target = target
1697
1439
self.permanently = ' permanently'
1699
1441
self.permanently = ''
1442
self.is_permament = is_permament
1443
self._qualified_proto = qual_proto
1700
1444
TransportError.__init__(self)
1446
def _requalify_url(self, url):
1447
"""Restore the qualified proto in front of the url"""
1448
# When this exception is raised, source and target are in
1449
# user readable format. But some transports may use a
1450
# different proto (http+urllib:// will present http:// to
1451
# the user. If a qualified proto is specified, the code
1452
# trapping the exception can get the qualified urls to
1453
# properly handle the redirection themself (creating a
1454
# new transport object from the target url for example).
1455
# But checking that the scheme of the original and
1456
# redirected urls are the same can be tricky. (see the
1457
# FIXME in BzrDir.open_from_transport for the unique use
1459
if self._qualified_proto is None:
1462
# The TODO related to NotBranchError mention that doing
1463
# that kind of manipulation on the urls may not be the
1464
# exception object job. On the other hand, this object is
1465
# the interface between the code and the user so
1466
# presenting the urls in different ways is indeed its
1469
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1470
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1473
def get_source_url(self):
1474
return self._requalify_url(self.source)
1476
def get_target_url(self):
1477
return self._requalify_url(self.target)
1703
1480
class TooManyRedirections(TransportError):
1705
1482
_fmt = "Too many redirections"
1708
1484
class ConflictsInTree(BzrError):
1710
1486
_fmt = "Working tree has conflicts."
1713
class ConfigContentError(BzrError):
1715
_fmt = "Config file %(filename)s is not UTF-8 encoded\n"
1717
def __init__(self, filename):
1718
BzrError.__init__(self)
1719
self.filename = filename
1722
1489
class ParseConfigError(BzrError):
1724
_fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
1726
1491
def __init__(self, errors, filename):
1727
BzrError.__init__(self)
1728
self.filename = filename
1729
self.errors = '\n'.join(e.msg for e in errors)
1732
class ConfigOptionValueError(BzrError):
1734
_fmt = """Bad value "%(value)s" for option "%(name)s"."""
1736
def __init__(self, name, value):
1737
BzrError.__init__(self, name=name, value=value)
1492
if filename is None:
1494
message = "Error(s) parsing config file %s:\n%s" % \
1495
(filename, ('\n'.join(e.message for e in errors)))
1496
BzrError.__init__(self, message)
1740
1499
class NoEmailInUsername(BzrError):
2726
2300
def __init__(self, error):
2727
2301
self.error = error
2730
class NoMessageSupplied(BzrError):
2732
_fmt = "No message supplied."
2735
class NoMailAddressSpecified(BzrError):
2737
_fmt = "No mail-to address (--mail-to) or output (-o) specified."
2740
class UnknownMailClient(BzrError):
2742
_fmt = "Unknown mail client: %(mail_client)s"
2744
def __init__(self, mail_client):
2745
BzrError.__init__(self, mail_client=mail_client)
2748
class MailClientNotFound(BzrError):
2750
_fmt = "Unable to find mail client with the following names:"\
2751
" %(mail_command_list_string)s"
2753
def __init__(self, mail_command_list):
2754
mail_command_list_string = ', '.join(mail_command_list)
2755
BzrError.__init__(self, mail_command_list=mail_command_list,
2756
mail_command_list_string=mail_command_list_string)
2758
class SMTPConnectionRefused(SMTPError):
2760
_fmt = "SMTP connection to %(host)s refused"
2762
def __init__(self, error, host):
2767
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2769
_fmt = "Please specify smtp_server. No server at default %(host)s."
2772
class BzrDirError(BzrError):
2774
def __init__(self, bzrdir):
2775
import bzrlib.urlutils as urlutils
2776
display_url = urlutils.unescape_for_display(bzrdir.user_url,
2778
BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2781
class UnsyncedBranches(BzrDirError):
2783
_fmt = ("'%(display_url)s' is not in sync with %(target_url)s. See"
2784
" bzr help sync-for-reconfigure.")
2786
def __init__(self, bzrdir, target_branch):
2787
BzrDirError.__init__(self, bzrdir)
2788
import bzrlib.urlutils as urlutils
2789
self.target_url = urlutils.unescape_for_display(target_branch.base,
2793
class AlreadyBranch(BzrDirError):
2795
_fmt = "'%(display_url)s' is already a branch."
2798
class AlreadyTree(BzrDirError):
2800
_fmt = "'%(display_url)s' is already a tree."
2803
class AlreadyCheckout(BzrDirError):
2805
_fmt = "'%(display_url)s' is already a checkout."
2808
class AlreadyLightweightCheckout(BzrDirError):
2810
_fmt = "'%(display_url)s' is already a lightweight checkout."
2813
class AlreadyUsingShared(BzrDirError):
2815
_fmt = "'%(display_url)s' is already using a shared repository."
2818
class AlreadyStandalone(BzrDirError):
2820
_fmt = "'%(display_url)s' is already standalone."
2823
class AlreadyWithTrees(BzrDirError):
2825
_fmt = ("Shared repository '%(display_url)s' already creates "
2829
class AlreadyWithNoTrees(BzrDirError):
2831
_fmt = ("Shared repository '%(display_url)s' already doesn't create "
2835
class ReconfigurationNotSupported(BzrDirError):
2837
_fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2840
class NoBindLocation(BzrDirError):
2842
_fmt = "No location could be found to bind to at %(display_url)s."
2845
class UncommittedChanges(BzrError):
2847
_fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2848
' (See bzr status).%(more)s')
2850
def __init__(self, tree, more=None):
2855
import bzrlib.urlutils as urlutils
2856
user_url = getattr(tree, "user_url", None)
2857
if user_url is None:
2858
display_url = str(tree)
2860
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2861
BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2864
class ShelvedChanges(UncommittedChanges):
2866
_fmt = ('Working tree "%(display_url)s" has shelved changes'
2867
' (See bzr shelve --list).%(more)s')
2870
class MissingTemplateVariable(BzrError):
2872
_fmt = 'Variable {%(name)s} is not available.'
2874
def __init__(self, name):
2878
class NoTemplate(BzrError):
2880
_fmt = 'No template specified.'
2883
class UnableCreateSymlink(BzrError):
2885
_fmt = 'Unable to create symlink %(path_str)son this platform'
2887
def __init__(self, path=None):
2891
path_str = repr(str(path))
2892
except UnicodeEncodeError:
2893
path_str = repr(path)
2895
self.path_str = path_str
2898
class UnsupportedTimezoneFormat(BzrError):
2900
_fmt = ('Unsupported timezone format "%(timezone)s", '
2901
'options are "utc", "original", "local".')
2903
def __init__(self, timezone):
2904
self.timezone = timezone
2907
class CommandAvailableInPlugin(StandardError):
2909
internal_error = False
2911
def __init__(self, cmd_name, plugin_metadata, provider):
2913
self.plugin_metadata = plugin_metadata
2914
self.cmd_name = cmd_name
2915
self.provider = provider
2919
_fmt = ('"%s" is not a standard bzr command. \n'
2920
'However, the following official plugin provides this command: %s\n'
2921
'You can install it by going to: %s'
2922
% (self.cmd_name, self.plugin_metadata['name'],
2923
self.plugin_metadata['url']))
2928
class NoPluginAvailable(BzrError):
2932
class UnableEncodePath(BzrError):
2934
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2935
'user encoding %(user_encoding)s')
2937
def __init__(self, path, kind):
2938
from bzrlib.osutils import get_user_encoding
2941
self.user_encoding = get_user_encoding()
2944
class NoSuchConfig(BzrError):
2946
_fmt = ('The "%(config_id)s" configuration does not exist.')
2948
def __init__(self, config_id):
2949
BzrError.__init__(self, config_id=config_id)
2952
class NoSuchConfigOption(BzrError):
2954
_fmt = ('The "%(option_name)s" configuration option does not exist.')
2956
def __init__(self, option_name):
2957
BzrError.__init__(self, option_name=option_name)
2960
class NoSuchAlias(BzrError):
2962
_fmt = ('The alias "%(alias_name)s" does not exist.')
2964
def __init__(self, alias_name):
2965
BzrError.__init__(self, alias_name=alias_name)
2968
class DirectoryLookupFailure(BzrError):
2969
"""Base type for lookup errors."""
2974
class InvalidLocationAlias(DirectoryLookupFailure):
2976
_fmt = '"%(alias_name)s" is not a valid location alias.'
2978
def __init__(self, alias_name):
2979
DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2982
class UnsetLocationAlias(DirectoryLookupFailure):
2984
_fmt = 'No %(alias_name)s location assigned.'
2986
def __init__(self, alias_name):
2987
DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2990
class CannotBindAddress(BzrError):
2992
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2994
def __init__(self, host, port, orig_error):
2995
# nb: in python2.4 socket.error doesn't have a useful repr
2996
BzrError.__init__(self, host=host, port=port,
2997
orig_error=repr(orig_error.args))
3000
class UnknownRules(BzrError):
3002
_fmt = ('Unknown rules detected: %(unknowns_str)s.')
3004
def __init__(self, unknowns):
3005
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
3008
class TipChangeRejected(BzrError):
3009
"""A pre_change_branch_tip hook function may raise this to cleanly and
3010
explicitly abort a change to a branch tip.
3013
_fmt = u"Tip change rejected: %(msg)s"
3015
def __init__(self, msg):
3019
class ShelfCorrupt(BzrError):
3021
_fmt = "Shelf corrupt."
3024
class DecompressCorruption(BzrError):
3026
_fmt = "Corruption while decompressing repository file%(orig_error)s"
3028
def __init__(self, orig_error=None):
3029
if orig_error is not None:
3030
self.orig_error = ", %s" % (orig_error,)
3032
self.orig_error = ""
3033
BzrError.__init__(self)
3036
class NoSuchShelfId(BzrError):
3038
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
3040
def __init__(self, shelf_id):
3041
BzrError.__init__(self, shelf_id=shelf_id)
3044
class InvalidShelfId(BzrError):
3046
_fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3048
def __init__(self, invalid_id):
3049
BzrError.__init__(self, invalid_id=invalid_id)
3052
class JailBreak(BzrError):
3054
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3056
def __init__(self, url):
3057
BzrError.__init__(self, url=url)
3060
class UserAbort(BzrError):
3062
_fmt = 'The user aborted the operation.'
3065
class MustHaveWorkingTree(BzrError):
3067
_fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3069
def __init__(self, format, url):
3070
BzrError.__init__(self, format=format, url=url)
3073
class NoSuchView(BzrError):
3074
"""A view does not exist.
3077
_fmt = u"No such view: %(view_name)s."
3079
def __init__(self, view_name):
3080
self.view_name = view_name
3083
class ViewsNotSupported(BzrError):
3084
"""Views are not supported by a tree format.
3087
_fmt = ("Views are not supported by %(tree)s;"
3088
" use 'bzr upgrade' to change your tree to a later format.")
3090
def __init__(self, tree):
3094
class FileOutsideView(BzrError):
3096
_fmt = ('Specified file "%(file_name)s" is outside the current view: '
3099
def __init__(self, file_name, view_files):
3100
self.file_name = file_name
3101
self.view_str = ", ".join(view_files)
3104
class UnresumableWriteGroup(BzrError):
3106
_fmt = ("Repository %(repository)s cannot resume write group "
3107
"%(write_groups)r: %(reason)s")
3109
internal_error = True
3111
def __init__(self, repository, write_groups, reason):
3112
self.repository = repository
3113
self.write_groups = write_groups
3114
self.reason = reason
3117
class UnsuspendableWriteGroup(BzrError):
3119
_fmt = ("Repository %(repository)s cannot suspend a write group.")
3121
internal_error = True
3123
def __init__(self, repository):
3124
self.repository = repository
3127
class LossyPushToSameVCS(BzrError):
3129
_fmt = ("Lossy push not possible between %(source_branch)r and "
3130
"%(target_branch)r that are in the same VCS.")
3132
internal_error = True
3134
def __init__(self, source_branch, target_branch):
3135
self.source_branch = source_branch
3136
self.target_branch = target_branch
3139
class NoRoundtrippingSupport(BzrError):
3141
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
3142
"%(target_branch)r.")
3144
internal_error = True
3146
def __init__(self, source_branch, target_branch):
3147
self.source_branch = source_branch
3148
self.target_branch = target_branch
3151
class FileTimestampUnavailable(BzrError):
3153
_fmt = "The filestamp for %(path)s is not available."
3155
internal_error = True
3157
def __init__(self, path):
3161
class NoColocatedBranchSupport(BzrError):
3163
_fmt = ("%(bzrdir)r does not support co-located branches.")
3165
def __init__(self, bzrdir):
3166
self.bzrdir = bzrdir
3169
class NoWhoami(BzrError):
3171
_fmt = ('Unable to determine your name.\n'
3172
"Please, set your name with the 'whoami' command.\n"
3173
'E.g. bzr whoami "Your Name <name@example.com>"')
3176
class InvalidPattern(BzrError):
3178
_fmt = ('Invalid pattern(s) found. %(msg)s')
3180
def __init__(self, msg):
3184
class RecursiveBind(BzrError):
3186
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3187
'Please use `bzr unbind` to fix.')
3189
def __init__(self, branch_url):
3190
self.branch_url = branch_url
3193
# FIXME: I would prefer to define the config related exception classes in
3194
# config.py but the lazy import mechanism proscribes this -- vila 20101222
3195
class OptionExpansionLoop(BzrError):
3197
_fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3199
def __init__(self, string, refs):
3200
self.string = string
3201
self.refs = '->'.join(refs)
3204
class ExpandingUnknownOption(BzrError):
3206
_fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
3208
def __init__(self, name, string):
3210
self.string = string
3213
class NoCompatibleInter(BzrError):
3215
_fmt = ('No compatible object available for operations from %(source)r '
3218
def __init__(self, source, target):
3219
self.source = source
3220
self.target = target
3223
class HpssVfsRequestNotAllowed(BzrError):
3225
_fmt = ("VFS requests over the smart server are not allowed. Encountered: "
3226
"%(method)s, %(arguments)s.")
3228
def __init__(self, method, arguments):
3229
self.method = method
3230
self.arguments = arguments
3233
class UnsupportedKindChange(BzrError):
3235
_fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
3236
"%(path)s not supported by format %(format)r")
3238
def __init__(self, path, from_kind, to_kind, format):
3240
self.from_kind = from_kind
3241
self.to_kind = to_kind
3242
self.format = format
3245
class PatchSyntax(BzrError):
3246
"""Base class for patch syntax errors."""
3249
class BinaryFiles(BzrError):
3251
_fmt = 'Binary files section encountered.'
3253
def __init__(self, orig_name, mod_name):
3254
self.orig_name = orig_name
3255
self.mod_name = mod_name
3258
class MalformedPatchHeader(PatchSyntax):
3260
_fmt = "Malformed patch header. %(desc)s\n%(line)r"
3262
def __init__(self, desc, line):
3267
class MalformedHunkHeader(PatchSyntax):
3269
_fmt = "Malformed hunk header. %(desc)s\n%(line)r"
3271
def __init__(self, desc, line):
3276
class MalformedLine(PatchSyntax):
3278
_fmt = "Malformed line. %(desc)s\n%(line)r"
3280
def __init__(self, desc, line):
3285
class PatchConflict(BzrError):
3287
_fmt = ('Text contents mismatch at line %(line_no)d. Original has '
3288
'"%(orig_line)s", but patch says it should be "%(patch_line)s"')
3290
def __init__(self, line_no, orig_line, patch_line):
3291
self.line_no = line_no
3292
self.orig_line = orig_line.rstrip('\n')
3293
self.patch_line = patch_line.rstrip('\n')