688
649
# TODO: This is given a URL; we try to unescape it but doing that from inside
689
650
# the exception object is a bit undesirable.
690
# TODO: Probably this behavior of should be a common superclass
651
# TODO: Probably this behavior of should be a common superclass
691
652
class NotBranchError(PathError):
693
_fmt = 'Not a branch: "%(path)s".'
654
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
695
def __init__(self, path):
656
def __init__(self, path, detail=None, bzrdir=None):
696
657
import bzrlib.urlutils as urlutils
697
self.path = urlutils.unescape_for_display(path, 'ascii')
658
path = urlutils.unescape_for_display(path, 'ascii')
659
if detail is not None:
660
detail = ': ' + detail
663
PathError.__init__(self, path=path)
666
return '<%s %r>' % (self.__class__.__name__, self.__dict__)
669
# XXX: Ideally self.detail would be a property, but Exceptions in
670
# Python 2.4 have to be old-style classes so properties don't work.
671
# Instead we override _format.
672
if self.detail is None:
673
if self.bzrdir is not None:
675
self.bzrdir.open_repository()
676
except NoRepositoryPresent:
679
# Just ignore unexpected errors. Raising arbitrary errors
680
# during str(err) can provoke strange bugs. Concretely
681
# Launchpad's codehosting managed to raise NotBranchError
682
# here, and then get stuck in an infinite loop/recursion
683
# trying to str() that error. All this error really cares
684
# about that there's no working repository there, and if
685
# open_repository() fails, there probably isn't.
688
self.detail = ': location is a repository'
691
return PathError._format(self)
700
694
class NoSubmitBranch(PathError):
1468
1484
self.options = options
1487
class RetryWithNewPacks(BzrError):
1488
"""Raised when we realize that the packs on disk have changed.
1490
This is meant as more of a signaling exception, to trap between where a
1491
local error occurred and the code that can actually handle the error and
1492
code that can retry appropriately.
1495
internal_error = True
1497
_fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1500
def __init__(self, context, reload_occurred, exc_info):
1501
"""create a new RetryWithNewPacks error.
1503
:param reload_occurred: Set to True if we know that the packs have
1504
already been reloaded, and we are failing because of an in-memory
1505
cache miss. If set to True then we will ignore if a reload says
1506
nothing has changed, because we assume it has already reloaded. If
1507
False, then a reload with nothing changed will force an error.
1508
:param exc_info: The original exception traceback, so if there is a
1509
problem we can raise the original error (value from sys.exc_info())
1511
BzrError.__init__(self)
1512
self.context = context
1513
self.reload_occurred = reload_occurred
1514
self.exc_info = exc_info
1515
self.orig_error = exc_info[1]
1516
# TODO: The global error handler should probably treat this by
1517
# raising/printing the original exception with a bit about
1518
# RetryWithNewPacks also not being caught
1521
class RetryAutopack(RetryWithNewPacks):
1522
"""Raised when we are autopacking and we find a missing file.
1524
Meant as a signaling exception, to tell the autopack code it should try
1528
internal_error = True
1530
_fmt = ("Pack files have changed, reload and try autopack again."
1531
" context: %(context)s %(orig_error)s")
1471
1534
class NoSuchExportFormat(BzrError):
1473
1536
_fmt = "Export format %(format)r not supported"
1475
1538
def __init__(self, format):
1612
1716
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1614
def __init__(self, source, target, is_permanent=False, qual_proto=None):
1718
def __init__(self, source, target, is_permanent=False):
1615
1719
self.source = source
1616
1720
self.target = target
1617
1721
if is_permanent:
1618
1722
self.permanently = ' permanently'
1620
1724
self.permanently = ''
1621
self._qualified_proto = qual_proto
1622
1725
TransportError.__init__(self)
1624
def _requalify_url(self, url):
1625
"""Restore the qualified proto in front of the url"""
1626
# When this exception is raised, source and target are in
1627
# user readable format. But some transports may use a
1628
# different proto (http+urllib:// will present http:// to
1629
# the user. If a qualified proto is specified, the code
1630
# trapping the exception can get the qualified urls to
1631
# properly handle the redirection themself (creating a
1632
# new transport object from the target url for example).
1633
# But checking that the scheme of the original and
1634
# redirected urls are the same can be tricky. (see the
1635
# FIXME in BzrDir.open_from_transport for the unique use
1637
if self._qualified_proto is None:
1640
# The TODO related to NotBranchError mention that doing
1641
# that kind of manipulation on the urls may not be the
1642
# exception object job. On the other hand, this object is
1643
# the interface between the code and the user so
1644
# presenting the urls in different ways is indeed its
1647
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1648
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1651
def get_source_url(self):
1652
return self._requalify_url(self.source)
1654
def get_target_url(self):
1655
return self._requalify_url(self.target)
1658
1728
class TooManyRedirections(TransportError):
2861
3030
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2864
class HookFailed(BzrError):
2865
"""Raised when a pre_change_branch_tip hook function fails anything other
2866
than TipChangeRejected.
2869
_fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2870
"%(traceback_text)s%(exc_value)s")
2872
def __init__(self, hook_stage, hook_name, exc_info):
2874
self.hook_stage = hook_stage
2875
self.hook_name = hook_name
2876
self.exc_info = exc_info
2877
self.exc_type = exc_info[0]
2878
self.exc_value = exc_info[1]
2879
self.exc_tb = exc_info[2]
2880
self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2883
3033
class TipChangeRejected(BzrError):
2884
3034
"""A pre_change_branch_tip hook function may raise this to cleanly and
2885
3035
explicitly abort a change to a branch tip.
2888
3038
_fmt = u"Tip change rejected: %(msg)s"
2890
3040
def __init__(self, msg):
3044
class ShelfCorrupt(BzrError):
3046
_fmt = "Shelf corrupt."
3049
class DecompressCorruption(BzrError):
3051
_fmt = "Corruption while decompressing repository file%(orig_error)s"
3053
def __init__(self, orig_error=None):
3054
if orig_error is not None:
3055
self.orig_error = ", %s" % (orig_error,)
3057
self.orig_error = ""
3058
BzrError.__init__(self)
3061
class NoSuchShelfId(BzrError):
3063
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
3065
def __init__(self, shelf_id):
3066
BzrError.__init__(self, shelf_id=shelf_id)
3069
class InvalidShelfId(BzrError):
3071
_fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3073
def __init__(self, invalid_id):
3074
BzrError.__init__(self, invalid_id=invalid_id)
3077
class JailBreak(BzrError):
3079
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3081
def __init__(self, url):
3082
BzrError.__init__(self, url=url)
3085
class UserAbort(BzrError):
3087
_fmt = 'The user aborted the operation.'
3090
class MustHaveWorkingTree(BzrError):
3092
_fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3094
def __init__(self, format, url):
3095
BzrError.__init__(self, format=format, url=url)
3098
class NoSuchView(BzrError):
3099
"""A view does not exist.
3102
_fmt = u"No such view: %(view_name)s."
3104
def __init__(self, view_name):
3105
self.view_name = view_name
3108
class ViewsNotSupported(BzrError):
3109
"""Views are not supported by a tree format.
3112
_fmt = ("Views are not supported by %(tree)s;"
3113
" use 'bzr upgrade' to change your tree to a later format.")
3115
def __init__(self, tree):
3119
class FileOutsideView(BzrError):
3121
_fmt = ('Specified file "%(file_name)s" is outside the current view: '
3124
def __init__(self, file_name, view_files):
3125
self.file_name = file_name
3126
self.view_str = ", ".join(view_files)
3129
class UnresumableWriteGroup(BzrError):
3131
_fmt = ("Repository %(repository)s cannot resume write group "
3132
"%(write_groups)r: %(reason)s")
3134
internal_error = True
3136
def __init__(self, repository, write_groups, reason):
3137
self.repository = repository
3138
self.write_groups = write_groups
3139
self.reason = reason
3142
class UnsuspendableWriteGroup(BzrError):
3144
_fmt = ("Repository %(repository)s cannot suspend a write group.")
3146
internal_error = True
3148
def __init__(self, repository):
3149
self.repository = repository
3152
class LossyPushToSameVCS(BzrError):
3154
_fmt = ("Lossy push not possible between %(source_branch)r and "
3155
"%(target_branch)r that are in the same VCS.")
3157
internal_error = True
3159
def __init__(self, source_branch, target_branch):
3160
self.source_branch = source_branch
3161
self.target_branch = target_branch
3164
class NoRoundtrippingSupport(BzrError):
3166
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
3167
"%(target_branch)r.")
3169
internal_error = True
3171
def __init__(self, source_branch, target_branch):
3172
self.source_branch = source_branch
3173
self.target_branch = target_branch
3176
class FileTimestampUnavailable(BzrError):
3178
_fmt = "The filestamp for %(path)s is not available."
3180
internal_error = True
3182
def __init__(self, path):
3186
class NoColocatedBranchSupport(BzrError):
3188
_fmt = ("%(bzrdir)r does not support co-located branches.")
3190
def __init__(self, bzrdir):
3191
self.bzrdir = bzrdir
3194
class NoWhoami(BzrError):
3196
_fmt = ('Unable to determine your name.\n'
3197
"Please, set your name with the 'whoami' command.\n"
3198
'E.g. bzr whoami "Your Name <name@example.com>"')
3201
class InvalidPattern(BzrError):
3203
_fmt = ('Invalid pattern(s) found. %(msg)s')
3205
def __init__(self, msg):
3209
class RecursiveBind(BzrError):
3211
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3212
'Please use `bzr unbind` to fix.')
3214
def __init__(self, branch_url):
3215
self.branch_url = branch_url
3218
# FIXME: I would prefer to define the config related exception classes in
3219
# config.py but the lazy import mechanism proscribes this -- vila 20101222
3220
class OptionExpansionLoop(BzrError):
3222
_fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3224
def __init__(self, string, refs):
3225
self.string = string
3226
self.refs = '->'.join(refs)
3229
class ExpandingUnknownOption(BzrError):
3231
_fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
3233
def __init__(self, name, string):
3235
self.string = string
3238
class NoCompatibleInter(BzrError):
3240
_fmt = ('No compatible object available for operations from %(source)r '
3243
def __init__(self, source, target):
3244
self.source = source
3245
self.target = target
3248
class HpssVfsRequestNotAllowed(BzrError):
3250
_fmt = ("VFS requests over the smart server are not allowed. Encountered: "
3251
"%(method)s, %(arguments)s.")
3253
def __init__(self, method, arguments):
3254
self.method = method
3255
self.arguments = arguments
3258
class UnsupportedKindChange(BzrError):
3260
_fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
3261
"%(path)s not supported by format %(format)r")
3263
def __init__(self, path, from_kind, to_kind, format):
3265
self.from_kind = from_kind
3266
self.to_kind = to_kind
3267
self.format = format
3270
class MissingFeature(BzrError):
3272
_fmt = ("Missing feature %(feature)s not provided by this "
3273
"version of Bazaar or any plugin.")
3275
def __init__(self, feature):
3276
self.feature = feature
3279
class PatchSyntax(BzrError):
3280
"""Base class for patch syntax errors."""
3283
class BinaryFiles(BzrError):
3285
_fmt = 'Binary files section encountered.'
3287
def __init__(self, orig_name, mod_name):
3288
self.orig_name = orig_name
3289
self.mod_name = mod_name
3292
class MalformedPatchHeader(PatchSyntax):
3294
_fmt = "Malformed patch header. %(desc)s\n%(line)r"
3296
def __init__(self, desc, line):
3301
class MalformedHunkHeader(PatchSyntax):
3303
_fmt = "Malformed hunk header. %(desc)s\n%(line)r"
3305
def __init__(self, desc, line):
3310
class MalformedLine(PatchSyntax):
3312
_fmt = "Malformed line. %(desc)s\n%(line)r"
3314
def __init__(self, desc, line):
3319
class PatchConflict(BzrError):
3321
_fmt = ('Text contents mismatch at line %(line_no)d. Original has '
3322
'"%(orig_line)s", but patch says it should be "%(patch_line)s"')
3324
def __init__(self, line_no, orig_line, patch_line):
3325
self.line_no = line_no
3326
self.orig_line = orig_line.rstrip('\n')
3327
self.patch_line = patch_line.rstrip('\n')
3330
class FeatureAlreadyRegistered(BzrError):
3332
_fmt = 'The feature %(feature)s has already been registered.'
3334
def __init__(self, feature):
3335
self.feature = feature