87
80
for key, value in kwds.items():
88
81
setattr(self, key, value)
91
84
s = getattr(self, '_preformatted_string', None)
93
# contains a preformatted message; must be cast to plain str
86
# contains a preformatted message
96
89
fmt = self._get_format_string()
98
s = fmt % self.__dict__
91
d = dict(self.__dict__)
99
93
# __str__() should always return a 'str' object
100
94
# 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),
97
pass # just bind to 'e' for formatting below
100
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
101
% (self.__class__.__name__,
103
getattr(self, '_fmt', None),
106
def __unicode__(self):
108
if isinstance(u, str):
109
# Try decoding the str using the default encoding.
111
elif not isinstance(u, unicode):
112
# Try to make a unicode object from it, because __unicode__ must
113
# return a unicode object.
119
if isinstance(s, unicode):
122
# __str__ must return a str.
127
return '%s(%s)' % (self.__class__.__name__, str(self))
111
129
def _get_format_string(self):
112
130
"""Return format string for this exception or None"""
113
131
fmt = getattr(self, '_fmt', None)
114
132
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__,
133
from bzrlib.i18n import gettext
134
return gettext(unicode(fmt)) # _fmt strings should be ascii
136
def __eq__(self, other):
137
if self.__class__ is not other.__class__:
138
return NotImplemented
139
return self.__dict__ == other.__dict__
142
class InternalBzrError(BzrError):
143
"""Base class for errors that are internal in nature.
145
This is a convenience class for errors that are internal. The
146
internal_error attribute can still be altered in subclasses, if needed.
147
Using this class is simply an easy way to get internal errors.
150
internal_error = True
162
153
class AlreadyBuilding(BzrError):
164
155
_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):
158
class BranchError(BzrError):
159
"""Base class for concrete 'errors about a branch'."""
161
def __init__(self, branch):
162
BzrError.__init__(self, branch=branch)
165
class BzrCheckError(InternalBzrError):
167
_fmt = "Internal check failed: %(msg)s"
169
def __init__(self, msg):
170
BzrError.__init__(self)
174
class DirstateCorrupt(BzrError):
176
_fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
178
def __init__(self, state, msg):
179
BzrError.__init__(self)
184
class DisabledMethod(InternalBzrError):
180
186
_fmt = "The smart server method '%(class_name)s' is disabled."
182
internal_error = True
184
188
def __init__(self, class_name):
185
189
BzrError.__init__(self)
186
190
self.class_name = class_name
1363
1689
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1365
def __init__(self, source, target, is_permament=False, qual_proto=None):
1691
def __init__(self, source, target, is_permanent=False):
1366
1692
self.source = source
1367
1693
self.target = target
1369
1695
self.permanently = ' permanently'
1371
1697
self.permanently = ''
1372
self.is_permament = is_permament
1373
self._qualified_proto = qual_proto
1374
1698
TransportError.__init__(self)
1376
def _requalify_url(self, url):
1377
"""Restore the qualified proto in front of the url"""
1378
# When this exception is raised, source and target are in
1379
# user readable format. But some transports may use a
1380
# different proto (http+urllib:// will present http:// to
1381
# the user. If a qualified proto is specified, the code
1382
# trapping the exception can get the qualified urls to
1383
# properly handle the redirection themself (creating a
1384
# new transport object from the target url for example).
1385
# But checking that the scheme of the original and
1386
# redirected urls are the same can be tricky. (see the
1387
# FIXME in BzrDir.open_from_transport for the unique use
1389
if self._qualified_proto is None:
1392
# The TODO related to NotBranchError mention that doing
1393
# that kind of manipulation on the urls may not be the
1394
# exception object job. On the other hand, this object is
1395
# the interface between the code and the user so
1396
# presenting the urls in different ways is indeed its
1399
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1400
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1403
def get_source_url(self):
1404
return self._requalify_url(self.source)
1406
def get_target_url(self):
1407
return self._requalify_url(self.target)
1410
1701
class TooManyRedirections(TransportError):
1412
1703
_fmt = "Too many redirections"
1414
1706
class ConflictsInTree(BzrError):
1416
1708
_fmt = "Working tree has conflicts."
1711
class ConfigContentError(BzrError):
1713
_fmt = "Config file %(filename)s is not UTF-8 encoded\n"
1715
def __init__(self, filename):
1716
BzrError.__init__(self)
1717
self.filename = filename
1419
1720
class ParseConfigError(BzrError):
1722
_fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
1421
1724
def __init__(self, errors, filename):
1422
if filename is None:
1424
message = "Error(s) parsing config file %s:\n%s" % \
1425
(filename, ('\n'.join(e.message for e in errors)))
1426
BzrError.__init__(self, message)
1725
BzrError.__init__(self)
1726
self.filename = filename
1727
self.errors = '\n'.join(e.msg for e in errors)
1730
class ConfigOptionValueError(BzrError):
1732
_fmt = """Bad value "%(value)s" for option "%(name)s"."""
1734
def __init__(self, name, value):
1735
BzrError.__init__(self, name=name, value=value)
1429
1738
class NoEmailInUsername(BzrError):
2150
2609
self.response_tuple = response_tuple
2153
class NoDestinationAddress(BzrError):
2612
class ErrorFromSmartServer(BzrError):
2613
"""An error was received from a smart server.
2615
:seealso: UnknownErrorFromSmartServer
2618
_fmt = "Error received from smart server: %(error_tuple)r"
2620
internal_error = True
2622
def __init__(self, error_tuple):
2623
self.error_tuple = error_tuple
2625
self.error_verb = error_tuple[0]
2627
self.error_verb = None
2628
self.error_args = error_tuple[1:]
2631
class UnknownErrorFromSmartServer(BzrError):
2632
"""An ErrorFromSmartServer could not be translated into a typical bzrlib
2635
This is distinct from ErrorFromSmartServer so that it is possible to
2636
distinguish between the following two cases:
2638
- ErrorFromSmartServer was uncaught. This is logic error in the client
2639
and so should provoke a traceback to the user.
2640
- ErrorFromSmartServer was caught but its error_tuple could not be
2641
translated. This is probably because the server sent us garbage, and
2642
should not provoke a traceback.
2645
_fmt = "Server sent an unexpected error: %(error_tuple)r"
2647
internal_error = False
2649
def __init__(self, error_from_smart_server):
2652
:param error_from_smart_server: An ErrorFromSmartServer instance.
2654
self.error_from_smart_server = error_from_smart_server
2655
self.error_tuple = error_from_smart_server.error_tuple
2658
class ContainerError(BzrError):
2659
"""Base class of container errors."""
2662
class UnknownContainerFormatError(ContainerError):
2664
_fmt = "Unrecognised container format: %(container_format)r"
2666
def __init__(self, container_format):
2667
self.container_format = container_format
2670
class UnexpectedEndOfContainerError(ContainerError):
2672
_fmt = "Unexpected end of container stream"
2675
class UnknownRecordTypeError(ContainerError):
2677
_fmt = "Unknown record type: %(record_type)r"
2679
def __init__(self, record_type):
2680
self.record_type = record_type
2683
class InvalidRecordError(ContainerError):
2685
_fmt = "Invalid record: %(reason)s"
2687
def __init__(self, reason):
2688
self.reason = reason
2691
class ContainerHasExcessDataError(ContainerError):
2693
_fmt = "Container has data after end marker: %(excess)r"
2695
def __init__(self, excess):
2696
self.excess = excess
2699
class DuplicateRecordNameError(ContainerError):
2701
_fmt = "Container has multiple records with the same name: %(name)s"
2703
def __init__(self, name):
2704
self.name = name.decode("utf-8")
2707
class NoDestinationAddress(InternalBzrError):
2155
2709
_fmt = "Message does not have a destination address."
2157
internal_error = True
2712
class RepositoryDataStreamError(BzrError):
2714
_fmt = "Corrupt or incompatible data stream: %(reason)s"
2716
def __init__(self, reason):
2717
self.reason = reason
2160
2720
class SMTPError(BzrError):
2164
2724
def __init__(self, error):
2165
2725
self.error = error
2728
class NoMessageSupplied(BzrError):
2730
_fmt = "No message supplied."
2733
class NoMailAddressSpecified(BzrError):
2735
_fmt = "No mail-to address (--mail-to) or output (-o) specified."
2738
class UnknownMailClient(BzrError):
2740
_fmt = "Unknown mail client: %(mail_client)s"
2742
def __init__(self, mail_client):
2743
BzrError.__init__(self, mail_client=mail_client)
2746
class MailClientNotFound(BzrError):
2748
_fmt = "Unable to find mail client with the following names:"\
2749
" %(mail_command_list_string)s"
2751
def __init__(self, mail_command_list):
2752
mail_command_list_string = ', '.join(mail_command_list)
2753
BzrError.__init__(self, mail_command_list=mail_command_list,
2754
mail_command_list_string=mail_command_list_string)
2756
class SMTPConnectionRefused(SMTPError):
2758
_fmt = "SMTP connection to %(host)s refused"
2760
def __init__(self, error, host):
2765
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2767
_fmt = "Please specify smtp_server. No server at default %(host)s."
2770
class BzrDirError(BzrError):
2772
def __init__(self, bzrdir):
2773
import bzrlib.urlutils as urlutils
2774
display_url = urlutils.unescape_for_display(bzrdir.user_url,
2776
BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2779
class UnsyncedBranches(BzrDirError):
2781
_fmt = ("'%(display_url)s' is not in sync with %(target_url)s. See"
2782
" bzr help sync-for-reconfigure.")
2784
def __init__(self, bzrdir, target_branch):
2785
BzrDirError.__init__(self, bzrdir)
2786
import bzrlib.urlutils as urlutils
2787
self.target_url = urlutils.unescape_for_display(target_branch.base,
2791
class AlreadyBranch(BzrDirError):
2793
_fmt = "'%(display_url)s' is already a branch."
2796
class AlreadyTree(BzrDirError):
2798
_fmt = "'%(display_url)s' is already a tree."
2801
class AlreadyCheckout(BzrDirError):
2803
_fmt = "'%(display_url)s' is already a checkout."
2806
class AlreadyLightweightCheckout(BzrDirError):
2808
_fmt = "'%(display_url)s' is already a lightweight checkout."
2811
class AlreadyUsingShared(BzrDirError):
2813
_fmt = "'%(display_url)s' is already using a shared repository."
2816
class AlreadyStandalone(BzrDirError):
2818
_fmt = "'%(display_url)s' is already standalone."
2821
class AlreadyWithTrees(BzrDirError):
2823
_fmt = ("Shared repository '%(display_url)s' already creates "
2827
class AlreadyWithNoTrees(BzrDirError):
2829
_fmt = ("Shared repository '%(display_url)s' already doesn't create "
2833
class ReconfigurationNotSupported(BzrDirError):
2835
_fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2838
class NoBindLocation(BzrDirError):
2840
_fmt = "No location could be found to bind to at %(display_url)s."
2843
class UncommittedChanges(BzrError):
2845
_fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2846
' (See bzr status).%(more)s')
2848
def __init__(self, tree, more=None):
2853
import bzrlib.urlutils as urlutils
2854
user_url = getattr(tree, "user_url", None)
2855
if user_url is None:
2856
display_url = str(tree)
2858
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2859
BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2862
class ShelvedChanges(UncommittedChanges):
2864
_fmt = ('Working tree "%(display_url)s" has shelved changes'
2865
' (See bzr shelve --list).%(more)s')
2868
class MissingTemplateVariable(BzrError):
2870
_fmt = 'Variable {%(name)s} is not available.'
2872
def __init__(self, name):
2876
class NoTemplate(BzrError):
2878
_fmt = 'No template specified.'
2881
class UnableCreateSymlink(BzrError):
2883
_fmt = 'Unable to create symlink %(path_str)son this platform'
2885
def __init__(self, path=None):
2889
path_str = repr(str(path))
2890
except UnicodeEncodeError:
2891
path_str = repr(path)
2893
self.path_str = path_str
2896
class UnsupportedTimezoneFormat(BzrError):
2898
_fmt = ('Unsupported timezone format "%(timezone)s", '
2899
'options are "utc", "original", "local".')
2901
def __init__(self, timezone):
2902
self.timezone = timezone
2905
class CommandAvailableInPlugin(StandardError):
2907
internal_error = False
2909
def __init__(self, cmd_name, plugin_metadata, provider):
2911
self.plugin_metadata = plugin_metadata
2912
self.cmd_name = cmd_name
2913
self.provider = provider
2917
_fmt = ('"%s" is not a standard bzr command. \n'
2918
'However, the following official plugin provides this command: %s\n'
2919
'You can install it by going to: %s'
2920
% (self.cmd_name, self.plugin_metadata['name'],
2921
self.plugin_metadata['url']))
2926
class NoPluginAvailable(BzrError):
2930
class UnableEncodePath(BzrError):
2932
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2933
'user encoding %(user_encoding)s')
2935
def __init__(self, path, kind):
2936
from bzrlib.osutils import get_user_encoding
2939
self.user_encoding = get_user_encoding()
2942
class NoSuchConfig(BzrError):
2944
_fmt = ('The "%(config_id)s" configuration does not exist.')
2946
def __init__(self, config_id):
2947
BzrError.__init__(self, config_id=config_id)
2950
class NoSuchConfigOption(BzrError):
2952
_fmt = ('The "%(option_name)s" configuration option does not exist.')
2954
def __init__(self, option_name):
2955
BzrError.__init__(self, option_name=option_name)
2958
class NoSuchAlias(BzrError):
2960
_fmt = ('The alias "%(alias_name)s" does not exist.')
2962
def __init__(self, alias_name):
2963
BzrError.__init__(self, alias_name=alias_name)
2966
class DirectoryLookupFailure(BzrError):
2967
"""Base type for lookup errors."""
2972
class InvalidLocationAlias(DirectoryLookupFailure):
2974
_fmt = '"%(alias_name)s" is not a valid location alias.'
2976
def __init__(self, alias_name):
2977
DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2980
class UnsetLocationAlias(DirectoryLookupFailure):
2982
_fmt = 'No %(alias_name)s location assigned.'
2984
def __init__(self, alias_name):
2985
DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2988
class CannotBindAddress(BzrError):
2990
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2992
def __init__(self, host, port, orig_error):
2993
# nb: in python2.4 socket.error doesn't have a useful repr
2994
BzrError.__init__(self, host=host, port=port,
2995
orig_error=repr(orig_error.args))
2998
class UnknownRules(BzrError):
3000
_fmt = ('Unknown rules detected: %(unknowns_str)s.')
3002
def __init__(self, unknowns):
3003
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
3006
class TipChangeRejected(BzrError):
3007
"""A pre_change_branch_tip hook function may raise this to cleanly and
3008
explicitly abort a change to a branch tip.
3011
_fmt = u"Tip change rejected: %(msg)s"
3013
def __init__(self, msg):
3017
class ShelfCorrupt(BzrError):
3019
_fmt = "Shelf corrupt."
3022
class DecompressCorruption(BzrError):
3024
_fmt = "Corruption while decompressing repository file%(orig_error)s"
3026
def __init__(self, orig_error=None):
3027
if orig_error is not None:
3028
self.orig_error = ", %s" % (orig_error,)
3030
self.orig_error = ""
3031
BzrError.__init__(self)
3034
class NoSuchShelfId(BzrError):
3036
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
3038
def __init__(self, shelf_id):
3039
BzrError.__init__(self, shelf_id=shelf_id)
3042
class InvalidShelfId(BzrError):
3044
_fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3046
def __init__(self, invalid_id):
3047
BzrError.__init__(self, invalid_id=invalid_id)
3050
class JailBreak(BzrError):
3052
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3054
def __init__(self, url):
3055
BzrError.__init__(self, url=url)
3058
class UserAbort(BzrError):
3060
_fmt = 'The user aborted the operation.'
3063
class MustHaveWorkingTree(BzrError):
3065
_fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3067
def __init__(self, format, url):
3068
BzrError.__init__(self, format=format, url=url)
3071
class NoSuchView(BzrError):
3072
"""A view does not exist.
3075
_fmt = u"No such view: %(view_name)s."
3077
def __init__(self, view_name):
3078
self.view_name = view_name
3081
class ViewsNotSupported(BzrError):
3082
"""Views are not supported by a tree format.
3085
_fmt = ("Views are not supported by %(tree)s;"
3086
" use 'bzr upgrade' to change your tree to a later format.")
3088
def __init__(self, tree):
3092
class FileOutsideView(BzrError):
3094
_fmt = ('Specified file "%(file_name)s" is outside the current view: '
3097
def __init__(self, file_name, view_files):
3098
self.file_name = file_name
3099
self.view_str = ", ".join(view_files)
3102
class UnresumableWriteGroup(BzrError):
3104
_fmt = ("Repository %(repository)s cannot resume write group "
3105
"%(write_groups)r: %(reason)s")
3107
internal_error = True
3109
def __init__(self, repository, write_groups, reason):
3110
self.repository = repository
3111
self.write_groups = write_groups
3112
self.reason = reason
3115
class UnsuspendableWriteGroup(BzrError):
3117
_fmt = ("Repository %(repository)s cannot suspend a write group.")
3119
internal_error = True
3121
def __init__(self, repository):
3122
self.repository = repository
3125
class LossyPushToSameVCS(BzrError):
3127
_fmt = ("Lossy push not possible between %(source_branch)r and "
3128
"%(target_branch)r that are in the same VCS.")
3130
internal_error = True
3132
def __init__(self, source_branch, target_branch):
3133
self.source_branch = source_branch
3134
self.target_branch = target_branch
3137
class NoRoundtrippingSupport(BzrError):
3139
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
3140
"%(target_branch)r.")
3142
internal_error = True
3144
def __init__(self, source_branch, target_branch):
3145
self.source_branch = source_branch
3146
self.target_branch = target_branch
3149
class FileTimestampUnavailable(BzrError):
3151
_fmt = "The filestamp for %(path)s is not available."
3153
internal_error = True
3155
def __init__(self, path):
3159
class NoColocatedBranchSupport(BzrError):
3161
_fmt = ("%(bzrdir)r does not support co-located branches.")
3163
def __init__(self, bzrdir):
3164
self.bzrdir = bzrdir
3167
class NoWhoami(BzrError):
3169
_fmt = ('Unable to determine your name.\n'
3170
"Please, set your name with the 'whoami' command.\n"
3171
'E.g. bzr whoami "Your Name <name@example.com>"')
3174
class InvalidPattern(BzrError):
3176
_fmt = ('Invalid pattern(s) found. %(msg)s')
3178
def __init__(self, msg):
3182
class RecursiveBind(BzrError):
3184
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3185
'Please use `bzr unbind` to fix.')
3187
def __init__(self, branch_url):
3188
self.branch_url = branch_url
3191
# FIXME: I would prefer to define the config related exception classes in
3192
# config.py but the lazy import mechanism proscribes this -- vila 20101222
3193
class OptionExpansionLoop(BzrError):
3195
_fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3197
def __init__(self, string, refs):
3198
self.string = string
3199
self.refs = '->'.join(refs)
3202
class ExpandingUnknownOption(BzrError):
3204
_fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
3206
def __init__(self, name, string):
3208
self.string = string
3211
class NoCompatibleInter(BzrError):
3213
_fmt = ('No compatible object available for operations from %(source)r '
3216
def __init__(self, source, target):
3217
self.source = source
3218
self.target = target
3221
class HpssVfsRequestNotAllowed(BzrError):
3223
_fmt = ("VFS requests over the smart server are not allowed. Encountered: "
3224
"%(method)s, %(arguments)s.")
3226
def __init__(self, method, arguments):
3227
self.method = method
3228
self.arguments = arguments
3231
class UnsupportedKindChange(BzrError):
3233
_fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
3234
"%(path)s not supported by format %(format)r")
3236
def __init__(self, path, from_kind, to_kind, format):
3238
self.from_kind = from_kind
3239
self.to_kind = to_kind
3240
self.format = format
3243
class PatchSyntax(BzrError):
3244
"""Base class for patch syntax errors."""
3247
class BinaryFiles(BzrError):
3249
_fmt = 'Binary files section encountered.'
3251
def __init__(self, orig_name, mod_name):
3252
self.orig_name = orig_name
3253
self.mod_name = mod_name
3256
class MalformedPatchHeader(PatchSyntax):
3258
_fmt = "Malformed patch header. %(desc)s\n%(line)r"
3260
def __init__(self, desc, line):
3265
class MalformedHunkHeader(PatchSyntax):
3267
_fmt = "Malformed hunk header. %(desc)s\n%(line)r"
3269
def __init__(self, desc, line):
3274
class MalformedLine(PatchSyntax):
3276
_fmt = "Malformed line. %(desc)s\n%(line)r"
3278
def __init__(self, desc, line):
3283
class PatchConflict(BzrError):
3285
_fmt = ('Text contents mismatch at line %(line_no)d. Original has '
3286
'"%(orig_line)s", but patch says it should be "%(patch_line)s"')
3288
def __init__(self, line_no, orig_line, patch_line):
3289
self.line_no = line_no
3290
self.orig_line = orig_line.rstrip('\n')
3291
self.patch_line = patch_line.rstrip('\n')