577
542
class InvalidURLJoin(PathError):
579
_fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
581
def __init__(self, reason, base, join_args):
584
self.join_args = join_args
585
PathError.__init__(self, base, reason)
588
class InvalidRebaseURLs(PathError):
590
_fmt = "URLs differ by more than path: %(from_)r and %(to)r"
592
def __init__(self, from_, to):
595
PathError.__init__(self, from_, 'URLs differ by more than path.')
598
class UnavailableRepresentation(InternalBzrError):
600
_fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
601
"is encoded as '%(native)s'.")
603
def __init__(self, key, wanted, native):
604
InternalBzrError.__init__(self)
544
_fmt = 'Invalid URL join request: "%(args)s"%(extra)s'
546
def __init__(self, msg, base, args):
547
PathError.__init__(self, base, msg)
548
self.args = [base] + list(args)
610
551
class UnknownHook(BzrError):
700
609
# TODO: This is given a URL; we try to unescape it but doing that from inside
701
610
# the exception object is a bit undesirable.
702
# TODO: Probably this behavior of should be a common superclass
611
# TODO: Probably this behavior of should be a common superclass
703
612
class NotBranchError(PathError):
705
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
614
_fmt = 'Not a branch: "%(path)s".'
707
def __init__(self, path, detail=None, bzrdir=None):
616
def __init__(self, path):
708
617
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
# XXX: Ideally self.detail would be a property, but Exceptions in
718
# Python 2.4 have to be old-style classes so properties don't work.
719
# Instead we override _format.
720
if self.detail is None:
721
if self.bzrdir is not None:
723
self.bzrdir.open_repository()
724
except NoRepositoryPresent:
727
self.detail = ': location is a repository'
730
return PathError._format(self)
618
self.path = urlutils.unescape_for_display(path, 'ascii')
733
621
class NoSubmitBranch(PathError):
1515
1396
self.options = options
1518
class RetryWithNewPacks(BzrError):
1519
"""Raised when we realize that the packs on disk have changed.
1521
This is meant as more of a signaling exception, to trap between where a
1522
local error occurred and the code that can actually handle the error and
1523
code that can retry appropriately.
1526
internal_error = True
1528
_fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1531
def __init__(self, context, reload_occurred, exc_info):
1532
"""create a new RetryWithNewPacks error.
1534
:param reload_occurred: Set to True if we know that the packs have
1535
already been reloaded, and we are failing because of an in-memory
1536
cache miss. If set to True then we will ignore if a reload says
1537
nothing has changed, because we assume it has already reloaded. If
1538
False, then a reload with nothing changed will force an error.
1539
:param exc_info: The original exception traceback, so if there is a
1540
problem we can raise the original error (value from sys.exc_info())
1542
BzrError.__init__(self)
1543
self.reload_occurred = reload_occurred
1544
self.exc_info = exc_info
1545
self.orig_error = exc_info[1]
1546
# TODO: The global error handler should probably treat this by
1547
# raising/printing the original exception with a bit about
1548
# RetryWithNewPacks also not being caught
1551
class RetryAutopack(RetryWithNewPacks):
1552
"""Raised when we are autopacking and we find a missing file.
1554
Meant as a signaling exception, to tell the autopack code it should try
1558
internal_error = True
1560
_fmt = ("Pack files have changed, reload and try autopack again."
1561
" context: %(context)s %(orig_error)s")
1564
1399
class NoSuchExportFormat(BzrError):
1566
1401
_fmt = "Export format %(format)r not supported"
1568
1403
def __init__(self, format):
1713
1516
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1715
def __init__(self, source, target, is_permanent=False):
1518
def __init__(self, source, target, is_permanent=False, qual_proto=None):
1716
1519
self.source = source
1717
1520
self.target = target
1718
1521
if is_permanent:
1719
1522
self.permanently = ' permanently'
1721
1524
self.permanently = ''
1525
self._qualified_proto = qual_proto
1722
1526
TransportError.__init__(self)
1528
def _requalify_url(self, url):
1529
"""Restore the qualified proto in front of the url"""
1530
# When this exception is raised, source and target are in
1531
# user readable format. But some transports may use a
1532
# different proto (http+urllib:// will present http:// to
1533
# the user. If a qualified proto is specified, the code
1534
# trapping the exception can get the qualified urls to
1535
# properly handle the redirection themself (creating a
1536
# new transport object from the target url for example).
1537
# But checking that the scheme of the original and
1538
# redirected urls are the same can be tricky. (see the
1539
# FIXME in BzrDir.open_from_transport for the unique use
1541
if self._qualified_proto is None:
1544
# The TODO related to NotBranchError mention that doing
1545
# that kind of manipulation on the urls may not be the
1546
# exception object job. On the other hand, this object is
1547
# the interface between the code and the user so
1548
# presenting the urls in different ways is indeed its
1551
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1552
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1555
def get_source_url(self):
1556
return self._requalify_url(self.source)
1558
def get_target_url(self):
1559
return self._requalify_url(self.target)
1725
1562
class TooManyRedirections(TransportError):
2592
2379
self.response_tuple = response_tuple
2595
class ErrorFromSmartServer(BzrError):
2596
"""An error was received from a smart server.
2598
:seealso: UnknownErrorFromSmartServer
2601
_fmt = "Error received from smart server: %(error_tuple)r"
2603
internal_error = True
2605
def __init__(self, error_tuple):
2606
self.error_tuple = error_tuple
2608
self.error_verb = error_tuple[0]
2610
self.error_verb = None
2611
self.error_args = error_tuple[1:]
2614
class UnknownErrorFromSmartServer(BzrError):
2615
"""An ErrorFromSmartServer could not be translated into a typical bzrlib
2618
This is distinct from ErrorFromSmartServer so that it is possible to
2619
distinguish between the following two cases:
2620
- ErrorFromSmartServer was uncaught. This is logic error in the client
2621
and so should provoke a traceback to the user.
2622
- ErrorFromSmartServer was caught but its error_tuple could not be
2623
translated. This is probably because the server sent us garbage, and
2624
should not provoke a traceback.
2627
_fmt = "Server sent an unexpected error: %(error_tuple)r"
2629
internal_error = False
2631
def __init__(self, error_from_smart_server):
2634
:param error_from_smart_server: An ErrorFromSmartServer instance.
2636
self.error_from_smart_server = error_from_smart_server
2637
self.error_tuple = error_from_smart_server.error_tuple
2640
2382
class ContainerError(BzrError):
2641
2383
"""Base class of container errors."""
2874
2577
def __init__(self, timezone):
2875
2578
self.timezone = timezone
2878
class CommandAvailableInPlugin(StandardError):
2880
internal_error = False
2882
def __init__(self, cmd_name, plugin_metadata, provider):
2884
self.plugin_metadata = plugin_metadata
2885
self.cmd_name = cmd_name
2886
self.provider = provider
2890
_fmt = ('"%s" is not a standard bzr command. \n'
2891
'However, the following official plugin provides this command: %s\n'
2892
'You can install it by going to: %s'
2893
% (self.cmd_name, self.plugin_metadata['name'],
2894
self.plugin_metadata['url']))
2899
class NoPluginAvailable(BzrError):
2903
class UnableEncodePath(BzrError):
2905
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2906
'user encoding %(user_encoding)s')
2908
def __init__(self, path, kind):
2909
from bzrlib.osutils import get_user_encoding
2912
self.user_encoding = osutils.get_user_encoding()
2915
class NoSuchAlias(BzrError):
2917
_fmt = ('The alias "%(alias_name)s" does not exist.')
2919
def __init__(self, alias_name):
2920
BzrError.__init__(self, alias_name=alias_name)
2923
class DirectoryLookupFailure(BzrError):
2924
"""Base type for lookup errors."""
2929
class InvalidLocationAlias(DirectoryLookupFailure):
2931
_fmt = '"%(alias_name)s" is not a valid location alias.'
2933
def __init__(self, alias_name):
2934
DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2937
class UnsetLocationAlias(DirectoryLookupFailure):
2939
_fmt = 'No %(alias_name)s location assigned.'
2941
def __init__(self, alias_name):
2942
DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2945
class CannotBindAddress(BzrError):
2947
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2949
def __init__(self, host, port, orig_error):
2950
# nb: in python2.4 socket.error doesn't have a useful repr
2951
BzrError.__init__(self, host=host, port=port,
2952
orig_error=repr(orig_error.args))
2955
class UnknownRules(BzrError):
2957
_fmt = ('Unknown rules detected: %(unknowns_str)s.')
2959
def __init__(self, unknowns):
2960
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2963
class HookFailed(BzrError):
2964
"""Raised when a pre_change_branch_tip hook function fails anything other
2965
than TipChangeRejected.
2967
Note that this exception is no longer raised, and the import is only left
2968
to be nice to code which might catch it in a plugin.
2971
_fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2972
"%(traceback_text)s%(exc_value)s")
2974
def __init__(self, hook_stage, hook_name, exc_info, warn=True):
2976
symbol_versioning.warn("BzrError HookFailed has been deprecated "
2977
"as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
2979
self.hook_stage = hook_stage
2980
self.hook_name = hook_name
2981
self.exc_info = exc_info
2982
self.exc_type = exc_info[0]
2983
self.exc_value = exc_info[1]
2984
self.exc_tb = exc_info[2]
2985
self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2988
class TipChangeRejected(BzrError):
2989
"""A pre_change_branch_tip hook function may raise this to cleanly and
2990
explicitly abort a change to a branch tip.
2993
_fmt = u"Tip change rejected: %(msg)s"
2995
def __init__(self, msg):
2999
class ShelfCorrupt(BzrError):
3001
_fmt = "Shelf corrupt."
3004
class NoSuchShelfId(BzrError):
3006
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
3008
def __init__(self, shelf_id):
3009
BzrError.__init__(self, shelf_id=shelf_id)
3012
class InvalidShelfId(BzrError):
3014
_fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3016
def __init__(self, invalid_id):
3017
BzrError.__init__(self, invalid_id=invalid_id)
3020
class JailBreak(BzrError):
3022
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3024
def __init__(self, url):
3025
BzrError.__init__(self, url=url)
3028
class UserAbort(BzrError):
3030
_fmt = 'The user aborted the operation.'
3033
class MustHaveWorkingTree(BzrError):
3035
_fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3037
def __init__(self, format, url):
3038
BzrError.__init__(self, format=format, url=url)
3041
class NoSuchView(BzrError):
3042
"""A view does not exist.
3045
_fmt = u"No such view: %(view_name)s."
3047
def __init__(self, view_name):
3048
self.view_name = view_name
3051
class ViewsNotSupported(BzrError):
3052
"""Views are not supported by a tree format.
3055
_fmt = ("Views are not supported by %(tree)s;"
3056
" use 'bzr upgrade' to change your tree to a later format.")
3058
def __init__(self, tree):
3062
class FileOutsideView(BzrError):
3064
_fmt = ('Specified file "%(file_name)s" is outside the current view: '
3067
def __init__(self, file_name, view_files):
3068
self.file_name = file_name
3069
self.view_str = ", ".join(view_files)
3072
class UnresumableWriteGroup(BzrError):
3074
_fmt = ("Repository %(repository)s cannot resume write group "
3075
"%(write_groups)r: %(reason)s")
3077
internal_error = True
3079
def __init__(self, repository, write_groups, reason):
3080
self.repository = repository
3081
self.write_groups = write_groups
3082
self.reason = reason
3085
class UnsuspendableWriteGroup(BzrError):
3087
_fmt = ("Repository %(repository)s cannot suspend a write group.")
3089
internal_error = True
3091
def __init__(self, repository):
3092
self.repository = repository
3095
class LossyPushToSameVCS(BzrError):
3097
_fmt = ("Lossy push not possible between %(source_branch)r and "
3098
"%(target_branch)r that are in the same VCS.")
3100
internal_error = True
3102
def __init__(self, source_branch, target_branch):
3103
self.source_branch = source_branch
3104
self.target_branch = target_branch
3107
class NoRoundtrippingSupport(BzrError):
3109
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
3110
"%(target_branch)r.")
3112
internal_error = True
3114
def __init__(self, source_branch, target_branch):
3115
self.source_branch = source_branch
3116
self.target_branch = target_branch
3119
class FileTimestampUnavailable(BzrError):
3121
_fmt = "The filestamp for %(path)s is not available."
3123
internal_error = True
3125
def __init__(self, path):