13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Exceptions for bzr, and reporting of them.
20
from __future__ import absolute_import
25
from bzrlib.patches import (
26
34
# TODO: is there any value in providing the .args field used by standard
27
# python exceptions? A list of values with no names seems less useful
35
# python exceptions? A list of values with no names seems less useful
30
# TODO: Perhaps convert the exception to a string at the moment it's
38
# TODO: Perhaps convert the exception to a string at the moment it's
31
39
# constructed to make sure it will succeed. But that says nothing about
32
40
# exceptions that are never raised.
39
# return codes from the brz program
47
# return codes from the bzr program
42
50
EXIT_INTERNAL_ERROR = 4
45
class BzrError(Exception):
53
class BzrError(StandardError):
47
Base class for errors raised by breezy.
55
Base class for errors raised by bzrlib.
49
:cvar internal_error: if True this was probably caused by a brz bug and
50
should be displayed with a traceback; if False (or absent) this was
51
probably a user or environment error and they don't need the gory
52
details. (That can be overridden by -Derror on the command line.)
57
:cvar internal_error: if True this was probably caused by a bzr bug and
58
should be displayed with a traceback; if False (or absent) this was
59
probably a user or environment error and they don't need the gory details.
60
(That can be overridden by -Derror on the command line.)
54
62
:cvar _fmt: Format string to display the error; this is expanded
55
by the instance's dict.
63
by the instance's dict.
58
66
internal_error = False
60
68
def __init__(self, msg=None, **kwds):
65
73
arguments can be given. The first is for generic "user" errors which
66
74
are not intended to be caught and so do not need a specific subclass.
67
75
The second case is for use with subclasses that provide a _fmt format
68
string to print the arguments.
76
string to print the arguments.
70
Keyword arguments are taken as parameters to the error, which can
71
be inserted into the format string template. It's recommended
72
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
75
83
:param msg: If given, this is the literal complete text for the error,
76
not subject to expansion. 'msg' is used instead of 'message' because
77
python evolved and, in 2.6, forbids the use of 'message'.
84
not subject to expansion.
79
Exception.__init__(self)
86
StandardError.__init__(self)
80
87
if msg is not None:
81
88
# I was going to deprecate this, but it actually turns out to be
82
89
# quite handy - mbp 20061103.
86
93
for key, value in kwds.items():
87
94
setattr(self, key, value)
90
97
s = getattr(self, '_preformatted_string', None)
92
# contains a preformatted message
99
# contains a preformatted message; must be cast to plain str
96
102
fmt = self._get_format_string()
98
104
d = dict(self.__dict__)
105
# special case: python2.5 puts the 'message' attribute in a
106
# slot, so it isn't seen in __dict__
107
d['message'] = getattr(self, 'message', 'no message')
100
109
# __str__() should always return a 'str' object
101
110
# never a 'unicode' object.
111
if isinstance(s, unicode):
112
return s.encode('utf8')
103
except Exception as e:
105
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
114
except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
115
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
116
% (self.__class__.__name__,
118
getattr(self, '_fmt', None),
121
def _get_format_string(self):
122
"""Return format string for this exception or None"""
123
fmt = getattr(self, '_fmt', None)
126
fmt = getattr(self, '__doc__', None)
128
symbol_versioning.warn("%s uses its docstring as a format, "
129
"it should use _fmt instead" % self.__class__.__name__,
132
return 'Unprintable exception %s: dict=%r, fmt=%r' \
106
133
% (self.__class__.__name__,
108
135
getattr(self, '_fmt', None),
115
return self._format().encode('utf-8')
117
__unicode__ = _format
120
return '%s(%s)' % (self.__class__.__name__, str(self))
122
def _get_format_string(self):
123
"""Return format string for this exception or None"""
124
fmt = getattr(self, '_fmt', None)
126
from breezy.i18n import gettext
127
return gettext(fmt) # _fmt strings should be ascii
129
def __eq__(self, other):
130
if self.__class__ is not other.__class__:
131
return NotImplemented
132
return self.__dict__ == other.__dict__
138
139
class InternalBzrError(BzrError):
146
147
internal_error = True
150
class BzrNewError(BzrError):
151
"""Deprecated error base class."""
152
# base classes should override the docstring with their human-
153
# readable explanation
155
def __init__(self, *args, **kwds):
156
# XXX: Use the underlying BzrError to always generate the args
157
# attribute if it doesn't exist. We can't use super here, because
158
# exceptions are old-style classes in python2.4 (but new in 2.5).
160
symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
161
'please convert %s to use BzrError instead'
162
% self.__class__.__name__,
165
BzrError.__init__(self, *args)
166
for key, value in kwds.items():
167
setattr(self, key, value)
171
# __str__() should always return a 'str' object
172
# never a 'unicode' object.
173
s = self.__doc__ % self.__dict__
174
if isinstance(s, unicode):
175
return s.encode('utf8')
177
except (TypeError, NameError, ValueError, KeyError), e:
178
return 'Unprintable exception %s(%r): %r' \
179
% (self.__class__.__name__,
183
class AlreadyBuilding(BzrError):
185
_fmt = "The tree builder is already building a tree."
149
188
class BranchError(BzrError):
150
189
"""Base class for concrete 'errors about a branch'."""
156
195
class BzrCheckError(InternalBzrError):
158
_fmt = "Internal check failed: %(msg)s"
160
def __init__(self, msg):
161
BzrError.__init__(self)
165
class IncompatibleVersion(BzrError):
167
_fmt = 'API %(api)s is not compatible; one of versions %(wanted)r '\
168
'is required, but current version is %(current)r.'
170
def __init__(self, api, wanted, current):
197
_fmt = "Internal check failed: %(message)s"
199
def __init__(self, message):
200
BzrError.__init__(self)
201
self.message = message
204
class DisabledMethod(InternalBzrError):
206
_fmt = "The smart server method '%(class_name)s' is disabled."
208
def __init__(self, class_name):
209
BzrError.__init__(self)
210
self.class_name = class_name
213
class IncompatibleAPI(BzrError):
215
_fmt = 'The API for "%(api)s" is not compatible with "%(wanted)s". '\
216
'It supports versions "%(minimum)s" to "%(current)s".'
218
def __init__(self, api, wanted, minimum, current):
172
220
self.wanted = wanted
221
self.minimum = minimum
173
222
self.current = current
230
279
_fmt = 'There is no public branch set for "%(branch_url)s".'
232
281
def __init__(self, branch):
233
from . import urlutils
282
import bzrlib.urlutils as urlutils
234
283
public_location = urlutils.unescape_for_display(branch.base, 'ascii')
235
284
BzrError.__init__(self, branch_url=public_location)
287
class NoHelpTopic(BzrError):
289
_fmt = ("No help could be found for '%(topic)s'. "
290
"Please use 'bzr help topics' to obtain a list of topics.")
292
def __init__(self, topic):
238
296
class NoSuchId(BzrError):
240
298
_fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
242
300
def __init__(self, tree, file_id):
243
301
BzrError.__init__(self)
244
302
self.file_id = file_id
306
class NoSuchIdInRepository(NoSuchId):
308
_fmt = ('The file id "%(file_id)s" is not present in the repository'
311
def __init__(self, repository, file_id):
312
BzrError.__init__(self, repository=repository, file_id=file_id)
248
315
class NotStacked(BranchError):
250
317
_fmt = "The branch '%(branch)s' is not stacked."
304
386
self.not_locked = not_locked
389
class BzrOptionError(BzrCommandError):
391
_fmt = "Error in command line options"
394
class BadIndexFormatSignature(BzrError):
396
_fmt = "%(value)s is not an index of type %(_type)s."
398
def __init__(self, value, _type):
399
BzrError.__init__(self)
404
class BadIndexData(BzrError):
406
_fmt = "Error in data for index %(value)s."
408
def __init__(self, value):
409
BzrError.__init__(self)
413
class BadIndexDuplicateKey(BzrError):
415
_fmt = "The key '%(key)s' is already in index '%(index)s'."
417
def __init__(self, key, index):
418
BzrError.__init__(self)
423
class BadIndexKey(BzrError):
425
_fmt = "The key '%(key)s' is not a valid key."
427
def __init__(self, key):
428
BzrError.__init__(self)
432
class BadIndexOptions(BzrError):
434
_fmt = "Could not parse options for index %(value)s."
436
def __init__(self, value):
437
BzrError.__init__(self)
441
class BadIndexValue(BzrError):
443
_fmt = "The value '%(value)s' is not a valid value."
445
def __init__(self, value):
446
BzrError.__init__(self)
450
class BadOptionValue(BzrError):
452
_fmt = """Bad value "%(value)s" for option "%(name)s"."""
454
def __init__(self, name, value):
455
BzrError.__init__(self, name=name, value=value)
307
458
class StrictCommitFailed(BzrError):
309
460
_fmt = "Commit refused because there are unknown files in the tree"
395
546
_fmt = 'Permission denied: "%(path)s"%(extra)s'
549
class InvalidURL(PathError):
551
_fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
554
class InvalidURLJoin(PathError):
556
_fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
558
def __init__(self, reason, base, join_args):
561
self.join_args = join_args
562
PathError.__init__(self, base, reason)
565
class InvalidRebaseURLs(PathError):
567
_fmt = "URLs differ by more than path: %(from_)r and %(to)r"
569
def __init__(self, from_, to):
572
PathError.__init__(self, from_, 'URLs differ by more than path.')
398
575
class UnavailableRepresentation(InternalBzrError):
400
577
_fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
587
class UnknownHook(BzrError):
589
_fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
591
def __init__(self, hook_type, hook_name):
592
BzrError.__init__(self)
593
self.type = hook_type
594
self.hook = hook_name
410
597
class UnsupportedProtocol(PathError):
412
599
_fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
414
def __init__(self, url, extra=""):
601
def __init__(self, url, extra):
415
602
PathError.__init__(self, url, extra=extra)
418
class UnstackableLocationError(BzrError):
420
_fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
422
def __init__(self, branch_url, target_url):
605
class UnstackableBranchFormat(BzrError):
607
_fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
608
"You will need to upgrade the branch to permit branch stacking.")
610
def __init__(self, format, url):
423
611
BzrError.__init__(self)
424
self.branch_url = branch_url
425
self.target_url = target_url
428
616
class UnstackableRepositoryFormat(BzrError):
479
667
# TODO: This is given a URL; we try to unescape it but doing that from inside
480
668
# the exception object is a bit undesirable.
481
# TODO: Probably this behavior of should be a common superclass
669
# TODO: Probably this behavior of should be a common superclass
482
670
class NotBranchError(PathError):
484
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
486
def __init__(self, path, detail=None, controldir=None):
487
from . import urlutils
488
path = urlutils.unescape_for_display(path, 'ascii')
489
if detail is not None:
490
detail = ': ' + detail
492
self.controldir = controldir
493
PathError.__init__(self, path=path)
496
return '<%s %r>' % (self.__class__.__name__, self.__dict__)
498
def _get_format_string(self):
499
# GZ 2017-06-08: Not the best place to lazy fill detail in.
500
if self.detail is None:
501
self.detail = self._get_detail()
502
return super(NotBranchError, self)._get_format_string()
504
def _get_detail(self):
505
if self.controldir is not None:
507
self.controldir.open_repository()
508
except NoRepositoryPresent:
510
except Exception as e:
511
# Just ignore unexpected errors. Raising arbitrary errors
512
# during str(err) can provoke strange bugs. Concretely
513
# Launchpad's codehosting managed to raise NotBranchError
514
# here, and then get stuck in an infinite loop/recursion
515
# trying to str() that error. All this error really cares
516
# about that there's no working repository there, and if
517
# open_repository() fails, there probably isn't.
518
return ': ' + e.__class__.__name__
520
return ': location is a repository'
672
_fmt = 'Not a branch: "%(path)s".'
674
def __init__(self, path):
675
import bzrlib.urlutils as urlutils
676
self.path = urlutils.unescape_for_display(path, 'ascii')
524
679
class NoSubmitBranch(PathError):
526
681
_fmt = 'No submit branch available for branch "%(path)s"'
528
683
def __init__(self, branch):
529
from . import urlutils
684
import bzrlib.urlutils as urlutils
530
685
self.path = urlutils.unescape_for_display(branch.base, 'ascii')
533
class AlreadyControlDirError(PathError):
535
_fmt = 'A control directory already exists: "%(path)s".'
538
688
class AlreadyBranchError(PathError):
540
690
_fmt = 'Already a branch: "%(path)s".'
543
class InvalidBranchName(PathError):
545
_fmt = "Invalid branch name: %(name)s"
547
def __init__(self, name):
548
BzrError.__init__(self)
552
class ParentBranchExists(AlreadyBranchError):
554
_fmt = 'Parent branch already exists: "%(path)s".'
557
693
class BranchExistsWithoutWorkingTree(PathError):
559
695
_fmt = 'Directory contains a branch, but no working tree \
560
(use brz checkout if you wish to build a working tree): "%(path)s"'
696
(use bzr checkout if you wish to build a working tree): "%(path)s"'
699
class AtomicFileAlreadyClosed(PathError):
701
_fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
704
def __init__(self, path, function):
705
PathError.__init__(self, path=path, extra=None)
706
self.function = function
563
709
class InaccessibleParent(PathError):
573
719
class NoRepositoryPresent(BzrError):
575
721
_fmt = 'No repository present: "%(path)s"'
576
def __init__(self, controldir):
577
BzrError.__init__(self)
578
self.path = controldir.transport.clone('..').base
722
def __init__(self, bzrdir):
723
BzrError.__init__(self)
724
self.path = bzrdir.transport.clone('..').base
727
class FileInWrongBranch(BzrError):
729
_fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
731
def __init__(self, branch, path):
732
BzrError.__init__(self)
734
self.branch_base = branch.base
581
738
class UnsupportedFormatError(BzrError):
583
_fmt = "Unsupported branch format: %(format)s\nPlease run 'brz upgrade'"
740
_fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
586
743
class UnknownFormatError(BzrError):
588
745
_fmt = "Unknown %(kind)s format: %(format)r"
590
747
def __init__(self, format, kind='branch'):
595
752
class IncompatibleFormat(BzrError):
597
_fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
599
def __init__(self, format, controldir_format):
600
BzrError.__init__(self)
602
self.controldir = controldir_format
605
class ParseFormatError(BzrError):
607
_fmt = "Parse error on line %(lineno)d of %(format)s format: %(line)s"
609
def __init__(self, format, lineno, line, text):
610
BzrError.__init__(self)
754
_fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
756
def __init__(self, format, bzrdir_format):
757
BzrError.__init__(self)
759
self.bzrdir = bzrdir_format
617
762
class IncompatibleRepositories(BzrError):
618
"""Report an error that two repositories are not compatible.
620
Note that the source and target repositories are permitted to be strings:
621
this exception is thrown from the smart server and may refer to a
622
repository the client hasn't opened.
625
_fmt = "%(target)s\n" \
626
"is not compatible with\n" \
630
def __init__(self, source, target, details=None):
632
details = "(no details)"
633
BzrError.__init__(self, target=target, source=source, details=details)
764
_fmt = "Repository %(target)s is not compatible with repository"\
767
def __init__(self, source, target):
768
BzrError.__init__(self, target=target, source=source)
636
771
class IncompatibleRevision(BzrError):
638
773
_fmt = "Revision is not compatible with %(repo_format)s"
640
775
def __init__(self, repo_format):
1043
1199
not_ancestor_id=not_ancestor_id)
1202
class InstallFailed(BzrError):
1204
def __init__(self, revisions):
1205
revision_str = ", ".join(str(r) for r in revisions)
1206
msg = "Could not install revisions:\n%s" % revision_str
1207
BzrError.__init__(self, msg)
1208
self.revisions = revisions
1211
class AmbiguousBase(BzrError):
1213
def __init__(self, bases):
1214
warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
1216
msg = ("The correct base is unclear, because %s are all equally close"
1218
BzrError.__init__(self, msg)
1046
1222
class NoCommits(BranchError):
1048
1224
_fmt = "Branch %(branch)s has no commits."
1106
1281
self.error = error
1284
class WeaveError(BzrError):
1286
_fmt = "Error in processing weave: %(message)s"
1288
def __init__(self, message=None):
1289
BzrError.__init__(self)
1290
self.message = message
1293
class WeaveRevisionAlreadyPresent(WeaveError):
1295
_fmt = "Revision {%(revision_id)s} already present in %(weave)s"
1297
def __init__(self, revision_id, weave):
1299
WeaveError.__init__(self)
1300
self.revision_id = revision_id
1304
class WeaveRevisionNotPresent(WeaveError):
1306
_fmt = "Revision {%(revision_id)s} not present in %(weave)s"
1308
def __init__(self, revision_id, weave):
1309
WeaveError.__init__(self)
1310
self.revision_id = revision_id
1314
class WeaveFormatError(WeaveError):
1316
_fmt = "Weave invariant violated: %(what)s"
1318
def __init__(self, what):
1319
WeaveError.__init__(self)
1323
class WeaveParentMismatch(WeaveError):
1325
_fmt = "Parents are mismatched between two revisions. %(message)s"
1328
class WeaveInvalidChecksum(WeaveError):
1330
_fmt = "Text did not match it's checksum: %(message)s"
1333
class WeaveTextDiffers(WeaveError):
1335
_fmt = ("Weaves differ on text content. Revision:"
1336
" {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
1338
def __init__(self, revision_id, weave_a, weave_b):
1339
WeaveError.__init__(self)
1340
self.revision_id = revision_id
1341
self.weave_a = weave_a
1342
self.weave_b = weave_b
1345
class WeaveTextDiffers(WeaveError):
1347
_fmt = ("Weaves differ on text content. Revision:"
1348
" {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
1350
def __init__(self, revision_id, weave_a, weave_b):
1351
WeaveError.__init__(self)
1352
self.revision_id = revision_id
1353
self.weave_a = weave_a
1354
self.weave_b = weave_b
1109
1357
class VersionedFileError(BzrError):
1111
1359
_fmt = "Versioned file error"
1114
1362
class RevisionNotPresent(VersionedFileError):
1116
1364
_fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1118
1366
def __init__(self, revision_id, file_id):
1134
1382
class VersionedFileInvalidChecksum(VersionedFileError):
1136
_fmt = "Text did not match its checksum: %(msg)s"
1139
class RetryWithNewPacks(BzrError):
1140
"""Raised when we realize that the packs on disk have changed.
1142
This is meant as more of a signaling exception, to trap between where a
1143
local error occurred and the code that can actually handle the error and
1144
code that can retry appropriately.
1147
internal_error = True
1149
_fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1152
def __init__(self, context, reload_occurred, exc_info):
1153
"""create a new RetryWithNewPacks error.
1155
:param reload_occurred: Set to True if we know that the packs have
1156
already been reloaded, and we are failing because of an in-memory
1157
cache miss. If set to True then we will ignore if a reload says
1158
nothing has changed, because we assume it has already reloaded. If
1159
False, then a reload with nothing changed will force an error.
1160
:param exc_info: The original exception traceback, so if there is a
1161
problem we can raise the original error (value from sys.exc_info())
1163
BzrError.__init__(self)
1164
self.context = context
1165
self.reload_occurred = reload_occurred
1166
self.exc_info = exc_info
1167
self.orig_error = exc_info[1]
1168
# TODO: The global error handler should probably treat this by
1169
# raising/printing the original exception with a bit about
1170
# RetryWithNewPacks also not being caught
1173
class RetryAutopack(RetryWithNewPacks):
1174
"""Raised when we are autopacking and we find a missing file.
1176
Meant as a signaling exception, to tell the autopack code it should try
1180
internal_error = True
1182
_fmt = ("Pack files have changed, reload and try autopack again."
1183
" context: %(context)s %(orig_error)s")
1384
_fmt = "Text did not match its checksum: %(message)s"
1387
class KnitError(InternalBzrError):
1392
class KnitCorrupt(KnitError):
1394
_fmt = "Knit %(filename)s corrupt: %(how)s"
1396
def __init__(self, filename, how):
1397
KnitError.__init__(self)
1398
self.filename = filename
1402
class KnitDataStreamIncompatible(KnitError):
1403
# Not raised anymore, as we can convert data streams. In future we may
1404
# need it again for more exotic cases, so we're keeping it around for now.
1406
_fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
1408
def __init__(self, stream_format, target_format):
1409
self.stream_format = stream_format
1410
self.target_format = target_format
1413
class KnitDataStreamUnknown(KnitError):
1414
# Indicates a data stream we don't know how to handle.
1416
_fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
1418
def __init__(self, stream_format):
1419
self.stream_format = stream_format
1422
class KnitHeaderError(KnitError):
1424
_fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
1426
def __init__(self, badline, filename):
1427
KnitError.__init__(self)
1428
self.badline = badline
1429
self.filename = filename
1431
class KnitIndexUnknownMethod(KnitError):
1432
"""Raised when we don't understand the storage method.
1434
Currently only 'fulltext' and 'line-delta' are supported.
1437
_fmt = ("Knit index %(filename)s does not have a known method"
1438
" in options: %(options)r")
1440
def __init__(self, filename, options):
1441
KnitError.__init__(self)
1442
self.filename = filename
1443
self.options = options
1186
1446
class NoSuchExportFormat(BzrError):
1188
1448
_fmt = "Export format %(format)r not supported"
1190
1450
def __init__(self, format):
1360
1587
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1362
def __init__(self, source, target, is_permanent=False):
1589
def __init__(self, source, target, is_permanent=False, qual_proto=None):
1363
1590
self.source = source
1364
1591
self.target = target
1365
1592
if is_permanent:
1366
1593
self.permanently = ' permanently'
1368
1595
self.permanently = ''
1596
self._qualified_proto = qual_proto
1369
1597
TransportError.__init__(self)
1599
def _requalify_url(self, url):
1600
"""Restore the qualified proto in front of the url"""
1601
# When this exception is raised, source and target are in
1602
# user readable format. But some transports may use a
1603
# different proto (http+urllib:// will present http:// to
1604
# the user. If a qualified proto is specified, the code
1605
# trapping the exception can get the qualified urls to
1606
# properly handle the redirection themself (creating a
1607
# new transport object from the target url for example).
1608
# But checking that the scheme of the original and
1609
# redirected urls are the same can be tricky. (see the
1610
# FIXME in BzrDir.open_from_transport for the unique use
1612
if self._qualified_proto is None:
1615
# The TODO related to NotBranchError mention that doing
1616
# that kind of manipulation on the urls may not be the
1617
# exception object job. On the other hand, this object is
1618
# the interface between the code and the user so
1619
# presenting the urls in different ways is indeed its
1622
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1623
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1626
def get_source_url(self):
1627
return self._requalify_url(self.source)
1629
def get_target_url(self):
1630
return self._requalify_url(self.target)
1372
1633
class TooManyRedirections(TransportError):
1379
1640
_fmt = "Working tree has conflicts."
1382
class DependencyNotPresent(BzrError):
1384
_fmt = 'Unable to import library "%(library)s": %(error)s'
1386
def __init__(self, library, error):
1387
BzrError.__init__(self, library=library, error=error)
1643
class ParseConfigError(BzrError):
1645
def __init__(self, errors, filename):
1646
if filename is None:
1648
message = "Error(s) parsing config file %s:\n%s" % \
1649
(filename, ('\n'.join(e.message for e in errors)))
1650
BzrError.__init__(self, message)
1653
class NoEmailInUsername(BzrError):
1655
_fmt = "%(username)r does not seem to contain a reasonable email address"
1657
def __init__(self, username):
1658
BzrError.__init__(self)
1659
self.username = username
1662
class SigningFailed(BzrError):
1664
_fmt = 'Failed to gpg sign data with command "%(command_line)s"'
1666
def __init__(self, command_line):
1667
BzrError.__init__(self, command_line=command_line)
1390
1670
class WorkingTreeNotRevision(BzrError):
1392
_fmt = ("The working tree for %(basedir)s has changed since"
1672
_fmt = ("The working tree for %(basedir)s has changed since"
1393
1673
" the last commit, but weave merge requires that it be"
1546
1832
_fmt = "Moving the root directory is not supported at this time"
1549
class TransformRenameFailed(BzrError):
1551
_fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
1553
def __init__(self, from_path, to_path, why, errno):
1554
self.from_path = from_path
1555
self.to_path = to_path
1560
1835
class BzrMoveFailedError(BzrError):
1562
_fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1563
"%(_has_extra)s%(extra)s")
1837
_fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1565
1839
def __init__(self, from_path='', to_path='', extra=None):
1566
from breezy.osutils import splitpath
1567
1840
BzrError.__init__(self)
1569
self.extra, self._has_extra = extra, ': '
1842
self.extra = ': ' + str(extra)
1571
self.extra = self._has_extra = ''
1573
1846
has_from = len(from_path) > 0
1574
1847
has_to = len(to_path) > 0
1576
self.from_path = splitpath(from_path)[-1]
1849
self.from_path = osutils.splitpath(from_path)[-1]
1578
1851
self.from_path = ''
1581
self.to_path = splitpath(to_path)[-1]
1854
self.to_path = osutils.splitpath(to_path)[-1]
1583
1856
self.to_path = ''
1596
1869
class BzrRenameFailedError(BzrMoveFailedError):
1598
_fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1599
"%(_has_extra)s%(extra)s")
1871
_fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
1601
1873
def __init__(self, from_path, to_path, extra=None):
1602
1874
BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1876
class BzrRemoveChangedFilesError(BzrError):
1877
"""Used when user is trying to remove changed files."""
1879
_fmt = ("Can't safely remove modified or unknown files:\n"
1880
"%(changes_as_text)s"
1881
"Use --keep to not delete them, or --force to delete them regardless.")
1883
def __init__(self, tree_delta):
1884
BzrError.__init__(self)
1885
self.changes_as_text = tree_delta.get_changes_as_text()
1886
#self.paths_as_string = '\n'.join(changed_files)
1887
#self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
1605
1890
class BzrBadParameterNotString(BzrBadParameter):
1820
2105
_fmt = "To use this feature you must upgrade your repository at %(path)s."
1823
class RichRootUpgradeRequired(UpgradeRequired):
1825
_fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1826
" a format which supports rich roots.")
1829
2108
class LocalRequiresBoundBranch(BzrError):
1831
2110
_fmt = "Cannot perform local-only commits on unbound branches."
2113
class MissingProgressBarFinish(BzrError):
2115
_fmt = "A nested progress bar was not 'finished' correctly."
2118
class InvalidProgressBarType(BzrError):
2120
_fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
2121
" is not a supported type Select one of: %(valid_types)s")
2123
def __init__(self, bar_type, valid_types):
2124
BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1834
2127
class UnsupportedOperation(BzrError):
1836
2129
_fmt = ("The method %(mname)s is not supported on"
1908
2189
self.text = text
1911
class MalformedHeader(BadBundle):
2192
class MalformedHeader(BadBundle):
1913
2194
_fmt = "Malformed bzr revision-bundle header: %(text)r"
1916
class MalformedPatches(BadBundle):
2197
class MalformedPatches(BadBundle):
1918
2199
_fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1921
class MalformedFooter(BadBundle):
2202
class MalformedFooter(BadBundle):
1923
2204
_fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1926
2207
class UnsupportedEOLMarker(BadBundle):
1928
_fmt = "End of line marker was not \\n in bzr revision-bundle"
2209
_fmt = "End of line marker was not \\n in bzr revision-bundle"
1930
2211
def __init__(self):
1931
# XXX: BadBundle's constructor assumes there's explanatory text,
2212
# XXX: BadBundle's constructor assumes there's explanatory text,
1932
2213
# but for this there is not
1933
2214
BzrError.__init__(self)
1936
2217
class IncompatibleBundleFormat(BzrError):
1938
2219
_fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1940
2221
def __init__(self, bundle_format, other):
2169
2482
self.error_args = error_tuple[1:]
2172
class UnknownErrorFromSmartServer(BzrError):
2173
"""An ErrorFromSmartServer could not be translated into a typical breezy
2176
This is distinct from ErrorFromSmartServer so that it is possible to
2177
distinguish between the following two cases:
2179
- ErrorFromSmartServer was uncaught. This is logic error in the client
2180
and so should provoke a traceback to the user.
2181
- ErrorFromSmartServer was caught but its error_tuple could not be
2182
translated. This is probably because the server sent us garbage, and
2183
should not provoke a traceback.
2186
_fmt = "Server sent an unexpected error: %(error_tuple)r"
2188
internal_error = False
2190
def __init__(self, error_from_smart_server):
2193
:param error_from_smart_server: An ErrorFromSmartServer instance.
2195
self.error_from_smart_server = error_from_smart_server
2196
self.error_tuple = error_from_smart_server.error_tuple
2199
2485
class ContainerError(BzrError):
2200
2486
"""Base class of container errors."""
2253
2544
self.reason = reason
2547
class SMTPError(BzrError):
2549
_fmt = "SMTP error: %(error)s"
2551
def __init__(self, error):
2555
class NoMessageSupplied(BzrError):
2557
_fmt = "No message supplied."
2560
class NoMailAddressSpecified(BzrError):
2562
_fmt = "No mail-to address specified."
2565
class UnknownMailClient(BzrError):
2567
_fmt = "Unknown mail client: %(mail_client)s"
2569
def __init__(self, mail_client):
2570
BzrError.__init__(self, mail_client=mail_client)
2573
class MailClientNotFound(BzrError):
2575
_fmt = "Unable to find mail client with the following names:"\
2576
" %(mail_command_list_string)s"
2578
def __init__(self, mail_command_list):
2579
mail_command_list_string = ', '.join(mail_command_list)
2580
BzrError.__init__(self, mail_command_list=mail_command_list,
2581
mail_command_list_string=mail_command_list_string)
2583
class SMTPConnectionRefused(SMTPError):
2585
_fmt = "SMTP connection to %(host)s refused"
2587
def __init__(self, error, host):
2592
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2594
_fmt = "Please specify smtp_server. No server at default %(host)s."
2597
class BzrDirError(BzrError):
2599
def __init__(self, bzrdir):
2600
import bzrlib.urlutils as urlutils
2601
display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
2603
BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2606
class UnsyncedBranches(BzrDirError):
2608
_fmt = ("'%(display_url)s' is not in sync with %(target_url)s. See"
2609
" bzr help sync-for-reconfigure.")
2611
def __init__(self, bzrdir, target_branch):
2612
BzrDirError.__init__(self, bzrdir)
2613
import bzrlib.urlutils as urlutils
2614
self.target_url = urlutils.unescape_for_display(target_branch.base,
2618
class AlreadyBranch(BzrDirError):
2620
_fmt = "'%(display_url)s' is already a branch."
2623
class AlreadyTree(BzrDirError):
2625
_fmt = "'%(display_url)s' is already a tree."
2628
class AlreadyCheckout(BzrDirError):
2630
_fmt = "'%(display_url)s' is already a checkout."
2633
class AlreadyLightweightCheckout(BzrDirError):
2635
_fmt = "'%(display_url)s' is already a lightweight checkout."
2638
class AlreadyUsingShared(BzrDirError):
2640
_fmt = "'%(display_url)s' is already using a shared repository."
2643
class AlreadyStandalone(BzrDirError):
2645
_fmt = "'%(display_url)s' is already standalone."
2648
class ReconfigurationNotSupported(BzrDirError):
2650
_fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2653
class NoBindLocation(BzrDirError):
2655
_fmt = "No location could be found to bind to at %(display_url)s."
2256
2658
class UncommittedChanges(BzrError):
2258
_fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2259
' (See brz status).%(more)s')
2261
def __init__(self, tree, more=None):
2266
import breezy.urlutils as urlutils
2267
user_url = getattr(tree, "user_url", None)
2268
if user_url is None:
2269
display_url = str(tree)
2271
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2272
BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2275
class StoringUncommittedNotSupported(BzrError):
2277
_fmt = ('Branch "%(display_url)s" does not support storing uncommitted'
2280
def __init__(self, branch):
2281
import breezy.urlutils as urlutils
2282
user_url = getattr(branch, "user_url", None)
2283
if user_url is None:
2284
display_url = str(branch)
2286
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2287
BzrError.__init__(self, branch=branch, display_url=display_url)
2290
class ShelvedChanges(UncommittedChanges):
2292
_fmt = ('Working tree "%(display_url)s" has shelved changes'
2293
' (See brz shelve --list).%(more)s')
2660
_fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2662
def __init__(self, tree):
2663
import bzrlib.urlutils as urlutils
2664
display_url = urlutils.unescape_for_display(
2665
tree.bzrdir.root_transport.base, 'ascii')
2666
BzrError.__init__(self, tree=tree, display_url=display_url)
2669
class MissingTemplateVariable(BzrError):
2671
_fmt = 'Variable {%(name)s} is not available.'
2673
def __init__(self, name):
2677
class NoTemplate(BzrError):
2679
_fmt = 'No template specified.'
2296
2682
class UnableCreateSymlink(BzrError):
2308
2694
self.path_str = path_str
2697
class UnsupportedTimezoneFormat(BzrError):
2699
_fmt = ('Unsupported timezone format "%(timezone)s", '
2700
'options are "utc", "original", "local".')
2702
def __init__(self, timezone):
2703
self.timezone = timezone
2706
class CommandAvailableInPlugin(StandardError):
2708
internal_error = False
2710
def __init__(self, cmd_name, plugin_metadata, provider):
2712
self.plugin_metadata = plugin_metadata
2713
self.cmd_name = cmd_name
2714
self.provider = provider
2718
_fmt = ('"%s" is not a standard bzr command. \n'
2719
'However, the following official plugin provides this command: %s\n'
2720
'You can install it by going to: %s'
2721
% (self.cmd_name, self.plugin_metadata['name'],
2722
self.plugin_metadata['url']))
2727
class NoPluginAvailable(BzrError):
2731
class NotATerminal(BzrError):
2733
_fmt = 'Unable to ask for a password without real terminal.'
2311
2736
class UnableEncodePath(BzrError):
2313
2738
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2314
2739
'user encoding %(user_encoding)s')
2316
2741
def __init__(self, path, kind):
2317
from breezy.osutils import get_user_encoding
2318
2742
self.path = path
2319
2743
self.kind = kind
2320
self.user_encoding = get_user_encoding()
2744
self.user_encoding = osutils.get_user_encoding()
2323
2747
class NoSuchAlias(BzrError):
2328
2752
BzrError.__init__(self, alias_name=alias_name)
2755
class DirectoryLookupFailure(BzrError):
2756
"""Base type for lookup errors."""
2761
class InvalidLocationAlias(DirectoryLookupFailure):
2763
_fmt = '"%(alias_name)s" is not a valid location alias.'
2765
def __init__(self, alias_name):
2766
DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2769
class UnsetLocationAlias(DirectoryLookupFailure):
2771
_fmt = 'No %(alias_name)s location assigned.'
2773
def __init__(self, alias_name):
2774
DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2331
2777
class CannotBindAddress(BzrError):
2333
2779
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2335
2781
def __init__(self, host, port, orig_error):
2336
# nb: in python2.4 socket.error doesn't have a useful repr
2337
2782
BzrError.__init__(self, host=host, port=port,
2338
orig_error=repr(orig_error.args))
2341
class TipChangeRejected(BzrError):
2342
"""A pre_change_branch_tip hook function may raise this to cleanly and
2343
explicitly abort a change to a branch tip.
2346
_fmt = u"Tip change rejected: %(msg)s"
2348
def __init__(self, msg):
2352
class JailBreak(BzrError):
2354
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
2356
def __init__(self, url):
2357
BzrError.__init__(self, url=url)
2360
class UserAbort(BzrError):
2362
_fmt = 'The user aborted the operation.'
2365
class UnresumableWriteGroup(BzrError):
2367
_fmt = ("Repository %(repository)s cannot resume write group "
2368
"%(write_groups)r: %(reason)s")
2370
internal_error = True
2372
def __init__(self, repository, write_groups, reason):
2373
self.repository = repository
2374
self.write_groups = write_groups
2375
self.reason = reason
2378
class UnsuspendableWriteGroup(BzrError):
2380
_fmt = ("Repository %(repository)s cannot suspend a write group.")
2382
internal_error = True
2384
def __init__(self, repository):
2385
self.repository = repository
2388
class LossyPushToSameVCS(BzrError):
2390
_fmt = ("Lossy push not possible between %(source_branch)r and "
2391
"%(target_branch)r that are in the same VCS.")
2393
internal_error = True
2395
def __init__(self, source_branch, target_branch):
2396
self.source_branch = source_branch
2397
self.target_branch = target_branch
2400
class NoRoundtrippingSupport(BzrError):
2402
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
2403
"%(target_branch)r.")
2405
internal_error = True
2407
def __init__(self, source_branch, target_branch):
2408
self.source_branch = source_branch
2409
self.target_branch = target_branch
2412
class NoColocatedBranchSupport(BzrError):
2414
_fmt = ("%(controldir)r does not support co-located branches.")
2416
def __init__(self, controldir):
2417
self.controldir = controldir
2420
class RecursiveBind(BzrError):
2422
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2423
'Please use `brz unbind` to fix.')
2425
def __init__(self, branch_url):
2426
self.branch_url = branch_url
2429
class UnsupportedKindChange(BzrError):
2431
_fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
2432
"%(path)s not supported by format %(format)r")
2434
def __init__(self, path, from_kind, to_kind, format):
2436
self.from_kind = from_kind
2437
self.to_kind = to_kind
2438
self.format = format
2441
class ChangesAlreadyStored(BzrCommandError):
2443
_fmt = ('Cannot store uncommitted changes because this branch already'
2444
' stores uncommitted changes.')
2783
orig_error=orig_error[1])
2786
class UnknownRules(BzrError):
2788
_fmt = ('Unknown rules detected: %(unknowns_str)s.')
2790
def __init__(self, unknowns):
2791
BzrError.__init__(self, unknowns_str=", ".join(unknowns))