/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/errors.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 20:02:36 UTC
  • mto: (7490.7.7 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200322200236-fsbl91ktcn6fcbdd
Fix tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
 
22
from .sixish import (
 
23
    PY3,
 
24
    )
20
25
 
21
26
# TODO: is there any value in providing the .args field used by standard
22
27
# python exceptions?   A list of values with no names seems less useful
103
108
               getattr(self, '_fmt', None),
104
109
               err)
105
110
 
106
 
    __str__ = _format
 
111
    if PY3:
 
112
        __str__ = _format
 
113
    else:
 
114
        def __str__(self):
 
115
            return self._format().encode('utf-8')
 
116
 
 
117
        __unicode__ = _format
107
118
 
108
119
    def __repr__(self):
109
120
        return '%s(%s)' % (self.__class__.__name__, str(self))
171
182
        self.transport = transport
172
183
 
173
184
 
 
185
class InvalidEntryName(InternalBzrError):
 
186
 
 
187
    _fmt = "Invalid entry name: %(name)s"
 
188
 
 
189
    def __init__(self, name):
 
190
        BzrError.__init__(self)
 
191
        self.name = name
 
192
 
 
193
 
174
194
class InvalidRevisionNumber(BzrError):
175
195
 
176
196
    _fmt = "Invalid revision number %(revno)s"
230
250
    _fmt = "The branch '%(branch)s' is not stacked."
231
251
 
232
252
 
 
253
class InventoryModified(InternalBzrError):
 
254
 
 
255
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
 
256
            " so a clean inventory cannot be read without data loss.")
 
257
 
 
258
    def __init__(self, tree):
 
259
        self.tree = tree
 
260
 
 
261
 
233
262
class NoWorkingTree(BzrError):
234
263
 
235
264
    _fmt = 'No WorkingTree exists for "%(base)s".'
262
291
            'E.g. brz whoami "Your Name <name@example.com>"')
263
292
 
264
293
 
265
 
class CommandError(BzrError):
 
294
class BzrCommandError(BzrError):
266
295
    """Error from user command"""
267
296
 
268
297
    # Error from malformed user command; please avoid raising this as a
270
299
    #
271
300
    # I think it's a waste of effort to differentiate between errors that
272
301
    # are not intended to be caught anyway.  UI code need not subclass
273
 
    # CommandError, and non-UI code should not throw a subclass of
274
 
    # CommandError.  ADHB 20051211
275
 
 
276
 
 
277
 
# Provide the old name as backup, for the moment.
278
 
BzrCommandError = CommandError
 
302
    # BzrCommandError, and non-UI code should not throw a subclass of
 
303
    # BzrCommandError.  ADHB 20051211
279
304
 
280
305
 
281
306
class NotWriteLocked(BzrError):
377
402
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
378
403
 
379
404
 
 
405
class UnavailableRepresentation(InternalBzrError):
 
406
 
 
407
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
 
408
            "is encoded as '%(native)s'.")
 
409
 
 
410
    def __init__(self, key, wanted, native):
 
411
        InternalBzrError.__init__(self)
 
412
        self.wanted = wanted
 
413
        self.native = native
 
414
        self.key = key
 
415
 
 
416
 
380
417
class UnsupportedProtocol(PathError):
381
418
 
382
419
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
563
600
        self.format = format
564
601
 
565
602
 
 
603
class LineEndingError(BzrError):
 
604
 
 
605
    _fmt = ("Line ending corrupted for file: %(file)s; "
 
606
            "Maybe your files got corrupted in transport?")
 
607
 
 
608
    def __init__(self, file):
 
609
        self.file = file
 
610
 
 
611
 
566
612
class IncompatibleFormat(BzrError):
567
613
 
568
614
    _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
930
976
        self.revision_id = revision_id
931
977
 
932
978
 
 
979
class InvalidRevisionSpec(BzrError):
 
980
 
 
981
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
 
982
            " %(branch_url)s%(extra)s")
 
983
 
 
984
    def __init__(self, spec, branch, extra=None):
 
985
        BzrError.__init__(self, branch=branch, spec=spec)
 
986
        self.branch_url = getattr(branch, 'user_url', str(branch))
 
987
        if extra:
 
988
            self.extra = '\n' + str(extra)
 
989
        else:
 
990
            self.extra = ''
 
991
 
 
992
 
933
993
class AppendRevisionsOnlyViolation(BzrError):
934
994
 
935
995
    _fmt = ('Operation denied because it would change the main history,'
1280
1340
        TransportError.__init__(self, msg, orig_error=orig_error)
1281
1341
 
1282
1342
 
1283
 
class UnexpectedHttpStatus(InvalidHttpResponse):
1284
 
 
1285
 
    _fmt = "Unexpected HTTP status %(code)d for %(path)s"
1286
 
 
1287
 
    def __init__(self, path, code, msg=None):
1288
 
        self.path = path
1289
 
        self.code = code
1290
 
        self.msg = msg
1291
 
        full_msg = 'status code %d unexpected' % code
1292
 
        if msg is not None:
1293
 
            full_msg += ': ' + msg
1294
 
        InvalidHttpResponse.__init__(
1295
 
            self, path, full_msg)
1296
 
 
1297
 
 
1298
 
class BadHttpRequest(UnexpectedHttpStatus):
1299
 
 
1300
 
    _fmt = "Bad http request for %(path)s: %(reason)s"
1301
 
 
1302
 
    def __init__(self, path, reason):
1303
 
        self.path = path
1304
 
        self.reason = reason
1305
 
        TransportError.__init__(self, reason)
1306
 
 
1307
 
 
1308
1343
class InvalidHttpRange(InvalidHttpResponse):
1309
1344
 
1310
1345
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1460
1495
        self.file_id = file_id
1461
1496
 
1462
1497
 
 
1498
class DuplicateFileId(BzrError):
 
1499
 
 
1500
    _fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
 
1501
 
 
1502
    def __init__(self, file_id, entry):
 
1503
        BzrError.__init__(self)
 
1504
        self.file_id = file_id
 
1505
        self.entry = entry
 
1506
 
 
1507
 
1463
1508
class DuplicateKey(BzrError):
1464
1509
 
1465
1510
    _fmt = "Key %(key)s is already present in map"
1473
1518
        self.prefix = prefix
1474
1519
 
1475
1520
 
 
1521
class MalformedTransform(InternalBzrError):
 
1522
 
 
1523
    _fmt = "Tree transform is malformed %(conflicts)r"
 
1524
 
 
1525
 
 
1526
class NoFinalPath(BzrError):
 
1527
 
 
1528
    _fmt = ("No final name for trans_id %(trans_id)r\n"
 
1529
            "file-id: %(file_id)r\n"
 
1530
            "root trans-id: %(root_trans_id)r\n")
 
1531
 
 
1532
    def __init__(self, trans_id, transform):
 
1533
        self.trans_id = trans_id
 
1534
        self.file_id = transform.final_file_id(trans_id)
 
1535
        self.root_trans_id = transform.root
 
1536
 
 
1537
 
1476
1538
class BzrBadParameter(InternalBzrError):
1477
1539
 
1478
1540
    _fmt = "Bad parameter: %(param)r"
1490
1552
    _fmt = "Parameter %(param)s is neither unicode nor utf8."
1491
1553
 
1492
1554
 
 
1555
class ReusingTransform(BzrError):
 
1556
 
 
1557
    _fmt = "Attempt to reuse a transform that has already been applied."
 
1558
 
 
1559
 
 
1560
class CantMoveRoot(BzrError):
 
1561
 
 
1562
    _fmt = "Moving the root directory is not supported at this time"
 
1563
 
 
1564
 
 
1565
class TransformRenameFailed(BzrError):
 
1566
 
 
1567
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
 
1568
 
 
1569
    def __init__(self, from_path, to_path, why, errno):
 
1570
        self.from_path = from_path
 
1571
        self.to_path = to_path
 
1572
        self.why = why
 
1573
        self.errno = errno
 
1574
 
 
1575
 
1493
1576
class BzrMoveFailedError(BzrError):
1494
1577
 
1495
1578
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1619
1702
    _fmt = "Diff3 is not installed on this machine."
1620
1703
 
1621
1704
 
 
1705
class ExistingContent(BzrError):
 
1706
    # Added in breezy 0.92, used by VersionedFile.add_lines.
 
1707
 
 
1708
    _fmt = "The content being inserted is already present."
 
1709
 
 
1710
 
1622
1711
class ExistingLimbo(BzrError):
1623
1712
 
1624
1713
    _fmt = """This tree contains left-over files from a failed operation.
1640
1729
        BzrError.__init__(self, pending_deletion=pending_deletion)
1641
1730
 
1642
1731
 
 
1732
class ImmortalLimbo(BzrError):
 
1733
 
 
1734
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
 
1735
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
1736
    keep, and delete it when you are done."""
 
1737
 
 
1738
    def __init__(self, limbo_dir):
 
1739
        BzrError.__init__(self)
 
1740
        self.limbo_dir = limbo_dir
 
1741
 
 
1742
 
1643
1743
class ImmortalPendingDeletion(BzrError):
1644
1744
 
1645
1745
    _fmt = ("Unable to delete transform temporary directory "
1866
1966
        self.other = other
1867
1967
 
1868
1968
 
 
1969
class BadInventoryFormat(BzrError):
 
1970
 
 
1971
    _fmt = "Root class for inventory serialization errors"
 
1972
 
 
1973
 
 
1974
class UnexpectedInventoryFormat(BadInventoryFormat):
 
1975
 
 
1976
    _fmt = "The inventory was not in the expected format:\n %(msg)s"
 
1977
 
 
1978
    def __init__(self, msg):
 
1979
        BadInventoryFormat.__init__(self, msg=msg)
 
1980
 
 
1981
 
1869
1982
class RootNotRich(BzrError):
1870
1983
 
1871
1984
    _fmt = """This operation requires rich root data storage"""
1928
2041
        " branch location."
1929
2042
 
1930
2043
 
 
2044
class IllegalMergeDirectivePayload(BzrError):
 
2045
    """A merge directive contained something other than a patch or bundle"""
 
2046
 
 
2047
    _fmt = "Bad merge directive payload %(start)r"
 
2048
 
 
2049
    def __init__(self, start):
 
2050
        BzrError(self)
 
2051
        self.start = start
 
2052
 
 
2053
 
1931
2054
class PatchVerificationFailed(BzrError):
1932
2055
    """A patch from a merge directive could not be verified"""
1933
2056
 
1957
2080
        self.location = location
1958
2081
 
1959
2082
 
 
2083
class UnsupportedInventoryKind(BzrError):
 
2084
 
 
2085
    _fmt = """Unsupported entry kind %(kind)s"""
 
2086
 
 
2087
    def __init__(self, kind):
 
2088
        self.kind = kind
 
2089
 
 
2090
 
1960
2091
class BadSubsumeSource(BzrError):
1961
2092
 
1962
2093
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
2282
2413
        self.format = format
2283
2414
 
2284
2415
 
2285
 
class ChangesAlreadyStored(CommandError):
 
2416
class ChangesAlreadyStored(BzrCommandError):
2286
2417
 
2287
2418
    _fmt = ('Cannot store uncommitted changes because this branch already'
2288
2419
            ' stores uncommitted changes.')