700
594
# TODO: This is given a URL; we try to unescape it but doing that from inside
701
595
# the exception object is a bit undesirable.
702
# TODO: Probably this behavior of should be a common superclass
596
# TODO: Probably this behavior of should be a common superclass
703
597
class NotBranchError(PathError):
705
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
599
_fmt = 'Not a branch: "%(path)s".'
707
def __init__(self, path, detail=None, bzrdir=None):
601
def __init__(self, path):
708
602
import bzrlib.urlutils as urlutils
709
path = urlutils.unescape_for_display(path, 'ascii')
710
if detail is not None:
711
detail = ': ' + detail
714
PathError.__init__(self, path=path)
717
return '<%s %r>' % (self.__class__.__name__, self.__dict__)
720
# XXX: Ideally self.detail would be a property, but Exceptions in
721
# Python 2.4 have to be old-style classes so properties don't work.
722
# Instead we override _format.
723
if self.detail is None:
724
if self.bzrdir is not None:
726
self.bzrdir.open_repository()
727
except NoRepositoryPresent:
730
# Just ignore unexpected errors. Raising arbitrary errors
731
# during str(err) can provoke strange bugs. Concretely
732
# Launchpad's codehosting managed to raise NotBranchError
733
# here, and then get stuck in an infinite loop/recursion
734
# trying to str() that error. All this error really cares
735
# about that there's no working repository there, and if
736
# open_repository() fails, there probably isn't.
739
self.detail = ': location is a repository'
742
return PathError._format(self)
603
self.path = urlutils.unescape_for_display(path, 'ascii')
745
606
class NoSubmitBranch(PathError):
1538
1375
self.options = options
1541
class RetryWithNewPacks(BzrError):
1542
"""Raised when we realize that the packs on disk have changed.
1544
This is meant as more of a signaling exception, to trap between where a
1545
local error occurred and the code that can actually handle the error and
1546
code that can retry appropriately.
1549
internal_error = True
1551
_fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1554
def __init__(self, context, reload_occurred, exc_info):
1555
"""create a new RetryWithNewPacks error.
1557
:param reload_occurred: Set to True if we know that the packs have
1558
already been reloaded, and we are failing because of an in-memory
1559
cache miss. If set to True then we will ignore if a reload says
1560
nothing has changed, because we assume it has already reloaded. If
1561
False, then a reload with nothing changed will force an error.
1562
:param exc_info: The original exception traceback, so if there is a
1563
problem we can raise the original error (value from sys.exc_info())
1565
BzrError.__init__(self)
1566
self.reload_occurred = reload_occurred
1567
self.exc_info = exc_info
1568
self.orig_error = exc_info[1]
1569
# TODO: The global error handler should probably treat this by
1570
# raising/printing the original exception with a bit about
1571
# RetryWithNewPacks also not being caught
1574
class RetryAutopack(RetryWithNewPacks):
1575
"""Raised when we are autopacking and we find a missing file.
1577
Meant as a signaling exception, to tell the autopack code it should try
1581
internal_error = True
1583
_fmt = ("Pack files have changed, reload and try autopack again."
1584
" context: %(context)s %(orig_error)s")
1587
1378
class NoSuchExportFormat(BzrError):
1589
1380
_fmt = "Export format %(format)r not supported"
1591
1382
def __init__(self, format):
1736
1496
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1738
def __init__(self, source, target, is_permanent=False):
1498
def __init__(self, source, target, is_permanent=False, qual_proto=None):
1739
1499
self.source = source
1740
1500
self.target = target
1741
1501
if is_permanent:
1742
1502
self.permanently = ' permanently'
1744
1504
self.permanently = ''
1505
self._qualified_proto = qual_proto
1745
1506
TransportError.__init__(self)
1508
def _requalify_url(self, url):
1509
"""Restore the qualified proto in front of the url"""
1510
# When this exception is raised, source and target are in
1511
# user readable format. But some transports may use a
1512
# different proto (http+urllib:// will present http:// to
1513
# the user. If a qualified proto is specified, the code
1514
# trapping the exception can get the qualified urls to
1515
# properly handle the redirection themself (creating a
1516
# new transport object from the target url for example).
1517
# But checking that the scheme of the original and
1518
# redirected urls are the same can be tricky. (see the
1519
# FIXME in BzrDir.open_from_transport for the unique use
1521
if self._qualified_proto is None:
1524
# The TODO related to NotBranchError mention that doing
1525
# that kind of manipulation on the urls may not be the
1526
# exception object job. On the other hand, this object is
1527
# the interface between the code and the user so
1528
# presenting the urls in different ways is indeed its
1531
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1532
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1535
def get_source_url(self):
1536
return self._requalify_url(self.source)
1538
def get_target_url(self):
1539
return self._requalify_url(self.target)
1748
1542
class TooManyRedirections(TransportError):
2912
2502
path_str = repr(path)
2913
2503
path_str += ' '
2914
2504
self.path_str = path_str
2917
class UnsupportedTimezoneFormat(BzrError):
2919
_fmt = ('Unsupported timezone format "%(timezone)s", '
2920
'options are "utc", "original", "local".')
2922
def __init__(self, timezone):
2923
self.timezone = timezone
2926
class CommandAvailableInPlugin(StandardError):
2928
internal_error = False
2930
def __init__(self, cmd_name, plugin_metadata, provider):
2932
self.plugin_metadata = plugin_metadata
2933
self.cmd_name = cmd_name
2934
self.provider = provider
2938
_fmt = ('"%s" is not a standard bzr command. \n'
2939
'However, the following official plugin provides this command: %s\n'
2940
'You can install it by going to: %s'
2941
% (self.cmd_name, self.plugin_metadata['name'],
2942
self.plugin_metadata['url']))
2947
class NoPluginAvailable(BzrError):
2951
class UnableEncodePath(BzrError):
2953
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2954
'user encoding %(user_encoding)s')
2956
def __init__(self, path, kind):
2957
from bzrlib.osutils import get_user_encoding
2960
self.user_encoding = osutils.get_user_encoding()
2963
class NoSuchConfig(BzrError):
2965
_fmt = ('The "%(config_id)s" configuration does not exist.')
2967
def __init__(self, config_id):
2968
BzrError.__init__(self, config_id=config_id)
2971
class NoSuchConfigOption(BzrError):
2973
_fmt = ('The "%(option_name)s" configuration option does not exist.')
2975
def __init__(self, option_name):
2976
BzrError.__init__(self, option_name=option_name)
2979
class NoSuchAlias(BzrError):
2981
_fmt = ('The alias "%(alias_name)s" does not exist.')
2983
def __init__(self, alias_name):
2984
BzrError.__init__(self, alias_name=alias_name)
2987
class DirectoryLookupFailure(BzrError):
2988
"""Base type for lookup errors."""
2993
class InvalidLocationAlias(DirectoryLookupFailure):
2995
_fmt = '"%(alias_name)s" is not a valid location alias.'
2997
def __init__(self, alias_name):
2998
DirectoryLookupFailure.__init__(self, alias_name=alias_name)
3001
class UnsetLocationAlias(DirectoryLookupFailure):
3003
_fmt = 'No %(alias_name)s location assigned.'
3005
def __init__(self, alias_name):
3006
DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
3009
class CannotBindAddress(BzrError):
3011
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
3013
def __init__(self, host, port, orig_error):
3014
# nb: in python2.4 socket.error doesn't have a useful repr
3015
BzrError.__init__(self, host=host, port=port,
3016
orig_error=repr(orig_error.args))
3019
class UnknownRules(BzrError):
3021
_fmt = ('Unknown rules detected: %(unknowns_str)s.')
3023
def __init__(self, unknowns):
3024
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
3027
class HookFailed(BzrError):
3028
"""Raised when a pre_change_branch_tip hook function fails anything other
3029
than TipChangeRejected.
3031
Note that this exception is no longer raised, and the import is only left
3032
to be nice to code which might catch it in a plugin.
3035
_fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
3036
"%(traceback_text)s%(exc_value)s")
3038
def __init__(self, hook_stage, hook_name, exc_info, warn=True):
3040
symbol_versioning.warn("BzrError HookFailed has been deprecated "
3041
"as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
3043
self.hook_stage = hook_stage
3044
self.hook_name = hook_name
3045
self.exc_info = exc_info
3046
self.exc_type = exc_info[0]
3047
self.exc_value = exc_info[1]
3048
self.exc_tb = exc_info[2]
3049
self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
3052
class TipChangeRejected(BzrError):
3053
"""A pre_change_branch_tip hook function may raise this to cleanly and
3054
explicitly abort a change to a branch tip.
3057
_fmt = u"Tip change rejected: %(msg)s"
3059
def __init__(self, msg):
3063
class ShelfCorrupt(BzrError):
3065
_fmt = "Shelf corrupt."
3068
class NoSuchShelfId(BzrError):
3070
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
3072
def __init__(self, shelf_id):
3073
BzrError.__init__(self, shelf_id=shelf_id)
3076
class InvalidShelfId(BzrError):
3078
_fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3080
def __init__(self, invalid_id):
3081
BzrError.__init__(self, invalid_id=invalid_id)
3084
class JailBreak(BzrError):
3086
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3088
def __init__(self, url):
3089
BzrError.__init__(self, url=url)
3092
class UserAbort(BzrError):
3094
_fmt = 'The user aborted the operation.'
3097
class MustHaveWorkingTree(BzrError):
3099
_fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3101
def __init__(self, format, url):
3102
BzrError.__init__(self, format=format, url=url)
3105
class NoSuchView(BzrError):
3106
"""A view does not exist.
3109
_fmt = u"No such view: %(view_name)s."
3111
def __init__(self, view_name):
3112
self.view_name = view_name
3115
class ViewsNotSupported(BzrError):
3116
"""Views are not supported by a tree format.
3119
_fmt = ("Views are not supported by %(tree)s;"
3120
" use 'bzr upgrade' to change your tree to a later format.")
3122
def __init__(self, tree):
3126
class FileOutsideView(BzrError):
3128
_fmt = ('Specified file "%(file_name)s" is outside the current view: '
3131
def __init__(self, file_name, view_files):
3132
self.file_name = file_name
3133
self.view_str = ", ".join(view_files)
3136
class UnresumableWriteGroup(BzrError):
3138
_fmt = ("Repository %(repository)s cannot resume write group "
3139
"%(write_groups)r: %(reason)s")
3141
internal_error = True
3143
def __init__(self, repository, write_groups, reason):
3144
self.repository = repository
3145
self.write_groups = write_groups
3146
self.reason = reason
3149
class UnsuspendableWriteGroup(BzrError):
3151
_fmt = ("Repository %(repository)s cannot suspend a write group.")
3153
internal_error = True
3155
def __init__(self, repository):
3156
self.repository = repository
3159
class LossyPushToSameVCS(BzrError):
3161
_fmt = ("Lossy push not possible between %(source_branch)r and "
3162
"%(target_branch)r that are in the same VCS.")
3164
internal_error = True
3166
def __init__(self, source_branch, target_branch):
3167
self.source_branch = source_branch
3168
self.target_branch = target_branch
3171
class NoRoundtrippingSupport(BzrError):
3173
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
3174
"%(target_branch)r.")
3176
internal_error = True
3178
def __init__(self, source_branch, target_branch):
3179
self.source_branch = source_branch
3180
self.target_branch = target_branch
3183
class FileTimestampUnavailable(BzrError):
3185
_fmt = "The filestamp for %(path)s is not available."
3187
internal_error = True
3189
def __init__(self, path):
3193
class NoColocatedBranchSupport(BzrError):
3195
_fmt = ("%(bzrdir)r does not support co-located branches.")
3197
def __init__(self, bzrdir):
3198
self.bzrdir = bzrdir
3201
class NoWhoami(BzrError):
3203
_fmt = ('Unable to determine your name.\n'
3204
"Please, set your name with the 'whoami' command.\n"
3205
'E.g. bzr whoami "Your Name <name@example.com>"')
3208
class InvalidPattern(BzrError):
3210
_fmt = ('Invalid pattern(s) found. %(msg)s')
3212
def __init__(self, msg):
3216
class RecursiveBind(BzrError):
3218
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3219
'Please use `bzr unbind` to fix.')
3221
def __init__(self, branch_url):
3222
self.branch_url = branch_url