690
649
# TODO: This is given a URL; we try to unescape it but doing that from inside
691
650
# the exception object is a bit undesirable.
692
# TODO: Probably this behavior of should be a common superclass
651
# TODO: Probably this behavior of should be a common superclass
693
652
class NotBranchError(PathError):
695
_fmt = 'Not a branch: "%(path)s".'
654
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
697
def __init__(self, path):
656
def __init__(self, path, detail=None, bzrdir=None):
698
657
import bzrlib.urlutils as urlutils
699
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)
702
694
class NoSubmitBranch(PathError):
1470
1498
self.options = options
1501
class RetryWithNewPacks(BzrError):
1502
"""Raised when we realize that the packs on disk have changed.
1504
This is meant as more of a signaling exception, to trap between where a
1505
local error occurred and the code that can actually handle the error and
1506
code that can retry appropriately.
1509
internal_error = True
1511
_fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1514
def __init__(self, context, reload_occurred, exc_info):
1515
"""create a new RetryWithNewPacks error.
1517
:param reload_occurred: Set to True if we know that the packs have
1518
already been reloaded, and we are failing because of an in-memory
1519
cache miss. If set to True then we will ignore if a reload says
1520
nothing has changed, because we assume it has already reloaded. If
1521
False, then a reload with nothing changed will force an error.
1522
:param exc_info: The original exception traceback, so if there is a
1523
problem we can raise the original error (value from sys.exc_info())
1525
BzrError.__init__(self)
1526
self.context = context
1527
self.reload_occurred = reload_occurred
1528
self.exc_info = exc_info
1529
self.orig_error = exc_info[1]
1530
# TODO: The global error handler should probably treat this by
1531
# raising/printing the original exception with a bit about
1532
# RetryWithNewPacks also not being caught
1535
class RetryAutopack(RetryWithNewPacks):
1536
"""Raised when we are autopacking and we find a missing file.
1538
Meant as a signaling exception, to tell the autopack code it should try
1542
internal_error = True
1544
_fmt = ("Pack files have changed, reload and try autopack again."
1545
" context: %(context)s %(orig_error)s")
1473
1548
class NoSuchExportFormat(BzrError):
1475
1550
_fmt = "Export format %(format)r not supported"
1477
1552
def __init__(self, format):
1614
1730
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1616
def __init__(self, source, target, is_permanent=False, qual_proto=None):
1732
def __init__(self, source, target, is_permanent=False):
1617
1733
self.source = source
1618
1734
self.target = target
1619
1735
if is_permanent:
1620
1736
self.permanently = ' permanently'
1622
1738
self.permanently = ''
1623
self._qualified_proto = qual_proto
1624
1739
TransportError.__init__(self)
1626
def _requalify_url(self, url):
1627
"""Restore the qualified proto in front of the url"""
1628
# When this exception is raised, source and target are in
1629
# user readable format. But some transports may use a
1630
# different proto (http+urllib:// will present http:// to
1631
# the user. If a qualified proto is specified, the code
1632
# trapping the exception can get the qualified urls to
1633
# properly handle the redirection themself (creating a
1634
# new transport object from the target url for example).
1635
# But checking that the scheme of the original and
1636
# redirected urls are the same can be tricky. (see the
1637
# FIXME in BzrDir.open_from_transport for the unique use
1639
if self._qualified_proto is None:
1642
# The TODO related to NotBranchError mention that doing
1643
# that kind of manipulation on the urls may not be the
1644
# exception object job. On the other hand, this object is
1645
# the interface between the code and the user so
1646
# presenting the urls in different ways is indeed its
1649
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1650
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1653
def get_source_url(self):
1654
return self._requalify_url(self.source)
1656
def get_target_url(self):
1657
return self._requalify_url(self.target)
1660
1742
class TooManyRedirections(TransportError):
2698
2877
class UncommittedChanges(BzrError):
2700
_fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2702
def __init__(self, tree):
2703
import bzrlib.urlutils as urlutils
2704
display_url = urlutils.unescape_for_display(
2705
tree.bzrdir.root_transport.base, 'ascii')
2706
BzrError.__init__(self, tree=tree, display_url=display_url)
2879
_fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2880
' (See bzr status).%(more)s')
2882
def __init__(self, tree, more=None):
2887
import bzrlib.urlutils as urlutils
2888
user_url = getattr(tree, "user_url", None)
2889
if user_url is None:
2890
display_url = str(tree)
2892
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2893
BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2896
class StoringUncommittedNotSupported(BzrError):
2898
_fmt = ('Branch "%(display_url)s" does not support storing uncommitted'
2901
def __init__(self, branch):
2902
import bzrlib.urlutils as urlutils
2903
user_url = getattr(branch, "user_url", None)
2904
if user_url is None:
2905
display_url = str(branch)
2907
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2908
BzrError.__init__(self, branch=branch, display_url=display_url)
2911
class ShelvedChanges(UncommittedChanges):
2913
_fmt = ('Working tree "%(display_url)s" has shelved changes'
2914
' (See bzr shelve --list).%(more)s')
2709
2917
class MissingTemplateVariable(BzrError):
2831
3052
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2834
class HookFailed(BzrError):
2835
"""Raised when a pre_change_branch_tip hook function fails anything other
2836
than TipChangeRejected.
2839
_fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2840
"%(traceback_text)s%(exc_value)s")
2842
def __init__(self, hook_stage, hook_name, exc_info):
2844
self.hook_stage = hook_stage
2845
self.hook_name = hook_name
2846
self.exc_info = exc_info
2847
self.exc_type = exc_info[0]
2848
self.exc_value = exc_info[1]
2849
self.exc_tb = exc_info[2]
2850
self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2853
3055
class TipChangeRejected(BzrError):
2854
3056
"""A pre_change_branch_tip hook function may raise this to cleanly and
2855
3057
explicitly abort a change to a branch tip.
2858
3060
_fmt = u"Tip change rejected: %(msg)s"
2860
3062
def __init__(self, msg):
3066
class ShelfCorrupt(BzrError):
3068
_fmt = "Shelf corrupt."
3071
class DecompressCorruption(BzrError):
3073
_fmt = "Corruption while decompressing repository file%(orig_error)s"
3075
def __init__(self, orig_error=None):
3076
if orig_error is not None:
3077
self.orig_error = ", %s" % (orig_error,)
3079
self.orig_error = ""
3080
BzrError.__init__(self)
3083
class NoSuchShelfId(BzrError):
3085
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
3087
def __init__(self, shelf_id):
3088
BzrError.__init__(self, shelf_id=shelf_id)
3091
class InvalidShelfId(BzrError):
3093
_fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3095
def __init__(self, invalid_id):
3096
BzrError.__init__(self, invalid_id=invalid_id)
3099
class JailBreak(BzrError):
3101
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3103
def __init__(self, url):
3104
BzrError.__init__(self, url=url)
3107
class UserAbort(BzrError):
3109
_fmt = 'The user aborted the operation.'
3112
class MustHaveWorkingTree(BzrError):
3114
_fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3116
def __init__(self, format, url):
3117
BzrError.__init__(self, format=format, url=url)
3120
class NoSuchView(BzrError):
3121
"""A view does not exist.
3124
_fmt = u"No such view: %(view_name)s."
3126
def __init__(self, view_name):
3127
self.view_name = view_name
3130
class ViewsNotSupported(BzrError):
3131
"""Views are not supported by a tree format.
3134
_fmt = ("Views are not supported by %(tree)s;"
3135
" use 'bzr upgrade' to change your tree to a later format.")
3137
def __init__(self, tree):
3141
class FileOutsideView(BzrError):
3143
_fmt = ('Specified file "%(file_name)s" is outside the current view: '
3146
def __init__(self, file_name, view_files):
3147
self.file_name = file_name
3148
self.view_str = ", ".join(view_files)
3151
class UnresumableWriteGroup(BzrError):
3153
_fmt = ("Repository %(repository)s cannot resume write group "
3154
"%(write_groups)r: %(reason)s")
3156
internal_error = True
3158
def __init__(self, repository, write_groups, reason):
3159
self.repository = repository
3160
self.write_groups = write_groups
3161
self.reason = reason
3164
class UnsuspendableWriteGroup(BzrError):
3166
_fmt = ("Repository %(repository)s cannot suspend a write group.")
3168
internal_error = True
3170
def __init__(self, repository):
3171
self.repository = repository
3174
class LossyPushToSameVCS(BzrError):
3176
_fmt = ("Lossy push not possible between %(source_branch)r and "
3177
"%(target_branch)r that are in the same VCS.")
3179
internal_error = True
3181
def __init__(self, source_branch, target_branch):
3182
self.source_branch = source_branch
3183
self.target_branch = target_branch
3186
class NoRoundtrippingSupport(BzrError):
3188
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
3189
"%(target_branch)r.")
3191
internal_error = True
3193
def __init__(self, source_branch, target_branch):
3194
self.source_branch = source_branch
3195
self.target_branch = target_branch
3198
class FileTimestampUnavailable(BzrError):
3200
_fmt = "The filestamp for %(path)s is not available."
3202
internal_error = True
3204
def __init__(self, path):
3208
class NoColocatedBranchSupport(BzrError):
3210
_fmt = ("%(bzrdir)r does not support co-located branches.")
3212
def __init__(self, bzrdir):
3213
self.bzrdir = bzrdir
3216
class NoWhoami(BzrError):
3218
_fmt = ('Unable to determine your name.\n'
3219
"Please, set your name with the 'whoami' command.\n"
3220
'E.g. bzr whoami "Your Name <name@example.com>"')
3223
class InvalidPattern(BzrError):
3225
_fmt = ('Invalid pattern(s) found. %(msg)s')
3227
def __init__(self, msg):
3231
class RecursiveBind(BzrError):
3233
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3234
'Please use `bzr unbind` to fix.')
3236
def __init__(self, branch_url):
3237
self.branch_url = branch_url
3240
# FIXME: I would prefer to define the config related exception classes in
3241
# config.py but the lazy import mechanism proscribes this -- vila 20101222
3242
class OptionExpansionLoop(BzrError):
3244
_fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3246
def __init__(self, string, refs):
3247
self.string = string
3248
self.refs = '->'.join(refs)
3251
class ExpandingUnknownOption(BzrError):
3253
_fmt = 'Option "%(name)s" is not defined while expanding "%(string)s".'
3255
def __init__(self, name, string):
3257
self.string = string
3260
class IllegalOptionName(BzrError):
3262
_fmt = 'Option "%(name)s" is not allowed.'
3264
def __init__(self, name):
3268
class NoCompatibleInter(BzrError):
3270
_fmt = ('No compatible object available for operations from %(source)r '
3273
def __init__(self, source, target):
3274
self.source = source
3275
self.target = target
3278
class HpssVfsRequestNotAllowed(BzrError):
3280
_fmt = ("VFS requests over the smart server are not allowed. Encountered: "
3281
"%(method)s, %(arguments)s.")
3283
def __init__(self, method, arguments):
3284
self.method = method
3285
self.arguments = arguments
3288
class UnsupportedKindChange(BzrError):
3290
_fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
3291
"%(path)s not supported by format %(format)r")
3293
def __init__(self, path, from_kind, to_kind, format):
3295
self.from_kind = from_kind
3296
self.to_kind = to_kind
3297
self.format = format
3300
class MissingFeature(BzrError):
3302
_fmt = ("Missing feature %(feature)s not provided by this "
3303
"version of Bazaar or any plugin.")
3305
def __init__(self, feature):
3306
self.feature = feature
3309
class PatchSyntax(BzrError):
3310
"""Base class for patch syntax errors."""
3313
class BinaryFiles(BzrError):
3315
_fmt = 'Binary files section encountered.'
3317
def __init__(self, orig_name, mod_name):
3318
self.orig_name = orig_name
3319
self.mod_name = mod_name
3322
class MalformedPatchHeader(PatchSyntax):
3324
_fmt = "Malformed patch header. %(desc)s\n%(line)r"
3326
def __init__(self, desc, line):
3331
class MalformedHunkHeader(PatchSyntax):
3333
_fmt = "Malformed hunk header. %(desc)s\n%(line)r"
3335
def __init__(self, desc, line):
3340
class MalformedLine(PatchSyntax):
3342
_fmt = "Malformed line. %(desc)s\n%(line)r"
3344
def __init__(self, desc, line):
3349
class PatchConflict(BzrError):
3351
_fmt = ('Text contents mismatch at line %(line_no)d. Original has '
3352
'"%(orig_line)s", but patch says it should be "%(patch_line)s"')
3354
def __init__(self, line_no, orig_line, patch_line):
3355
self.line_no = line_no
3356
self.orig_line = orig_line.rstrip('\n')
3357
self.patch_line = patch_line.rstrip('\n')
3360
class FeatureAlreadyRegistered(BzrError):
3362
_fmt = 'The feature %(feature)s has already been registered.'
3364
def __init__(self, feature):
3365
self.feature = feature
3368
class ChangesAlreadyStored(BzrCommandError):
3370
_fmt = ('Cannot store uncommitted changes because this branch already'
3371
' stores uncommitted changes.')