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
189
class InvalidEntryName(BzrError):
195
class IncompatibleAPI(BzrError):
197
_fmt = 'The API for "%(api)s" is not compatible with "%(wanted)s". '\
198
'It supports versions "%(minimum)s" to "%(current)s".'
200
def __init__(self, api, wanted, minimum, current):
203
self.minimum = minimum
204
self.current = current
207
class InProcessTransport(BzrError):
209
_fmt = "The transport '%(transport)s' is only accessible within this " \
212
def __init__(self, transport):
213
self.transport = transport
216
class InvalidEntryName(InternalBzrError):
191
218
_fmt = "Invalid entry name: %(name)s"
193
internal_error = True
195
220
def __init__(self, name):
196
221
BzrError.__init__(self)
200
225
class InvalidRevisionNumber(BzrError):
202
227
_fmt = "Invalid revision number %(revno)s"
204
229
def __init__(self, revno):
2128
2619
self.branch = branch
2622
class InvalidLineInBugsProperty(BzrError):
2624
_fmt = ("Invalid line in bugs property: '%(line)s'")
2626
def __init__(self, line):
2630
class InvalidBugStatus(BzrError):
2632
_fmt = ("Invalid bug status: '%(status)s'")
2634
def __init__(self, status):
2635
self.status = status
2131
2638
class UnexpectedSmartServerResponse(BzrError):
2133
2640
_fmt = "Could not understand response from smart server: %(response_tuple)r"
2135
2642
def __init__(self, response_tuple):
2136
2643
self.response_tuple = response_tuple
2646
class ErrorFromSmartServer(BzrError):
2647
"""An error was received from a smart server.
2649
:seealso: UnknownErrorFromSmartServer
2652
_fmt = "Error received from smart server: %(error_tuple)r"
2654
internal_error = True
2656
def __init__(self, error_tuple):
2657
self.error_tuple = error_tuple
2659
self.error_verb = error_tuple[0]
2661
self.error_verb = None
2662
self.error_args = error_tuple[1:]
2665
class UnknownErrorFromSmartServer(BzrError):
2666
"""An ErrorFromSmartServer could not be translated into a typical bzrlib
2669
This is distinct from ErrorFromSmartServer so that it is possible to
2670
distinguish between the following two cases:
2672
- ErrorFromSmartServer was uncaught. This is logic error in the client
2673
and so should provoke a traceback to the user.
2674
- ErrorFromSmartServer was caught but its error_tuple could not be
2675
translated. This is probably because the server sent us garbage, and
2676
should not provoke a traceback.
2679
_fmt = "Server sent an unexpected error: %(error_tuple)r"
2681
internal_error = False
2683
def __init__(self, error_from_smart_server):
2686
:param error_from_smart_server: An ErrorFromSmartServer instance.
2688
self.error_from_smart_server = error_from_smart_server
2689
self.error_tuple = error_from_smart_server.error_tuple
2692
class ContainerError(BzrError):
2693
"""Base class of container errors."""
2696
class UnknownContainerFormatError(ContainerError):
2698
_fmt = "Unrecognised container format: %(container_format)r"
2700
def __init__(self, container_format):
2701
self.container_format = container_format
2704
class UnexpectedEndOfContainerError(ContainerError):
2706
_fmt = "Unexpected end of container stream"
2709
class UnknownRecordTypeError(ContainerError):
2711
_fmt = "Unknown record type: %(record_type)r"
2713
def __init__(self, record_type):
2714
self.record_type = record_type
2717
class InvalidRecordError(ContainerError):
2719
_fmt = "Invalid record: %(reason)s"
2721
def __init__(self, reason):
2722
self.reason = reason
2725
class ContainerHasExcessDataError(ContainerError):
2727
_fmt = "Container has data after end marker: %(excess)r"
2729
def __init__(self, excess):
2730
self.excess = excess
2733
class DuplicateRecordNameError(ContainerError):
2735
_fmt = "Container has multiple records with the same name: %(name)s"
2737
def __init__(self, name):
2738
self.name = name.decode("utf-8")
2741
class NoDestinationAddress(InternalBzrError):
2743
_fmt = "Message does not have a destination address."
2746
class RepositoryDataStreamError(BzrError):
2748
_fmt = "Corrupt or incompatible data stream: %(reason)s"
2750
def __init__(self, reason):
2751
self.reason = reason
2754
class SMTPError(BzrError):
2756
_fmt = "SMTP error: %(error)s"
2758
def __init__(self, error):
2762
class NoMessageSupplied(BzrError):
2764
_fmt = "No message supplied."
2767
class NoMailAddressSpecified(BzrError):
2769
_fmt = "No mail-to address (--mail-to) or output (-o) specified."
2772
class MailClientNotFound(BzrError):
2774
_fmt = "Unable to find mail client with the following names:"\
2775
" %(mail_command_list_string)s"
2777
def __init__(self, mail_command_list):
2778
mail_command_list_string = ', '.join(mail_command_list)
2779
BzrError.__init__(self, mail_command_list=mail_command_list,
2780
mail_command_list_string=mail_command_list_string)
2782
class SMTPConnectionRefused(SMTPError):
2784
_fmt = "SMTP connection to %(host)s refused"
2786
def __init__(self, error, host):
2791
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2793
_fmt = "Please specify smtp_server. No server at default %(host)s."
2796
class BzrDirError(BzrError):
2798
def __init__(self, bzrdir):
2799
import bzrlib.urlutils as urlutils
2800
display_url = urlutils.unescape_for_display(bzrdir.user_url,
2802
BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2805
class UnsyncedBranches(BzrDirError):
2807
_fmt = ("'%(display_url)s' is not in sync with %(target_url)s. See"
2808
" bzr help sync-for-reconfigure.")
2810
def __init__(self, bzrdir, target_branch):
2811
BzrDirError.__init__(self, bzrdir)
2812
import bzrlib.urlutils as urlutils
2813
self.target_url = urlutils.unescape_for_display(target_branch.base,
2817
class AlreadyBranch(BzrDirError):
2819
_fmt = "'%(display_url)s' is already a branch."
2822
class AlreadyTree(BzrDirError):
2824
_fmt = "'%(display_url)s' is already a tree."
2827
class AlreadyCheckout(BzrDirError):
2829
_fmt = "'%(display_url)s' is already a checkout."
2832
class AlreadyLightweightCheckout(BzrDirError):
2834
_fmt = "'%(display_url)s' is already a lightweight checkout."
2837
class AlreadyUsingShared(BzrDirError):
2839
_fmt = "'%(display_url)s' is already using a shared repository."
2842
class AlreadyStandalone(BzrDirError):
2844
_fmt = "'%(display_url)s' is already standalone."
2847
class AlreadyWithTrees(BzrDirError):
2849
_fmt = ("Shared repository '%(display_url)s' already creates "
2853
class AlreadyWithNoTrees(BzrDirError):
2855
_fmt = ("Shared repository '%(display_url)s' already doesn't create "
2859
class ReconfigurationNotSupported(BzrDirError):
2861
_fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2864
class NoBindLocation(BzrDirError):
2866
_fmt = "No location could be found to bind to at %(display_url)s."
2869
class UncommittedChanges(BzrError):
2871
_fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2872
' (See bzr status).%(more)s')
2874
def __init__(self, tree, more=None):
2879
import bzrlib.urlutils as urlutils
2880
user_url = getattr(tree, "user_url", None)
2881
if user_url is None:
2882
display_url = str(tree)
2884
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2885
BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2888
class StoringUncommittedNotSupported(BzrError):
2890
_fmt = ('Branch "%(display_url)s" does not support storing uncommitted'
2893
def __init__(self, branch):
2894
import bzrlib.urlutils as urlutils
2895
user_url = getattr(branch, "user_url", None)
2896
if user_url is None:
2897
display_url = str(branch)
2899
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2900
BzrError.__init__(self, branch=branch, display_url=display_url)
2903
class ShelvedChanges(UncommittedChanges):
2905
_fmt = ('Working tree "%(display_url)s" has shelved changes'
2906
' (See bzr shelve --list).%(more)s')
2909
class MissingTemplateVariable(BzrError):
2911
_fmt = 'Variable {%(name)s} is not available.'
2913
def __init__(self, name):
2917
class NoTemplate(BzrError):
2919
_fmt = 'No template specified.'
2922
class UnableCreateSymlink(BzrError):
2924
_fmt = 'Unable to create symlink %(path_str)son this platform'
2926
def __init__(self, path=None):
2930
path_str = repr(str(path))
2931
except UnicodeEncodeError:
2932
path_str = repr(path)
2934
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.')