86
87
for key, value in kwds.items():
87
88
setattr(self, key, value)
90
91
s = getattr(self, '_preformatted_string', None)
92
# contains a preformatted message
93
# contains a preformatted message; must be cast to plain str
96
96
fmt = self._get_format_string()
98
d = dict(self.__dict__)
98
s = fmt % self.__dict__
100
99
# __str__() should always return a 'str' object
101
100
# never a 'unicode' object.
101
if isinstance(s, unicode):
102
return s.encode('utf8')
103
except Exception as e:
105
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' \
106
123
% (self.__class__.__name__,
108
125
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
class InternalBzrError(BzrError):
139
"""Base class for errors that are internal in nature.
141
This is a convenience class for errors that are internal. The
142
internal_error attribute can still be altered in subclasses, if needed.
143
Using this class is simply an easy way to get internal errors.
146
internal_error = True
149
class BranchError(BzrError):
150
"""Base class for concrete 'errors about a branch'."""
152
def __init__(self, branch):
153
BzrError.__init__(self, branch=branch)
156
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):
173
self.current = current
176
class InProcessTransport(BzrError):
178
_fmt = "The transport '%(transport)s' is only accessible within this " \
181
def __init__(self, transport):
182
self.transport = transport
185
class InvalidEntryName(InternalBzrError):
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):
187
191
_fmt = "Invalid entry name: %(name)s"
193
internal_error = True
189
195
def __init__(self, name):
190
196
BzrError.__init__(self)
194
200
class InvalidRevisionNumber(BzrError):
196
202
_fmt = "Invalid revision number %(revno)s"
198
204
def __init__(self, revno):
218
223
def __init__(self, revision_id):
219
224
self.revision_id = revision_id
222
class RootMissing(InternalBzrError):
224
_fmt = ("The root entry of a tree must be the first entry supplied to "
225
"the commit builder.")
228
class NoPublicBranch(BzrError):
230
_fmt = 'There is no public branch set for "%(branch_url)s".'
232
def __init__(self, branch):
233
from . import urlutils
234
public_location = urlutils.unescape_for_display(branch.base, 'ascii')
235
BzrError.__init__(self, branch_url=public_location)
238
226
class NoSuchId(BzrError):
240
_fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
228
_fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
242
230
def __init__(self, tree, file_id):
243
231
BzrError.__init__(self)
244
232
self.file_id = file_id
248
class NotStacked(BranchError):
250
_fmt = "The branch '%(branch)s' is not stacked."
253
class InventoryModified(InternalBzrError):
236
class InventoryModified(BzrError):
255
238
_fmt = ("The current inventory for the tree %(tree)r has been modified,"
256
239
" so a clean inventory cannot be read without data loss.")
241
internal_error = True
258
243
def __init__(self, tree):
262
247
class NoWorkingTree(BzrError):
264
_fmt = 'No WorkingTree exists for "%(base)s".'
249
_fmt = "No WorkingTree exists for %(base)s."
266
251
def __init__(self, base):
267
252
BzrError.__init__(self)
256
class NotBuilding(BzrError):
258
_fmt = "Not currently building a tree."
271
261
class NotLocalUrl(BzrError):
273
263
_fmt = "%(url)s is not a local path."
358
369
class NotADirectory(PathError):
360
_fmt = '"%(path)s" is not a directory %(extra)s'
371
_fmt = "%(path)r is not a directory %(extra)s"
363
374
class NotInWorkingDirectory(PathError):
365
_fmt = '"%(path)s" is not in the working directory %(extra)s'
376
_fmt = "%(path)r is not in the working directory %(extra)s"
368
379
class DirectoryNotEmpty(PathError):
370
_fmt = 'Directory not empty: "%(path)s"%(extra)s'
373
class HardLinkNotSupported(PathError):
375
_fmt = 'Hard-linking "%(path)s" is not supported'
378
class ReadingCompleted(InternalBzrError):
381
_fmt = "Directory not empty: %(path)r%(extra)s"
384
class ReadingCompleted(BzrError):
380
386
_fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
381
387
"called upon it - the request has been completed and no more "
382
388
"data may be read.")
390
internal_error = True
384
392
def __init__(self, request):
385
393
self.request = request
388
396
class ResourceBusy(PathError):
390
_fmt = 'Device or resource busy: "%(path)s"%(extra)s'
398
_fmt = "Device or resource busy: %(path)r%(extra)s"
393
401
class PermissionDenied(PathError):
395
_fmt = 'Permission denied: "%(path)s"%(extra)s'
398
class UnavailableRepresentation(InternalBzrError):
400
_fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
401
"is encoded as '%(native)s'.")
403
def __init__(self, key, wanted, native):
404
InternalBzrError.__init__(self)
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
410
430
class UnsupportedProtocol(PathError):
412
432
_fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
414
def __init__(self, url, extra=""):
434
def __init__(self, url, extra):
415
435
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):
423
BzrError.__init__(self)
424
self.branch_url = branch_url
425
self.target_url = target_url
428
class UnstackableRepositoryFormat(BzrError):
430
_fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
431
"You will need to upgrade the repository to permit branch stacking.")
433
def __init__(self, format, url):
434
BzrError.__init__(self)
439
class ReadError(PathError):
441
_fmt = """Error reading from %(path)r."""
444
438
class ShortReadvError(PathError):
446
_fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
447
' 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")
449
443
internal_error = True
474
468
class InvalidNormalization(PathError):
476
_fmt = 'Path "%(path)s" is not unicode normalized'
470
_fmt = "Path %(path)r is not unicode normalized"
479
473
# TODO: This is given a URL; we try to unescape it but doing that from inside
480
474
# the exception object is a bit undesirable.
481
# TODO: Probably this behavior of should be a common superclass
475
# TODO: Probably this behavior of should be a common superclass
482
476
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'
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')
524
485
class NoSubmitBranch(PathError):
526
487
_fmt = 'No submit branch available for branch "%(path)s"'
528
489
def __init__(self, branch):
529
from . import urlutils
490
import bzrlib.urlutils as urlutils
530
491
self.path = urlutils.unescape_for_display(branch.base, 'ascii')
533
class AlreadyControlDirError(PathError):
535
_fmt = 'A control directory already exists: "%(path)s".'
538
494
class AlreadyBranchError(PathError):
540
_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".'
496
_fmt = "Already a branch: %(path)s."
557
499
class BranchExistsWithoutWorkingTree(PathError):
559
_fmt = 'Directory contains a branch, but no working tree \
560
(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
563
515
class InaccessibleParent(PathError):
565
_fmt = ('Parent not accessible given base "%(base)s" and'
566
' relative path "%(path)s"')
517
_fmt = ("Parent not accessible given base %(base)s and"
518
" relative path %(path)s")
568
520
def __init__(self, path, base):
569
521
PathError.__init__(self, path)
573
525
class NoRepositoryPresent(BzrError):
575
_fmt = 'No repository present: "%(path)s"'
576
def __init__(self, controldir):
577
BzrError.__init__(self)
578
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
581
544
class UnsupportedFormatError(BzrError):
583
_fmt = "Unsupported branch format: %(format)s\nPlease run 'brz upgrade'"
546
_fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
586
549
class UnknownFormatError(BzrError):
588
_fmt = "Unknown %(kind)s format: %(format)r"
590
def __init__(self, format, kind='branch'):
551
_fmt = "Unknown branch format: %(format)r"
595
554
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)
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
617
564
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)
566
_fmt = "Repository %(target)s is not compatible with repository"\
569
def __init__(self, source, target):
570
BzrError.__init__(self, target=target, source=source)
636
573
class IncompatibleRevision(BzrError):
638
575
_fmt = "Revision is not compatible with %(repo_format)s"
640
577
def __init__(self, repo_format):
1106
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
1109
1144
class VersionedFileError(BzrError):
1111
1146
_fmt = "Versioned file error"
1114
1149
class RevisionNotPresent(VersionedFileError):
1116
_fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1151
_fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
1118
1153
def __init__(self, revision_id, file_id):
1119
1154
VersionedFileError.__init__(self)
1131
1166
self.file_id = file_id
1134
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")
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
1186
1211
class NoSuchExportFormat(BzrError):
1188
1213
_fmt = "Export format %(format)r not supported"
1190
1215
def __init__(self, format):
1287
1283
self.port = ':%s' % port
1290
# XXX: This is also used for unexpected end of file, which is different at the
1291
# TCP level from "connection reset".
1292
1286
class ConnectionReset(TransportError):
1294
1288
_fmt = "Connection closed: %(msg)s %(orig_error)s"
1297
class ConnectionTimeout(ConnectionError):
1299
_fmt = "Connection Timeout: %(msg)s%(orig_error)s"
1302
1291
class InvalidRange(TransportError):
1304
_fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1306
def __init__(self, path, offset, msg=None):
1307
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"
1308
1298
self.path = path
1309
1299
self.offset = offset
1312
1302
class InvalidHttpResponse(TransportError):
1314
_fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
1304
_fmt = "Invalid http response for %(path)s: %(msg)s"
1316
1306
def __init__(self, path, msg, orig_error=None):
1317
1307
self.path = path
1318
if orig_error is None:
1321
# This is reached for obscure and unusual errors so we want to
1322
# preserve as much info as possible to ease debug.
1323
orig_error = ': %r' % (orig_error,)
1324
1308
TransportError.__init__(self, msg, orig_error=orig_error)
1327
1311
class InvalidHttpRange(InvalidHttpResponse):
1329
1313
_fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1331
1315
def __init__(self, path, range, msg):
1332
1316
self.range = range
1333
1317
InvalidHttpResponse.__init__(self, path, msg)
1336
class HttpBoundaryMissing(InvalidHttpResponse):
1337
"""A multipart response ends with no boundary marker.
1339
This is a special case caused by buggy proxies, described in
1340
<https://bugs.launchpad.net/bzr/+bug/198646>.
1343
_fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
1345
def __init__(self, path, msg):
1346
InvalidHttpResponse.__init__(self, path, msg)
1349
1320
class InvalidHttpContentType(InvalidHttpResponse):
1351
1322
_fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1353
1324
def __init__(self, path, ctype, msg):
1354
1325
self.ctype = ctype
1355
1326
InvalidHttpResponse.__init__(self, path, msg)
1360
1331
_fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1362
def __init__(self, source, target, is_permanent=False):
1333
def __init__(self, source, target, is_permament=False, qual_proto=None):
1363
1334
self.source = source
1364
1335
self.target = target
1366
1337
self.permanently = ' permanently'
1368
1339
self.permanently = ''
1340
self.is_permament = is_permament
1341
self._qualified_proto = qual_proto
1369
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)
1372
1378
class TooManyRedirections(TransportError):
1374
1380
_fmt = "Too many redirections"
1377
1382
class ConflictsInTree(BzrError):
1379
1384
_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)
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)
1390
1414
class WorkingTreeNotRevision(BzrError):
1392
_fmt = ("The working tree for %(basedir)s has changed since"
1416
_fmt = ("The working tree for %(basedir)s has changed since"
1393
1417
" the last commit, but weave merge requires that it be"
2128
2055
class TagsNotSupported(BzrError):
2130
2057
_fmt = ("Tags not supported by %(branch)s;"
2131
" you may be able to use brz upgrade.")
2058
" you may be able to use bzr upgrade.")
2133
2060
def __init__(self, branch):
2134
2061
self.branch = branch
2137
2064
class TagAlreadyExists(BzrError):
2139
2066
_fmt = "Tag %(tag_name)s already exists."
2141
2068
def __init__(self, tag_name):
2142
2069
self.tag_name = tag_name
2145
class UnexpectedSmartServerResponse(BzrError):
2147
_fmt = "Could not understand response from smart server: %(response_tuple)r"
2149
def __init__(self, response_tuple):
2150
self.response_tuple = response_tuple
2153
class ErrorFromSmartServer(BzrError):
2154
"""An error was received from a smart server.
2156
:seealso: UnknownErrorFromSmartServer
2159
_fmt = "Error received from smart server: %(error_tuple)r"
2161
internal_error = True
2163
def __init__(self, error_tuple):
2164
self.error_tuple = error_tuple
2166
self.error_verb = error_tuple[0]
2168
self.error_verb = None
2169
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
class ContainerError(BzrError):
2200
"""Base class of container errors."""
2203
class UnknownContainerFormatError(ContainerError):
2205
_fmt = "Unrecognised container format: %(container_format)r"
2207
def __init__(self, container_format):
2208
self.container_format = container_format
2211
class UnexpectedEndOfContainerError(ContainerError):
2213
_fmt = "Unexpected end of container stream"
2216
class UnknownRecordTypeError(ContainerError):
2218
_fmt = "Unknown record type: %(record_type)r"
2220
def __init__(self, record_type):
2221
self.record_type = record_type
2224
class InvalidRecordError(ContainerError):
2226
_fmt = "Invalid record: %(reason)s"
2228
def __init__(self, reason):
2229
self.reason = reason
2232
class ContainerHasExcessDataError(ContainerError):
2234
_fmt = "Container has data after end marker: %(excess)r"
2236
def __init__(self, excess):
2237
self.excess = excess
2240
class DuplicateRecordNameError(ContainerError):
2242
_fmt = "Container has multiple records with the same name: %(name)s"
2244
def __init__(self, name):
2245
self.name = name.decode("utf-8")
2248
class RepositoryDataStreamError(BzrError):
2250
_fmt = "Corrupt or incompatible data stream: %(reason)s"
2252
def __init__(self, reason):
2253
self.reason = reason
2256
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')
2296
class UnableCreateSymlink(BzrError):
2298
_fmt = 'Unable to create symlink %(path_str)son this platform'
2300
def __init__(self, path=None):
2304
path_str = repr(str(path))
2305
except UnicodeEncodeError:
2306
path_str = repr(path)
2308
self.path_str = path_str
2311
class UnableEncodePath(BzrError):
2313
_fmt = ('Unable to encode %(kind)s path %(path)r in '
2314
'user encoding %(user_encoding)s')
2316
def __init__(self, path, kind):
2317
from breezy.osutils import get_user_encoding
2320
self.user_encoding = get_user_encoding()
2323
class NoSuchAlias(BzrError):
2325
_fmt = ('The alias "%(alias_name)s" does not exist.')
2327
def __init__(self, alias_name):
2328
BzrError.__init__(self, alias_name=alias_name)
2331
class CannotBindAddress(BzrError):
2333
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2335
def __init__(self, host, port, orig_error):
2336
# nb: in python2.4 socket.error doesn't have a useful repr
2337
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.')