707
609
# TODO: This is given a URL; we try to unescape it but doing that from inside
708
610
# the exception object is a bit undesirable.
709
# TODO: Probably this behavior of should be a common superclass
611
# TODO: Probably this behavior of should be a common superclass
710
612
class NotBranchError(PathError):
712
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
614
_fmt = 'Not a branch: "%(path)s".'
714
def __init__(self, path, detail=None, bzrdir=None):
616
def __init__(self, path):
715
617
import bzrlib.urlutils as urlutils
716
path = urlutils.unescape_for_display(path, 'ascii')
717
if detail is not None:
718
detail = ': ' + detail
721
PathError.__init__(self, path=path)
724
return '<%s %r>' % (self.__class__.__name__, self.__dict__)
727
# XXX: Ideally self.detail would be a property, but Exceptions in
728
# Python 2.4 have to be old-style classes so properties don't work.
729
# Instead we override _format.
730
if self.detail is None:
731
if self.bzrdir is not None:
733
self.bzrdir.open_repository()
734
except NoRepositoryPresent:
737
# Just ignore unexpected errors. Raising arbitrary errors
738
# during str(err) can provoke strange bugs. Concretely
739
# Launchpad's codehosting managed to raise NotBranchError
740
# here, and then get stuck in an infinite loop/recursion
741
# trying to str() that error. All this error really cares
742
# about that there's no working repository there, and if
743
# open_repository() fails, there probably isn't.
746
self.detail = ': location is a repository'
749
return PathError._format(self)
618
self.path = urlutils.unescape_for_display(path, 'ascii')
752
621
class NoSubmitBranch(PathError):
1777
1520
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1779
def __init__(self, source, target, is_permanent=False):
1522
def __init__(self, source, target, is_permanent=False, qual_proto=None):
1780
1523
self.source = source
1781
1524
self.target = target
1782
1525
if is_permanent:
1783
1526
self.permanently = ' permanently'
1785
1528
self.permanently = ''
1529
self._qualified_proto = qual_proto
1786
1530
TransportError.__init__(self)
1532
def _requalify_url(self, url):
1533
"""Restore the qualified proto in front of the url"""
1534
# When this exception is raised, source and target are in
1535
# user readable format. But some transports may use a
1536
# different proto (http+urllib:// will present http:// to
1537
# the user. If a qualified proto is specified, the code
1538
# trapping the exception can get the qualified urls to
1539
# properly handle the redirection themself (creating a
1540
# new transport object from the target url for example).
1541
# But checking that the scheme of the original and
1542
# redirected urls are the same can be tricky. (see the
1543
# FIXME in BzrDir.open_from_transport for the unique use
1545
if self._qualified_proto is None:
1548
# The TODO related to NotBranchError mention that doing
1549
# that kind of manipulation on the urls may not be the
1550
# exception object job. On the other hand, this object is
1551
# the interface between the code and the user so
1552
# presenting the urls in different ways is indeed its
1555
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1556
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1559
def get_source_url(self):
1560
return self._requalify_url(self.source)
1562
def get_target_url(self):
1563
return self._requalify_url(self.target)
1789
1566
class TooManyRedirections(TransportError):
3006
2582
self.timezone = timezone
3009
class CommandAvailableInPlugin(StandardError):
3011
internal_error = False
3013
def __init__(self, cmd_name, plugin_metadata, provider):
3015
self.plugin_metadata = plugin_metadata
3016
self.cmd_name = cmd_name
3017
self.provider = provider
3021
_fmt = ('"%s" is not a standard bzr command. \n'
3022
'However, the following official plugin provides this command: %s\n'
3023
'You can install it by going to: %s'
3024
% (self.cmd_name, self.plugin_metadata['name'],
3025
self.plugin_metadata['url']))
3030
class NoPluginAvailable(BzrError):
3034
2585
class UnableEncodePath(BzrError):
3036
2587
_fmt = ('Unable to encode %(kind)s path %(path)r in '
3037
2588
'user encoding %(user_encoding)s')
3039
2590
def __init__(self, path, kind):
3040
from bzrlib.osutils import get_user_encoding
3041
2591
self.path = path
3042
2592
self.kind = kind
3043
2593
self.user_encoding = osutils.get_user_encoding()
3046
class NoSuchConfig(BzrError):
3048
_fmt = ('The "%(config_id)s" configuration does not exist.')
3050
def __init__(self, config_id):
3051
BzrError.__init__(self, config_id=config_id)
3054
class NoSuchConfigOption(BzrError):
3056
_fmt = ('The "%(option_name)s" configuration option does not exist.')
3058
def __init__(self, option_name):
3059
BzrError.__init__(self, option_name=option_name)
3062
class NoSuchAlias(BzrError):
3064
_fmt = ('The alias "%(alias_name)s" does not exist.')
3066
def __init__(self, alias_name):
3067
BzrError.__init__(self, alias_name=alias_name)
3070
class DirectoryLookupFailure(BzrError):
3071
"""Base type for lookup errors."""
3076
class InvalidLocationAlias(DirectoryLookupFailure):
3078
_fmt = '"%(alias_name)s" is not a valid location alias.'
3080
def __init__(self, alias_name):
3081
DirectoryLookupFailure.__init__(self, alias_name=alias_name)
3084
class UnsetLocationAlias(DirectoryLookupFailure):
3086
_fmt = 'No %(alias_name)s location assigned.'
3088
def __init__(self, alias_name):
3089
DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
3092
class CannotBindAddress(BzrError):
3094
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
3096
def __init__(self, host, port, orig_error):
3097
# nb: in python2.4 socket.error doesn't have a useful repr
3098
BzrError.__init__(self, host=host, port=port,
3099
orig_error=repr(orig_error.args))
3102
class UnknownRules(BzrError):
3104
_fmt = ('Unknown rules detected: %(unknowns_str)s.')
3106
def __init__(self, unknowns):
3107
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
3110
class HookFailed(BzrError):
3111
"""Raised when a pre_change_branch_tip hook function fails anything other
3112
than TipChangeRejected.
3114
Note that this exception is no longer raised, and the import is only left
3115
to be nice to code which might catch it in a plugin.
3118
_fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
3119
"%(traceback_text)s%(exc_value)s")
3121
def __init__(self, hook_stage, hook_name, exc_info, warn=True):
3123
symbol_versioning.warn("BzrError HookFailed has been deprecated "
3124
"as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
3126
self.hook_stage = hook_stage
3127
self.hook_name = hook_name
3128
self.exc_info = exc_info
3129
self.exc_type = exc_info[0]
3130
self.exc_value = exc_info[1]
3131
self.exc_tb = exc_info[2]
3132
self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
3135
class TipChangeRejected(BzrError):
3136
"""A pre_change_branch_tip hook function may raise this to cleanly and
3137
explicitly abort a change to a branch tip.
3140
_fmt = u"Tip change rejected: %(msg)s"
3142
def __init__(self, msg):
3146
class ShelfCorrupt(BzrError):
3148
_fmt = "Shelf corrupt."
3151
class DecompressCorruption(BzrError):
3153
_fmt = "Corruption while decompressing repository file%(orig_error)s"
3155
def __init__(self, orig_error=None):
3156
if orig_error is not None:
3157
self.orig_error = ", %s" % (orig_error,)
3159
self.orig_error = ""
3160
BzrError.__init__(self)
3163
class NoSuchShelfId(BzrError):
3165
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
3167
def __init__(self, shelf_id):
3168
BzrError.__init__(self, shelf_id=shelf_id)
3171
class InvalidShelfId(BzrError):
3173
_fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3175
def __init__(self, invalid_id):
3176
BzrError.__init__(self, invalid_id=invalid_id)
3179
class JailBreak(BzrError):
3181
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3183
def __init__(self, url):
3184
BzrError.__init__(self, url=url)
3187
class UserAbort(BzrError):
3189
_fmt = 'The user aborted the operation.'
3192
class MustHaveWorkingTree(BzrError):
3194
_fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3196
def __init__(self, format, url):
3197
BzrError.__init__(self, format=format, url=url)
3200
class NoSuchView(BzrError):
3201
"""A view does not exist.
3204
_fmt = u"No such view: %(view_name)s."
3206
def __init__(self, view_name):
3207
self.view_name = view_name
3210
class ViewsNotSupported(BzrError):
3211
"""Views are not supported by a tree format.
3214
_fmt = ("Views are not supported by %(tree)s;"
3215
" use 'bzr upgrade' to change your tree to a later format.")
3217
def __init__(self, tree):
3221
class FileOutsideView(BzrError):
3223
_fmt = ('Specified file "%(file_name)s" is outside the current view: '
3226
def __init__(self, file_name, view_files):
3227
self.file_name = file_name
3228
self.view_str = ", ".join(view_files)
3231
class UnresumableWriteGroup(BzrError):
3233
_fmt = ("Repository %(repository)s cannot resume write group "
3234
"%(write_groups)r: %(reason)s")
3236
internal_error = True
3238
def __init__(self, repository, write_groups, reason):
3239
self.repository = repository
3240
self.write_groups = write_groups
3241
self.reason = reason
3244
class UnsuspendableWriteGroup(BzrError):
3246
_fmt = ("Repository %(repository)s cannot suspend a write group.")
3248
internal_error = True
3250
def __init__(self, repository):
3251
self.repository = repository
3254
class LossyPushToSameVCS(BzrError):
3256
_fmt = ("Lossy push not possible between %(source_branch)r and "
3257
"%(target_branch)r that are in the same VCS.")
3259
internal_error = True
3261
def __init__(self, source_branch, target_branch):
3262
self.source_branch = source_branch
3263
self.target_branch = target_branch
3266
class NoRoundtrippingSupport(BzrError):
3268
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
3269
"%(target_branch)r.")
3271
internal_error = True
3273
def __init__(self, source_branch, target_branch):
3274
self.source_branch = source_branch
3275
self.target_branch = target_branch
3278
class FileTimestampUnavailable(BzrError):
3280
_fmt = "The filestamp for %(path)s is not available."
3282
internal_error = True
3284
def __init__(self, path):
3288
class NoColocatedBranchSupport(BzrError):
3290
_fmt = ("%(bzrdir)r does not support co-located branches.")
3292
def __init__(self, bzrdir):
3293
self.bzrdir = bzrdir
3296
class NoWhoami(BzrError):
3298
_fmt = ('Unable to determine your name.\n'
3299
"Please, set your name with the 'whoami' command.\n"
3300
'E.g. bzr whoami "Your Name <name@example.com>"')
3303
class InvalidPattern(BzrError):
3305
_fmt = ('Invalid pattern(s) found. %(msg)s')
3307
def __init__(self, msg):
3311
class RecursiveBind(BzrError):
3313
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3314
'Please use `bzr unbind` to fix.')
3316
def __init__(self, branch_url):
3317
self.branch_url = branch_url
3320
# FIXME: I would prefer to define the config related exception classes in
3321
# config.py but the lazy import mechanism proscribes this -- vila 20101222
3322
class OptionExpansionLoop(BzrError):
3324
_fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3326
def __init__(self, string, refs):
3327
self.string = string
3328
self.refs = '->'.join(refs)
3331
class ExpandingUnknownOption(BzrError):
3333
_fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
3335
def __init__(self, name, string):
3337
self.string = string
3340
class NoCompatibleInter(BzrError):
3342
_fmt = ('No compatible object available for operations from %(source)r '
3345
def __init__(self, source, target):
3346
self.source = source
3347
self.target = target
3350
class HpssVfsRequestNotAllowed(BzrError):
3352
_fmt = ("VFS requests over the smart server are not allowed. Encountered: "
3353
"%(method)s, %(arguments)s.")
3355
def __init__(self, method, arguments):
3356
self.method = method
3357
self.arguments = arguments