141
140
if type(fmt) == unicode:
142
141
trace.mutter("Unicode strings in error.fmt are deprecated")
143
142
return gettext(unicode_fmt)
144
fmt = getattr(self, '__doc__', None)
146
symbol_versioning.warn("%s uses its docstring as a format, "
147
"it should use _fmt instead" % self.__class__.__name__,
150
143
return 'Unprintable exception %s: dict=%r, fmt=%r' \
151
144
% (self.__class__.__name__,
170
163
internal_error = True
173
class BzrNewError(BzrError):
174
"""Deprecated error base class."""
175
# base classes should override the docstring with their human-
176
# readable explanation
178
def __init__(self, *args, **kwds):
179
# XXX: Use the underlying BzrError to always generate the args
180
# attribute if it doesn't exist. We can't use super here, because
181
# exceptions are old-style classes in python2.4 (but new in 2.5).
183
symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
184
'please convert %s to use BzrError instead'
185
% self.__class__.__name__,
188
BzrError.__init__(self, *args)
189
for key, value in kwds.items():
190
setattr(self, key, value)
194
# __str__() should always return a 'str' object
195
# never a 'unicode' object.
196
s = self.__doc__ % self.__dict__
197
if isinstance(s, unicode):
198
return s.encode('utf8')
200
except (TypeError, NameError, ValueError, KeyError), e:
201
return 'Unprintable exception %s(%r): %r' \
202
% (self.__class__.__name__,
206
166
class AlreadyBuilding(BzrError):
208
168
_fmt = "The tree builder is already building a tree."
790
750
self.path = bzrdir.transport.clone('..').base
793
class FileInWrongBranch(BzrError):
795
_fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
797
# use PathNotChild instead
798
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 3, 0)))
799
def __init__(self, branch, path):
800
BzrError.__init__(self)
802
self.branch_base = branch.base
806
753
class UnsupportedFormatError(BzrError):
808
755
_fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
1296
1243
not_ancestor_id=not_ancestor_id)
1299
class AmbiguousBase(BzrError):
1301
def __init__(self, bases):
1302
symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
1303
"as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
1304
msg = ("The correct base is unclear, because %s are all equally close"
1306
BzrError.__init__(self, msg)
1310
1246
class NoCommits(BranchError):
1312
1248
_fmt = "Branch %(branch)s has no commits."
2079
2015
BzrMoveFailedError.__init__(self, from_path, to_path, extra)
2082
class BzrRemoveChangedFilesError(BzrError):
2083
"""Used when user is trying to remove changed files."""
2085
_fmt = ("Can't safely remove modified or unknown files:\n"
2086
"%(changes_as_text)s"
2087
"Use --keep to not delete them, or --force to delete them regardless.")
2089
def __init__(self, tree_delta):
2090
symbol_versioning.warn(symbol_versioning.deprecated_in((2, 3, 0)) %
2091
"BzrRemoveChangedFilesError", DeprecationWarning, stacklevel=2)
2092
BzrError.__init__(self)
2093
self.changes_as_text = tree_delta.get_changes_as_text()
2094
#self.paths_as_string = '\n'.join(changed_files)
2095
#self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
2098
2018
class BzrBadParameterNotString(BzrBadParameter):
2100
2020
_fmt = "Parameter %(param)s is not a string or unicode string."
3101
3021
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
3104
class HookFailed(BzrError):
3105
"""Raised when a pre_change_branch_tip hook function fails anything other
3106
than TipChangeRejected.
3108
Note that this exception is no longer raised, and the import is only left
3109
to be nice to code which might catch it in a plugin.
3112
_fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
3113
"%(traceback_text)s%(exc_value)s")
3115
def __init__(self, hook_stage, hook_name, exc_info, warn=True):
3117
symbol_versioning.warn("BzrError HookFailed has been deprecated "
3118
"as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
3120
self.hook_stage = hook_stage
3121
self.hook_name = hook_name
3122
self.exc_info = exc_info
3123
self.exc_type = exc_info[0]
3124
self.exc_value = exc_info[1]
3125
self.exc_tb = exc_info[2]
3126
self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
3129
3024
class TipChangeRejected(BzrError):
3130
3025
"""A pre_change_branch_tip hook function may raise this to cleanly and
3131
3026
explicitly abort a change to a branch tip.