72
73
arguments can be given. The first is for generic "user" errors which
73
74
are not intended to be caught and so do not need a specific subclass.
74
75
The second case is for use with subclasses that provide a _fmt format
75
string to print the arguments.
76
string to print the arguments.
77
Keyword arguments are taken as parameters to the error, which can
78
be inserted into the format string template. It's recommended
79
that subclasses override the __init__ method to require specific
78
Keyword arguments are taken as parameters to the error, which can
79
be inserted into the format string template. It's recommended
80
that subclasses override the __init__ method to require specific
82
83
:param msg: If given, this is the literal complete text for the error,
83
not subject to expansion. 'msg' is used instead of 'message' because
84
python evolved and, in 2.6, forbids the use of 'message'.
84
not subject to expansion.
86
86
StandardError.__init__(self)
87
87
if msg is not None:
700
690
# TODO: This is given a URL; we try to unescape it but doing that from inside
701
691
# the exception object is a bit undesirable.
702
# TODO: Probably this behavior of should be a common superclass
692
# TODO: Probably this behavior of should be a common superclass
703
693
class NotBranchError(PathError):
705
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
695
_fmt = 'Not a branch: "%(path)s".'
707
def __init__(self, path, detail=None, bzrdir=None):
697
def __init__(self, path):
708
698
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)
699
self.path = urlutils.unescape_for_display(path, 'ascii')
745
702
class NoSubmitBranch(PathError):
1547
1470
self.options = options
1550
class RetryWithNewPacks(BzrError):
1551
"""Raised when we realize that the packs on disk have changed.
1553
This is meant as more of a signaling exception, to trap between where a
1554
local error occurred and the code that can actually handle the error and
1555
code that can retry appropriately.
1558
internal_error = True
1560
_fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1563
def __init__(self, context, reload_occurred, exc_info):
1564
"""create a new RetryWithNewPacks error.
1566
:param reload_occurred: Set to True if we know that the packs have
1567
already been reloaded, and we are failing because of an in-memory
1568
cache miss. If set to True then we will ignore if a reload says
1569
nothing has changed, because we assume it has already reloaded. If
1570
False, then a reload with nothing changed will force an error.
1571
:param exc_info: The original exception traceback, so if there is a
1572
problem we can raise the original error (value from sys.exc_info())
1574
BzrError.__init__(self)
1575
self.reload_occurred = reload_occurred
1576
self.exc_info = exc_info
1577
self.orig_error = exc_info[1]
1578
# TODO: The global error handler should probably treat this by
1579
# raising/printing the original exception with a bit about
1580
# RetryWithNewPacks also not being caught
1583
class RetryAutopack(RetryWithNewPacks):
1584
"""Raised when we are autopacking and we find a missing file.
1586
Meant as a signaling exception, to tell the autopack code it should try
1590
internal_error = True
1592
_fmt = ("Pack files have changed, reload and try autopack again."
1593
" context: %(context)s %(orig_error)s")
1596
1473
class NoSuchExportFormat(BzrError):
1598
1475
_fmt = "Export format %(format)r not supported"
1600
1477
def __init__(self, format):
1764
1614
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1766
def __init__(self, source, target, is_permanent=False):
1616
def __init__(self, source, target, is_permanent=False, qual_proto=None):
1767
1617
self.source = source
1768
1618
self.target = target
1769
1619
if is_permanent:
1770
1620
self.permanently = ' permanently'
1772
1622
self.permanently = ''
1623
self._qualified_proto = qual_proto
1773
1624
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)
1776
1660
class TooManyRedirections(TransportError):
1783
1667
_fmt = "Working tree has conflicts."
1786
class ConfigContentError(BzrError):
1788
_fmt = "Config file %(filename)s is not UTF-8 encoded\n"
1790
def __init__(self, filename):
1791
BzrError.__init__(self)
1792
self.filename = filename
1795
1670
class ParseConfigError(BzrError):
1797
_fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
1799
1672
def __init__(self, errors, filename):
1800
BzrError.__init__(self)
1801
self.filename = filename
1802
self.errors = '\n'.join(e.msg for e in errors)
1805
class ConfigOptionValueError(BzrError):
1807
_fmt = """Bad value "%(value)s" for option "%(name)s"."""
1809
def __init__(self, name, value):
1810
BzrError.__init__(self, name=name, value=value)
1673
if filename is None:
1675
message = "Error(s) parsing config file %s:\n%s" % \
1676
(filename, ('\n'.join(e.message for e in errors)))
1677
BzrError.__init__(self, message)
1813
1680
class NoEmailInUsername(BzrError):
1822
1689
class SigningFailed(BzrError):
1824
_fmt = 'Failed to GPG sign data with command "%(command_line)s"'
1691
_fmt = 'Failed to gpg sign data with command "%(command_line)s"'
1826
1693
def __init__(self, command_line):
1827
1694
BzrError.__init__(self, command_line=command_line)
1830
class SignatureVerificationFailed(BzrError):
1832
_fmt = 'Failed to verify GPG signature data with error "%(error)s"'
1834
def __init__(self, error):
1835
BzrError.__init__(self, error=error)
1838
class DependencyNotPresent(BzrError):
1840
_fmt = 'Unable to import library "%(library)s": %(error)s'
1842
def __init__(self, library, error):
1843
BzrError.__init__(self, library=library, error=error)
1846
class GpgmeNotInstalled(DependencyNotPresent):
1848
_fmt = 'python-gpgme is not installed, it is needed to verify signatures'
1850
def __init__(self, error):
1851
DependencyNotPresent.__init__(self, 'gpgme', error)
1854
1697
class WorkingTreeNotRevision(BzrError):
1856
_fmt = ("The working tree for %(basedir)s has changed since"
1699
_fmt = ("The working tree for %(basedir)s has changed since"
1857
1700
" the last commit, but weave merge requires that it be"
2016
1859
_fmt = "Moving the root directory is not supported at this time"
2019
class TransformRenameFailed(BzrError):
2021
_fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
2023
def __init__(self, from_path, to_path, why, errno):
2024
self.from_path = from_path
2025
self.to_path = to_path
2030
1862
class BzrMoveFailedError(BzrError):
2032
_fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
2033
"%(_has_extra)s%(extra)s")
1864
_fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
2035
1866
def __init__(self, from_path='', to_path='', extra=None):
2036
from bzrlib.osutils import splitpath
2037
1867
BzrError.__init__(self)
2039
self.extra, self._has_extra = extra, ': '
1869
self.extra = ': ' + str(extra)
2041
self.extra = self._has_extra = ''
2043
1873
has_from = len(from_path) > 0
2044
1874
has_to = len(to_path) > 0
2046
self.from_path = splitpath(from_path)[-1]
1876
self.from_path = osutils.splitpath(from_path)[-1]
2048
1878
self.from_path = ''
2051
self.to_path = splitpath(to_path)[-1]
1881
self.to_path = osutils.splitpath(to_path)[-1]
2053
1883
self.to_path = ''
2393
2216
self.text = text
2396
class MalformedHeader(BadBundle):
2219
class MalformedHeader(BadBundle):
2398
2221
_fmt = "Malformed bzr revision-bundle header: %(text)r"
2401
class MalformedPatches(BadBundle):
2224
class MalformedPatches(BadBundle):
2403
2226
_fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2406
class MalformedFooter(BadBundle):
2229
class MalformedFooter(BadBundle):
2408
2231
_fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2411
2234
class UnsupportedEOLMarker(BadBundle):
2413
_fmt = "End of line marker was not \\n in bzr revision-bundle"
2236
_fmt = "End of line marker was not \\n in bzr revision-bundle"
2415
2238
def __init__(self):
2416
# XXX: BadBundle's constructor assumes there's explanatory text,
2239
# XXX: BadBundle's constructor assumes there's explanatory text,
2417
2240
# but for this there is not
2418
2241
BzrError.__init__(self)
2421
2244
class IncompatibleBundleFormat(BzrError):
2423
2246
_fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2425
2248
def __init__(self, bundle_format, other):
2926
2728
class UncommittedChanges(BzrError):
2928
_fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2929
' (See bzr status).%(more)s')
2730
_fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2931
def __init__(self, tree, more=None):
2732
def __init__(self, tree):
2936
2733
import bzrlib.urlutils as urlutils
2937
user_url = getattr(tree, "user_url", None)
2938
if user_url is None:
2939
display_url = str(tree)
2941
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2942
BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2945
class ShelvedChanges(UncommittedChanges):
2947
_fmt = ('Working tree "%(display_url)s" has shelved changes'
2948
' (See bzr shelve --list).%(more)s')
2734
display_url = urlutils.unescape_for_display(
2735
tree.bzrdir.root_transport.base, 'ascii')
2736
BzrError.__init__(self, tree=tree, display_url=display_url)
2951
2739
class MissingTemplateVariable(BzrError):
3115
2884
"""A pre_change_branch_tip hook function may raise this to cleanly and
3116
2885
explicitly abort a change to a branch tip.
3119
2888
_fmt = u"Tip change rejected: %(msg)s"
3121
2890
def __init__(self, msg):
3125
class ShelfCorrupt(BzrError):
3127
_fmt = "Shelf corrupt."
3130
class DecompressCorruption(BzrError):
3132
_fmt = "Corruption while decompressing repository file%(orig_error)s"
3134
def __init__(self, orig_error=None):
3135
if orig_error is not None:
3136
self.orig_error = ", %s" % (orig_error,)
3138
self.orig_error = ""
3139
BzrError.__init__(self)
3142
class NoSuchShelfId(BzrError):
3144
_fmt = 'No changes are shelved with id "%(shelf_id)d".'
3146
def __init__(self, shelf_id):
3147
BzrError.__init__(self, shelf_id=shelf_id)
3150
class InvalidShelfId(BzrError):
3152
_fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3154
def __init__(self, invalid_id):
3155
BzrError.__init__(self, invalid_id=invalid_id)
3158
class JailBreak(BzrError):
3160
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3162
def __init__(self, url):
3163
BzrError.__init__(self, url=url)
3166
class UserAbort(BzrError):
3168
_fmt = 'The user aborted the operation.'
3171
class MustHaveWorkingTree(BzrError):
3173
_fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3175
def __init__(self, format, url):
3176
BzrError.__init__(self, format=format, url=url)
3179
class NoSuchView(BzrError):
3180
"""A view does not exist.
3183
_fmt = u"No such view: %(view_name)s."
3185
def __init__(self, view_name):
3186
self.view_name = view_name
3189
class ViewsNotSupported(BzrError):
3190
"""Views are not supported by a tree format.
3193
_fmt = ("Views are not supported by %(tree)s;"
3194
" use 'bzr upgrade' to change your tree to a later format.")
3196
def __init__(self, tree):
3200
class FileOutsideView(BzrError):
3202
_fmt = ('Specified file "%(file_name)s" is outside the current view: '
3205
def __init__(self, file_name, view_files):
3206
self.file_name = file_name
3207
self.view_str = ", ".join(view_files)
3210
class UnresumableWriteGroup(BzrError):
3212
_fmt = ("Repository %(repository)s cannot resume write group "
3213
"%(write_groups)r: %(reason)s")
3215
internal_error = True
3217
def __init__(self, repository, write_groups, reason):
3218
self.repository = repository
3219
self.write_groups = write_groups
3220
self.reason = reason
3223
class UnsuspendableWriteGroup(BzrError):
3225
_fmt = ("Repository %(repository)s cannot suspend a write group.")
3227
internal_error = True
3229
def __init__(self, repository):
3230
self.repository = repository
3233
class LossyPushToSameVCS(BzrError):
3235
_fmt = ("Lossy push not possible between %(source_branch)r and "
3236
"%(target_branch)r that are in the same VCS.")
3238
internal_error = True
3240
def __init__(self, source_branch, target_branch):
3241
self.source_branch = source_branch
3242
self.target_branch = target_branch
3245
class NoRoundtrippingSupport(BzrError):
3247
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
3248
"%(target_branch)r.")
3250
internal_error = True
3252
def __init__(self, source_branch, target_branch):
3253
self.source_branch = source_branch
3254
self.target_branch = target_branch
3257
class FileTimestampUnavailable(BzrError):
3259
_fmt = "The filestamp for %(path)s is not available."
3261
internal_error = True
3263
def __init__(self, path):
3267
class NoColocatedBranchSupport(BzrError):
3269
_fmt = ("%(bzrdir)r does not support co-located branches.")
3271
def __init__(self, bzrdir):
3272
self.bzrdir = bzrdir
3275
class NoWhoami(BzrError):
3277
_fmt = ('Unable to determine your name.\n'
3278
"Please, set your name with the 'whoami' command.\n"
3279
'E.g. bzr whoami "Your Name <name@example.com>"')
3282
class InvalidPattern(BzrError):
3284
_fmt = ('Invalid pattern(s) found. %(msg)s')
3286
def __init__(self, msg):
3290
class RecursiveBind(BzrError):
3292
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3293
'Please use `bzr unbind` to fix.')
3295
def __init__(self, branch_url):
3296
self.branch_url = branch_url
3299
# FIXME: I would prefer to define the config related exception classes in
3300
# config.py but the lazy import mechanism proscribes this -- vila 20101222
3301
class OptionExpansionLoop(BzrError):
3303
_fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3305
def __init__(self, string, refs):
3306
self.string = string
3307
self.refs = '->'.join(refs)
3310
class ExpandingUnknownOption(BzrError):
3312
_fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
3314
def __init__(self, name, string):
3316
self.string = string
3319
class NoCompatibleInter(BzrError):
3321
_fmt = ('No compatible object available for operations from %(source)r '
3324
def __init__(self, source, target):
3325
self.source = source
3326
self.target = target