81
87
for key, value in kwds.items():
82
88
setattr(self, key, value)
85
91
s = getattr(self, '_preformatted_string', None)
87
# contains a preformatted message
93
# contains a preformatted message; must be cast to plain str
91
96
fmt = self._get_format_string()
93
d = dict(self.__dict__)
98
s = fmt % self.__dict__
95
99
# __str__() should always return a 'str' object
96
100
# never a 'unicode' object.
101
if isinstance(s, unicode):
102
return s.encode('utf8')
98
except Exception as e:
100
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
104
except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
105
return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
106
% (self.__class__.__name__,
108
getattr(self, '_fmt', None),
111
def _get_format_string(self):
112
"""Return format string for this exception or None"""
113
fmt = getattr(self, '_fmt', None)
116
fmt = getattr(self, '__doc__', None)
118
symbol_versioning.warn("%s uses its docstring as a format, "
119
"it should use _fmt instead" % self.__class__.__name__,
122
return 'Unprintable exception %s: dict=%r, fmt=%r' \
101
123
% (self.__class__.__name__,
103
125
getattr(self, '_fmt', None),
109
return '%s(%s)' % (self.__class__.__name__, str(self))
111
def _get_format_string(self):
112
"""Return format string for this exception or None"""
113
fmt = getattr(self, '_fmt', None)
115
from breezy.i18n import gettext
116
return gettext(fmt) # _fmt strings should be ascii
118
def __eq__(self, other):
119
if self.__class__ is not other.__class__:
120
return NotImplemented
121
return self.__dict__ == other.__dict__
127
class InternalBzrError(BzrError):
128
"""Base class for errors that are internal in nature.
130
This is a convenience class for errors that are internal. The
131
internal_error attribute can still be altered in subclasses, if needed.
132
Using this class is simply an easy way to get internal errors.
135
internal_error = True
138
class BranchError(BzrError):
139
"""Base class for concrete 'errors about a branch'."""
141
def __init__(self, branch):
142
BzrError.__init__(self, branch=branch)
145
class BzrCheckError(InternalBzrError):
147
_fmt = "Internal check failed: %(msg)s"
149
def __init__(self, msg):
150
BzrError.__init__(self)
154
class IncompatibleVersion(BzrError):
156
_fmt = 'API %(api)s is not compatible; one of versions %(wanted)r '\
157
'is required, but current version is %(current)r.'
159
def __init__(self, api, wanted, current):
162
self.current = current
165
class InProcessTransport(BzrError):
167
_fmt = "The transport '%(transport)s' is only accessible within this " \
170
def __init__(self, transport):
171
self.transport = transport
129
class BzrNewError(BzrError):
130
"""Deprecated error base class."""
131
# base classes should override the docstring with their human-
132
# readable explanation
134
def __init__(self, *args, **kwds):
135
# XXX: Use the underlying BzrError to always generate the args
136
# attribute if it doesn't exist. We can't use super here, because
137
# exceptions are old-style classes in python2.4 (but new in 2.5).
139
symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
140
'please convert %s to use BzrError instead'
141
% self.__class__.__name__,
144
BzrError.__init__(self, *args)
145
for key, value in kwds.items():
146
setattr(self, key, value)
150
# __str__() should always return a 'str' object
151
# never a 'unicode' object.
152
s = self.__doc__ % self.__dict__
153
if isinstance(s, unicode):
154
return s.encode('utf8')
156
except (TypeError, NameError, ValueError, KeyError), e:
157
return 'Unprintable exception %s(%r): %s' \
158
% (self.__class__.__name__,
159
self.__dict__, str(e))
162
class AlreadyBuilding(BzrError):
164
_fmt = "The tree builder is already building a tree."
167
class BzrCheckError(BzrError):
169
_fmt = "Internal check failed: %(message)s"
171
internal_error = True
173
def __init__(self, message):
174
BzrError.__init__(self)
175
self.message = message
178
class DisabledMethod(BzrError):
180
_fmt = "The smart server method '%(class_name)s' is disabled."
182
internal_error = True
184
def __init__(self, class_name):
185
BzrError.__init__(self)
186
self.class_name = class_name
189
class InvalidEntryName(BzrError):
191
_fmt = "Invalid entry name: %(name)s"
193
internal_error = True
195
def __init__(self, name):
196
BzrError.__init__(self)
174
200
class InvalidRevisionNumber(BzrError):
176
202
_fmt = "Invalid revision number %(revno)s"
178
204
def __init__(self, revno):
340
369
class NotADirectory(PathError):
342
_fmt = '"%(path)s" is not a directory %(extra)s'
371
_fmt = "%(path)r is not a directory %(extra)s"
345
374
class NotInWorkingDirectory(PathError):
347
_fmt = '"%(path)s" is not in the working directory %(extra)s'
376
_fmt = "%(path)r is not in the working directory %(extra)s"
350
379
class DirectoryNotEmpty(PathError):
352
_fmt = 'Directory not empty: "%(path)s"%(extra)s'
355
class HardLinkNotSupported(PathError):
357
_fmt = 'Hard-linking "%(path)s" is not supported'
360
class ReadingCompleted(InternalBzrError):
381
_fmt = "Directory not empty: %(path)r%(extra)s"
384
class ReadingCompleted(BzrError):
362
386
_fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
363
387
"called upon it - the request has been completed and no more "
364
388
"data may be read.")
390
internal_error = True
366
392
def __init__(self, request):
367
393
self.request = request
370
396
class ResourceBusy(PathError):
372
_fmt = 'Device or resource busy: "%(path)s"%(extra)s'
398
_fmt = "Device or resource busy: %(path)r%(extra)s"
375
401
class PermissionDenied(PathError):
377
_fmt = 'Permission denied: "%(path)s"%(extra)s'
403
_fmt = "Permission denied: %(path)r%(extra)s"
406
class InvalidURL(PathError):
408
_fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
411
class InvalidURLJoin(PathError):
413
_fmt = "Invalid URL join request: %(args)s%(extra)s"
415
def __init__(self, msg, base, args):
416
PathError.__init__(self, base, msg)
417
self.args = [base] + list(args)
420
class UnknownHook(BzrError):
422
_fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
424
def __init__(self, hook_type, hook_name):
425
BzrError.__init__(self)
426
self.type = hook_type
427
self.hook = hook_name
380
430
class UnsupportedProtocol(PathError):
382
432
_fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
384
def __init__(self, url, extra=""):
434
def __init__(self, url, extra):
385
435
PathError.__init__(self, url, extra=extra)
388
class UnstackableLocationError(BzrError):
390
_fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
392
def __init__(self, branch_url, target_url):
393
BzrError.__init__(self)
394
self.branch_url = branch_url
395
self.target_url = target_url
398
class UnstackableRepositoryFormat(BzrError):
400
_fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
401
"You will need to upgrade the repository to permit branch stacking.")
403
def __init__(self, format, url):
404
BzrError.__init__(self)
409
class ReadError(PathError):
411
_fmt = """Error reading from %(path)r."""
414
438
class ShortReadvError(PathError):
416
_fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
417
' at %(offset)s for "%(path)s"%(extra)s')
440
_fmt = ("readv() read %(actual)s bytes rather than %(length)s bytes"
441
" at %(offset)s for %(path)s%(extra)s")
419
443
internal_error = True
444
468
class InvalidNormalization(PathError):
446
_fmt = 'Path "%(path)s" is not unicode normalized'
470
_fmt = "Path %(path)r is not unicode normalized"
449
473
# TODO: This is given a URL; we try to unescape it but doing that from inside
450
474
# the exception object is a bit undesirable.
451
# TODO: Probably this behavior of should be a common superclass
475
# TODO: Probably this behavior of should be a common superclass
452
476
class NotBranchError(PathError):
454
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
456
def __init__(self, path, detail=None, controldir=None):
457
from . import urlutils
458
path = urlutils.unescape_for_display(path, 'ascii')
459
if detail is not None:
460
detail = ': ' + detail
462
self.controldir = controldir
463
PathError.__init__(self, path=path)
466
return '<%s %r>' % (self.__class__.__name__, self.__dict__)
468
def _get_format_string(self):
469
# GZ 2017-06-08: Not the best place to lazy fill detail in.
470
if self.detail is None:
471
self.detail = self._get_detail()
472
return super(NotBranchError, self)._get_format_string()
474
def _get_detail(self):
475
if self.controldir is not None:
477
self.controldir.open_repository()
478
except NoRepositoryPresent:
480
except Exception as e:
481
# Just ignore unexpected errors. Raising arbitrary errors
482
# during str(err) can provoke strange bugs. Concretely
483
# Launchpad's codehosting managed to raise NotBranchError
484
# here, and then get stuck in an infinite loop/recursion
485
# trying to str() that error. All this error really cares
486
# about that there's no working repository there, and if
487
# open_repository() fails, there probably isn't.
488
return ': ' + e.__class__.__name__
490
return ': location is a repository'
478
_fmt = "Not a branch: %(path)s"
480
def __init__(self, path):
481
import bzrlib.urlutils as urlutils
482
self.path = urlutils.unescape_for_display(path, 'ascii')
494
485
class NoSubmitBranch(PathError):
496
487
_fmt = 'No submit branch available for branch "%(path)s"'
498
489
def __init__(self, branch):
499
from . import urlutils
500
self.path = urlutils.unescape_for_display(branch.base, 'ascii')
503
class AlreadyControlDirError(PathError):
505
_fmt = 'A control directory already exists: "%(path)s".'
490
import bzrlib.urlutils as urlutils
491
self.path = urlutils.unescape_for_display(branch.base, 'ascii')
508
494
class AlreadyBranchError(PathError):
510
_fmt = 'Already a branch: "%(path)s".'
513
class InvalidBranchName(PathError):
515
_fmt = "Invalid branch name: %(name)s"
517
def __init__(self, name):
518
BzrError.__init__(self)
522
class ParentBranchExists(AlreadyBranchError):
524
_fmt = 'Parent branch already exists: "%(path)s".'
496
_fmt = "Already a branch: %(path)s."
527
499
class BranchExistsWithoutWorkingTree(PathError):
529
_fmt = 'Directory contains a branch, but no working tree \
530
(use brz checkout if you wish to build a working tree): "%(path)s"'
501
_fmt = "Directory contains a branch, but no working tree \
502
(use bzr checkout if you wish to build a working tree): %(path)s"
505
class AtomicFileAlreadyClosed(PathError):
507
_fmt = ("'%(function)s' called on an AtomicFile after it was closed:"
510
def __init__(self, path, function):
511
PathError.__init__(self, path=path, extra=None)
512
self.function = function
533
515
class InaccessibleParent(PathError):
535
_fmt = ('Parent not accessible given base "%(base)s" and'
536
' relative path "%(path)s"')
517
_fmt = ("Parent not accessible given base %(base)s and"
518
" relative path %(path)s")
538
520
def __init__(self, path, base):
539
521
PathError.__init__(self, path)
543
525
class NoRepositoryPresent(BzrError):
545
_fmt = 'No repository present: "%(path)s"'
547
def __init__(self, controldir):
548
BzrError.__init__(self)
549
self.path = controldir.transport.clone('..').base
527
_fmt = "No repository present: %(path)r"
528
def __init__(self, bzrdir):
529
BzrError.__init__(self)
530
self.path = bzrdir.transport.clone('..').base
533
class FileInWrongBranch(BzrError):
535
_fmt = "File %(path)s in not in branch %(branch_base)s."
537
def __init__(self, branch, path):
538
BzrError.__init__(self)
540
self.branch_base = branch.base
552
544
class UnsupportedFormatError(BzrError):
554
_fmt = "Unsupported branch format: %(format)s\nPlease run 'brz upgrade'"
546
_fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
557
549
class UnknownFormatError(BzrError):
559
_fmt = "Unknown %(kind)s format: %(format)r"
561
def __init__(self, format, kind='branch'):
551
_fmt = "Unknown branch format: %(format)r"
566
554
class IncompatibleFormat(BzrError):
568
_fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
570
def __init__(self, format, controldir_format):
571
BzrError.__init__(self)
573
self.controldir = controldir_format
576
class ParseFormatError(BzrError):
578
_fmt = "Parse error on line %(lineno)d of %(format)s format: %(line)s"
580
def __init__(self, format, lineno, line, text):
581
BzrError.__init__(self)
556
_fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
558
def __init__(self, format, bzrdir_format):
559
BzrError.__init__(self)
561
self.bzrdir = bzrdir_format
588
564
class IncompatibleRepositories(BzrError):
589
"""Report an error that two repositories are not compatible.
591
Note that the source and target repositories are permitted to be strings:
592
this exception is thrown from the smart server and may refer to a
593
repository the client hasn't opened.
596
_fmt = "%(target)s\n" \
597
"is not compatible with\n" \
601
def __init__(self, source, target, details=None):
603
details = "(no details)"
604
BzrError.__init__(self, target=target, source=source, details=details)
566
_fmt = "Repository %(target)s is not compatible with repository"\
569
def __init__(self, source, target):
570
BzrError.__init__(self, target=target, source=source)
607
573
class IncompatibleRevision(BzrError):
609
575
_fmt = "Revision is not compatible with %(repo_format)s"
611
577
def __init__(self, repo_format):
930
896
self.revision_id = revision_id
899
class InvalidRevisionSpec(BzrError):
901
_fmt = ("Requested revision: %(spec)r does not exist in branch:"
902
" %(branch)s%(extra)s")
904
def __init__(self, spec, branch, extra=None):
905
BzrError.__init__(self, branch=branch, spec=spec)
907
self.extra = '\n' + str(extra)
912
class HistoryMissing(BzrError):
914
_fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
933
917
class AppendRevisionsOnlyViolation(BzrError):
935
919
_fmt = ('Operation denied because it would change the main history,'
936
' which is not permitted by the append_revisions_only setting on'
937
' branch "%(location)s".')
920
' which is not permitted by the append_revisions_only setting on'
921
' branch "%(location)s".')
939
923
def __init__(self, location):
940
import breezy.urlutils as urlutils
941
location = urlutils.unescape_for_display(location, 'ascii')
942
BzrError.__init__(self, location=location)
924
import bzrlib.urlutils as urlutils
925
location = urlutils.unescape_for_display(location, 'ascii')
926
BzrError.__init__(self, location=location)
945
929
class DivergedBranches(BzrError):
947
931
_fmt = ("These branches have diverged."
948
" Use the missing command to see how.\n"
949
"Use the merge command to reconcile them.")
932
" Use the merge command to reconcile them.")
934
internal_error = False
951
936
def __init__(self, branch1, branch2):
952
937
self.branch1 = branch1
953
938
self.branch2 = branch2
956
class NotLefthandHistory(InternalBzrError):
941
class NotLefthandHistory(BzrError):
958
943
_fmt = "Supplied history does not follow left-hand parents"
945
internal_error = True
960
947
def __init__(self, history):
961
948
BzrError.__init__(self, history=history)
1062
1068
self.error = error
1071
class WeaveError(BzrError):
1073
_fmt = "Error in processing weave: %(message)s"
1075
def __init__(self, message=None):
1076
BzrError.__init__(self)
1077
self.message = message
1080
class WeaveRevisionAlreadyPresent(WeaveError):
1082
_fmt = "Revision {%(revision_id)s} already present in %(weave)s"
1084
def __init__(self, revision_id, weave):
1086
WeaveError.__init__(self)
1087
self.revision_id = revision_id
1091
class WeaveRevisionNotPresent(WeaveError):
1093
_fmt = "Revision {%(revision_id)s} not present in %(weave)s"
1095
def __init__(self, revision_id, weave):
1096
WeaveError.__init__(self)
1097
self.revision_id = revision_id
1101
class WeaveFormatError(WeaveError):
1103
_fmt = "Weave invariant violated: %(what)s"
1105
def __init__(self, what):
1106
WeaveError.__init__(self)
1110
class WeaveParentMismatch(WeaveError):
1112
_fmt = "Parents are mismatched between two revisions."
1115
class WeaveInvalidChecksum(WeaveError):
1117
_fmt = "Text did not match it's checksum: %(message)s"
1120
class WeaveTextDiffers(WeaveError):
1122
_fmt = ("Weaves differ on text content. Revision:"
1123
" {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
1125
def __init__(self, revision_id, weave_a, weave_b):
1126
WeaveError.__init__(self)
1127
self.revision_id = revision_id
1128
self.weave_a = weave_a
1129
self.weave_b = weave_b
1132
class WeaveTextDiffers(WeaveError):
1134
_fmt = ("Weaves differ on text content. Revision:"
1135
" {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
1137
def __init__(self, revision_id, weave_a, weave_b):
1138
WeaveError.__init__(self)
1139
self.revision_id = revision_id
1140
self.weave_a = weave_a
1141
self.weave_b = weave_b
1065
1144
class VersionedFileError(BzrError):
1067
1146
_fmt = "Versioned file error"
1070
1149
class RevisionNotPresent(VersionedFileError):
1072
_fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1151
_fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
1074
1153
def __init__(self, revision_id, file_id):
1075
1154
VersionedFileError.__init__(self)
1087
1166
self.file_id = file_id
1090
class VersionedFileInvalidChecksum(VersionedFileError):
1092
_fmt = "Text did not match its checksum: %(msg)s"
1095
class RetryWithNewPacks(BzrError):
1096
"""Raised when we realize that the packs on disk have changed.
1098
This is meant as more of a signaling exception, to trap between where a
1099
local error occurred and the code that can actually handle the error and
1100
code that can retry appropriately.
1103
internal_error = True
1105
_fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1108
def __init__(self, context, reload_occurred, exc_info):
1109
"""create a new RetryWithNewPacks error.
1111
:param reload_occurred: Set to True if we know that the packs have
1112
already been reloaded, and we are failing because of an in-memory
1113
cache miss. If set to True then we will ignore if a reload says
1114
nothing has changed, because we assume it has already reloaded. If
1115
False, then a reload with nothing changed will force an error.
1116
:param exc_info: The original exception traceback, so if there is a
1117
problem we can raise the original error (value from sys.exc_info())
1119
BzrError.__init__(self)
1120
self.context = context
1121
self.reload_occurred = reload_occurred
1122
self.exc_info = exc_info
1123
self.orig_error = exc_info[1]
1124
# TODO: The global error handler should probably treat this by
1125
# raising/printing the original exception with a bit about
1126
# RetryWithNewPacks also not being caught
1129
class RetryAutopack(RetryWithNewPacks):
1130
"""Raised when we are autopacking and we find a missing file.
1132
Meant as a signaling exception, to tell the autopack code it should try
1136
internal_error = True
1138
_fmt = ("Pack files have changed, reload and try autopack again."
1139
" context: %(context)s %(orig_error)s")
1169
class KnitError(BzrError):
1173
internal_error = True
1176
class KnitHeaderError(KnitError):
1178
_fmt = "Knit header error: %(badline)r unexpected for file %(filename)s"
1180
def __init__(self, badline, filename):
1181
KnitError.__init__(self)
1182
self.badline = badline
1183
self.filename = filename
1186
class KnitCorrupt(KnitError):
1188
_fmt = "Knit %(filename)s corrupt: %(how)s"
1190
def __init__(self, filename, how):
1191
KnitError.__init__(self)
1192
self.filename = filename
1196
class KnitIndexUnknownMethod(KnitError):
1197
"""Raised when we don't understand the storage method.
1199
Currently only 'fulltext' and 'line-delta' are supported.
1202
_fmt = ("Knit index %(filename)s does not have a known method"
1203
" in options: %(options)r")
1205
def __init__(self, filename, options):
1206
KnitError.__init__(self)
1207
self.filename = filename
1208
self.options = options
1142
1211
class NoSuchExportFormat(BzrError):
1144
1213
_fmt = "Export format %(format)r not supported"
1146
1215
def __init__(self, format):
1243
1283
self.port = ':%s' % port
1246
# XXX: This is also used for unexpected end of file, which is different at the
1247
# TCP level from "connection reset".
1248
1286
class ConnectionReset(TransportError):
1250
1288
_fmt = "Connection closed: %(msg)s %(orig_error)s"
1253
class ConnectionTimeout(ConnectionError):
1255
_fmt = "Connection Timeout: %(msg)s%(orig_error)s"
1258
1291
class InvalidRange(TransportError):
1260
_fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1262
def __init__(self, path, offset, msg=None):
1263
TransportError.__init__(self, msg)
1293
_fmt = "Invalid range access in %(path)s at %(offset)s."
1295
def __init__(self, path, offset):
1296
TransportError.__init__(self, ("Invalid range access in %s at %d"
1264
1298
self.path = path
1265
1299
self.offset = offset
1268
1302
class InvalidHttpResponse(TransportError):
1270
_fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
1304
_fmt = "Invalid http response for %(path)s: %(msg)s"
1272
1306
def __init__(self, path, msg, orig_error=None):
1273
1307
self.path = path
1274
if orig_error is None:
1277
# This is reached for obscure and unusual errors so we want to
1278
# preserve as much info as possible to ease debug.
1279
orig_error = ': %r' % (orig_error,)
1280
1308
TransportError.__init__(self, msg, orig_error=orig_error)
1283
class UnexpectedHttpStatus(InvalidHttpResponse):
1285
_fmt = "Unexpected HTTP status %(code)d for %(path)s: %(extra)s"
1287
def __init__(self, path, code, extra=None):
1290
self.extra = extra or ''
1291
full_msg = 'status code %d unexpected' % code
1292
if extra is not None:
1293
full_msg += ': ' + extra
1294
InvalidHttpResponse.__init__(
1295
self, path, full_msg)
1298
class BadHttpRequest(UnexpectedHttpStatus):
1300
_fmt = "Bad http request for %(path)s: %(reason)s"
1302
def __init__(self, path, reason):
1304
self.reason = reason
1305
TransportError.__init__(self, reason)
1308
1311
class InvalidHttpRange(InvalidHttpResponse):
1310
1313
_fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1312
1315
def __init__(self, path, range, msg):
1313
1316
self.range = range
1314
1317
InvalidHttpResponse.__init__(self, path, msg)
1317
class HttpBoundaryMissing(InvalidHttpResponse):
1318
"""A multipart response ends with no boundary marker.
1320
This is a special case caused by buggy proxies, described in
1321
<https://bugs.launchpad.net/bzr/+bug/198646>.
1324
_fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
1326
def __init__(self, path, msg):
1327
InvalidHttpResponse.__init__(self, path, msg)
1330
1320
class InvalidHttpContentType(InvalidHttpResponse):
1332
1322
_fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1334
1324
def __init__(self, path, ctype, msg):
1335
1325
self.ctype = ctype
1336
1326
InvalidHttpResponse.__init__(self, path, msg)
1341
1331
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1343
def __init__(self, source, target, is_permanent=False):
1333
def __init__(self, source, target, is_permament=False, qual_proto=None):
1344
1334
self.source = source
1345
1335
self.target = target
1347
1337
self.permanently = ' permanently'
1349
1339
self.permanently = ''
1340
self.is_permament = is_permament
1341
self._qualified_proto = qual_proto
1350
1342
TransportError.__init__(self)
1344
def _requalify_url(self, url):
1345
"""Restore the qualified proto in front of the url"""
1346
# When this exception is raised, source and target are in
1347
# user readable format. But some transports may use a
1348
# different proto (http+urllib:// will present http:// to
1349
# the user. If a qualified proto is specified, the code
1350
# trapping the exception can get the qualified urls to
1351
# properly handle the redirection themself (creating a
1352
# new transport object from the target url for example).
1353
# But checking that the scheme of the original and
1354
# redirected urls are the same can be tricky. (see the
1355
# FIXME in BzrDir.open_from_transport for the unique use
1357
if self._qualified_proto is None:
1360
# The TODO related to NotBranchError mention that doing
1361
# that kind of manipulation on the urls may not be the
1362
# exception object job. On the other hand, this object is
1363
# the interface between the code and the user so
1364
# presenting the urls in different ways is indeed its
1367
proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1368
return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1371
def get_source_url(self):
1372
return self._requalify_url(self.source)
1374
def get_target_url(self):
1375
return self._requalify_url(self.target)
1353
1378
class TooManyRedirections(TransportError):
1355
1380
_fmt = "Too many redirections"
1358
1382
class ConflictsInTree(BzrError):
1360
1384
_fmt = "Working tree has conflicts."
1363
class DependencyNotPresent(BzrError):
1365
_fmt = 'Unable to import library "%(library)s": %(error)s'
1367
def __init__(self, library, error):
1368
BzrError.__init__(self, library=library, error=error)
1387
class ParseConfigError(BzrError):
1389
def __init__(self, errors, filename):
1390
if filename is None:
1392
message = "Error(s) parsing config file %s:\n%s" % \
1393
(filename, ('\n'.join(e.message for e in errors)))
1394
BzrError.__init__(self, message)
1397
class NoEmailInUsername(BzrError):
1399
_fmt = "%(username)r does not seem to contain a reasonable email address"
1401
def __init__(self, username):
1402
BzrError.__init__(self)
1403
self.username = username
1406
class SigningFailed(BzrError):
1408
_fmt = "Failed to gpg sign data with command %(command_line)r"
1410
def __init__(self, command_line):
1411
BzrError.__init__(self, command_line=command_line)
1371
1414
class WorkingTreeNotRevision(BzrError):
1373
_fmt = ("The working tree for %(basedir)s has changed since"
1416
_fmt = ("The working tree for %(basedir)s has changed since"
1374
1417
" the last commit, but weave merge requires that it be"
1624
1695
_fmt = """This tree contains left-over files from a failed operation.
1625
1696
Please examine %(limbo_dir)s to see if it contains any files you wish to
1626
1697
keep, and delete it when you are done."""
1628
def __init__(self, limbo_dir):
1629
BzrError.__init__(self)
1630
self.limbo_dir = limbo_dir
1633
class ExistingPendingDeletion(BzrError):
1635
_fmt = """This tree contains left-over files from a failed operation.
1636
Please examine %(pending_deletion)s to see if it contains any files you
1637
wish to keep, and delete it when you are done."""
1639
def __init__(self, pending_deletion):
1640
BzrError.__init__(self, pending_deletion=pending_deletion)
1643
class ImmortalPendingDeletion(BzrError):
1645
_fmt = ("Unable to delete transform temporary directory "
1646
"%(pending_deletion)s. Please examine %(pending_deletion)s to see if it "
1647
"contains any files you wish to keep, and delete it when you are done.")
1649
def __init__(self, pending_deletion):
1650
BzrError.__init__(self, pending_deletion=pending_deletion)
1699
def __init__(self, limbo_dir):
1700
BzrError.__init__(self)
1701
self.limbo_dir = limbo_dir
1704
class ImmortalLimbo(BzrError):
1706
_fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
1707
Please examine %(limbo_dir)s to see if it contains any files you wish to
1708
keep, and delete it when you are done."""
1710
def __init__(self, limbo_dir):
1711
BzrError.__init__(self)
1712
self.limbo_dir = limbo_dir
1653
1715
class OutOfDateTree(BzrError):
1655
_fmt = "Working tree is out of date, please run 'brz update'.%(more)s"
1717
_fmt = "Working tree is out of date, please run 'bzr update'."
1657
def __init__(self, tree, more=None):
1719
def __init__(self, tree):
1662
1720
BzrError.__init__(self)
1663
1721
self.tree = tree
1667
1724
class PublicBranchOutOfDate(BzrError):
1986
2055
class TagsNotSupported(BzrError):
1988
2057
_fmt = ("Tags not supported by %(branch)s;"
1989
" you may be able to use 'brz upgrade %(branch_url)s'.")
2058
" you may be able to use bzr upgrade --dirstate-tags.")
1991
2060
def __init__(self, branch):
1992
2061
self.branch = branch
1993
self.branch_url = branch.user_url
1996
2064
class TagAlreadyExists(BzrError):
1998
2066
_fmt = "Tag %(tag_name)s already exists."
2000
2068
def __init__(self, tag_name):
2001
2069
self.tag_name = tag_name
2004
class UnexpectedSmartServerResponse(BzrError):
2006
_fmt = "Could not understand response from smart server: %(response_tuple)r"
2008
def __init__(self, response_tuple):
2009
self.response_tuple = response_tuple
2012
class ErrorFromSmartServer(BzrError):
2013
"""An error was received from a smart server.
2015
:seealso: UnknownErrorFromSmartServer
2018
_fmt = "Error received from smart server: %(error_tuple)r"
2020
internal_error = True
2022
def __init__(self, error_tuple):
2023
self.error_tuple = error_tuple
2025
self.error_verb = error_tuple[0]
2027
self.error_verb = None
2028
self.error_args = error_tuple[1:]
2031
class UnknownErrorFromSmartServer(BzrError):
2032
"""An ErrorFromSmartServer could not be translated into a typical breezy
2035
This is distinct from ErrorFromSmartServer so that it is possible to
2036
distinguish between the following two cases:
2038
- ErrorFromSmartServer was uncaught. This is logic error in the client
2039
and so should provoke a traceback to the user.
2040
- ErrorFromSmartServer was caught but its error_tuple could not be
2041
translated. This is probably because the server sent us garbage, and
2042
should not provoke a traceback.
2045
_fmt = "Server sent an unexpected error: %(error_tuple)r"
2047
internal_error = False
2049
def __init__(self, error_from_smart_server):
2052
:param error_from_smart_server: An ErrorFromSmartServer instance.
2054
self.error_from_smart_server = error_from_smart_server
2055
self.error_tuple = error_from_smart_server.error_tuple
2058
class ContainerError(BzrError):
2059
"""Base class of container errors."""
2062
class UnknownContainerFormatError(ContainerError):
2064
_fmt = "Unrecognised container format: %(container_format)r"
2066
def __init__(self, container_format):
2067
self.container_format = container_format
2070
class UnexpectedEndOfContainerError(ContainerError):
2072
_fmt = "Unexpected end of container stream"
2075
class UnknownRecordTypeError(ContainerError):
2077
_fmt = "Unknown record type: %(record_type)r"
2079
def __init__(self, record_type):
2080
self.record_type = record_type
2083
class InvalidRecordError(ContainerError):
2085
_fmt = "Invalid record: %(reason)s"
2087
def __init__(self, reason):
2088
self.reason = reason
2091
class ContainerHasExcessDataError(ContainerError):
2093
_fmt = "Container has data after end marker: %(excess)r"
2095
def __init__(self, excess):
2096
self.excess = excess
2099
class DuplicateRecordNameError(ContainerError):
2101
_fmt = "Container has multiple records with the same name: %(name)s"
2103
def __init__(self, name):
2104
self.name = name.decode("utf-8")
2107
class RepositoryDataStreamError(BzrError):
2109
_fmt = "Corrupt or incompatible data stream: %(reason)s"
2111
def __init__(self, reason):
2112
self.reason = reason
2115
class UncommittedChanges(BzrError):
2117
_fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2118
' (See brz status).%(more)s')
2120
def __init__(self, tree, more=None):
2125
import breezy.urlutils as urlutils
2126
user_url = getattr(tree, "user_url", None)
2127
if user_url is None:
2128
display_url = str(tree)
2130
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2131
BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2134
class StoringUncommittedNotSupported(BzrError):
2136
_fmt = ('Branch "%(display_url)s" does not support storing uncommitted'
2139
def __init__(self, branch):
2140
import breezy.urlutils as urlutils
2141
user_url = getattr(branch, "user_url", None)
2142
if user_url is None:
2143
display_url = str(branch)
2145
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2146
BzrError.__init__(self, branch=branch, display_url=display_url)
2149
class ShelvedChanges(UncommittedChanges):
2151
_fmt = ('Working tree "%(display_url)s" has shelved changes'
2152
' (See brz shelve --list).%(more)s')
2155
class UnableEncodePath(BzrError):
2157
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2158
'user encoding %(user_encoding)s')
2160
def __init__(self, path, kind):
2161
from breezy.osutils import get_user_encoding
2164
self.user_encoding = get_user_encoding()
2167
class NoSuchAlias(BzrError):
2169
_fmt = ('The alias "%(alias_name)s" does not exist.')
2171
def __init__(self, alias_name):
2172
BzrError.__init__(self, alias_name=alias_name)
2175
class CannotBindAddress(BzrError):
2177
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2179
def __init__(self, host, port, orig_error):
2180
# nb: in python2.4 socket.error doesn't have a useful repr
2181
BzrError.__init__(self, host=host, port=port,
2182
orig_error=repr(orig_error.args))
2185
class TipChangeRejected(BzrError):
2186
"""A pre_change_branch_tip hook function may raise this to cleanly and
2187
explicitly abort a change to a branch tip.
2190
_fmt = u"Tip change rejected: %(msg)s"
2192
def __init__(self, msg):
2196
class JailBreak(BzrError):
2198
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
2200
def __init__(self, url):
2201
BzrError.__init__(self, url=url)
2204
class UserAbort(BzrError):
2206
_fmt = 'The user aborted the operation.'
2209
class UnresumableWriteGroup(BzrError):
2211
_fmt = ("Repository %(repository)s cannot resume write group "
2212
"%(write_groups)r: %(reason)s")
2214
internal_error = True
2216
def __init__(self, repository, write_groups, reason):
2217
self.repository = repository
2218
self.write_groups = write_groups
2219
self.reason = reason
2222
class UnsuspendableWriteGroup(BzrError):
2224
_fmt = ("Repository %(repository)s cannot suspend a write group.")
2226
internal_error = True
2228
def __init__(self, repository):
2229
self.repository = repository
2232
class LossyPushToSameVCS(BzrError):
2234
_fmt = ("Lossy push not possible between %(source_branch)r and "
2235
"%(target_branch)r that are in the same VCS.")
2237
internal_error = True
2239
def __init__(self, source_branch, target_branch):
2240
self.source_branch = source_branch
2241
self.target_branch = target_branch
2244
class NoRoundtrippingSupport(BzrError):
2246
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
2247
"%(target_branch)r.")
2249
internal_error = True
2251
def __init__(self, source_branch, target_branch):
2252
self.source_branch = source_branch
2253
self.target_branch = target_branch
2256
class NoColocatedBranchSupport(BzrError):
2258
_fmt = ("%(controldir)r does not support co-located branches.")
2260
def __init__(self, controldir):
2261
self.controldir = controldir
2264
class RecursiveBind(BzrError):
2266
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2267
'Please use `brz unbind` to fix.')
2269
def __init__(self, branch_url):
2270
self.branch_url = branch_url
2273
class UnsupportedKindChange(BzrError):
2275
_fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
2276
"%(path)s not supported by format %(format)r")
2278
def __init__(self, path, from_kind, to_kind, format):
2280
self.from_kind = from_kind
2281
self.to_kind = to_kind
2282
self.format = format
2285
class ChangesAlreadyStored(CommandError):
2287
_fmt = ('Cannot store uncommitted changes because this branch already'
2288
' stores uncommitted changes.')
2291
class RevnoOutOfBounds(InternalBzrError):
2293
_fmt = ("The requested revision number %(revno)d is outside of the "
2294
"expected boundaries (%(minimum)d <= %(maximum)d).")
2296
def __init__(self, revno, bounds):
2297
InternalBzrError.__init__(
2298
self, revno=revno, minimum=bounds[0], maximum=bounds[1])