/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: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

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".'
255
284
        self.base = base
256
285
 
257
286
 
258
 
class NoWhoami(BzrError):
259
 
 
260
 
    _fmt = ('Unable to determine your name.\n'
261
 
            "Please, set your name with the 'whoami' command.\n"
262
 
            'E.g. brz whoami "Your Name <name@example.com>"')
263
 
 
264
 
 
265
 
class CommandError(BzrError):
 
287
class BzrCommandError(BzrError):
266
288
    """Error from user command"""
267
289
 
268
290
    # Error from malformed user command; please avoid raising this as a
270
292
    #
271
293
    # I think it's a waste of effort to differentiate between errors that
272
294
    # 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
 
295
    # BzrCommandError, and non-UI code should not throw a subclass of
 
296
    # BzrCommandError.  ADHB 20051211
279
297
 
280
298
 
281
299
class NotWriteLocked(BzrError):
377
395
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
378
396
 
379
397
 
 
398
class UnavailableRepresentation(InternalBzrError):
 
399
 
 
400
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
 
401
            "is encoded as '%(native)s'.")
 
402
 
 
403
    def __init__(self, key, wanted, native):
 
404
        InternalBzrError.__init__(self)
 
405
        self.wanted = wanted
 
406
        self.native = native
 
407
        self.key = key
 
408
 
 
409
 
380
410
class UnsupportedProtocol(PathError):
381
411
 
382
412
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
563
593
        self.format = format
564
594
 
565
595
 
 
596
class LineEndingError(BzrError):
 
597
 
 
598
    _fmt = ("Line ending corrupted for file: %(file)s; "
 
599
            "Maybe your files got corrupted in transport?")
 
600
 
 
601
    def __init__(self, file):
 
602
        self.file = file
 
603
 
 
604
 
566
605
class IncompatibleFormat(BzrError):
567
606
 
568
607
    _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
930
969
        self.revision_id = revision_id
931
970
 
932
971
 
 
972
class InvalidRevisionSpec(BzrError):
 
973
 
 
974
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
 
975
            " %(branch_url)s%(extra)s")
 
976
 
 
977
    def __init__(self, spec, branch, extra=None):
 
978
        BzrError.__init__(self, branch=branch, spec=spec)
 
979
        self.branch_url = getattr(branch, 'user_url', str(branch))
 
980
        if extra:
 
981
            self.extra = '\n' + str(extra)
 
982
        else:
 
983
            self.extra = ''
 
984
 
 
985
 
933
986
class AppendRevisionsOnlyViolation(BzrError):
934
987
 
935
988
    _fmt = ('Operation denied because it would change the main history,'
1280
1333
        TransportError.__init__(self, msg, orig_error=orig_error)
1281
1334
 
1282
1335
 
1283
 
class UnexpectedHttpStatus(InvalidHttpResponse):
1284
 
 
1285
 
    _fmt = "Unexpected HTTP status %(code)d for %(path)s: %(extra)s"
1286
 
 
1287
 
    def __init__(self, path, code, extra=None):
1288
 
        self.path = path
1289
 
        self.code = code
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)
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
1336
class InvalidHttpRange(InvalidHttpResponse):
1309
1337
 
1310
1338
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1460
1488
        self.file_id = file_id
1461
1489
 
1462
1490
 
 
1491
class DuplicateFileId(BzrError):
 
1492
 
 
1493
    _fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
 
1494
 
 
1495
    def __init__(self, file_id, entry):
 
1496
        BzrError.__init__(self)
 
1497
        self.file_id = file_id
 
1498
        self.entry = entry
 
1499
 
 
1500
 
1463
1501
class DuplicateKey(BzrError):
1464
1502
 
1465
1503
    _fmt = "Key %(key)s is already present in map"
1473
1511
        self.prefix = prefix
1474
1512
 
1475
1513
 
 
1514
class MalformedTransform(InternalBzrError):
 
1515
 
 
1516
    _fmt = "Tree transform is malformed %(conflicts)r"
 
1517
 
 
1518
 
 
1519
class NoFinalPath(BzrError):
 
1520
 
 
1521
    _fmt = ("No final name for trans_id %(trans_id)r\n"
 
1522
            "file-id: %(file_id)r\n"
 
1523
            "root trans-id: %(root_trans_id)r\n")
 
1524
 
 
1525
    def __init__(self, trans_id, transform):
 
1526
        self.trans_id = trans_id
 
1527
        self.file_id = transform.final_file_id(trans_id)
 
1528
        self.root_trans_id = transform.root
 
1529
 
 
1530
 
1476
1531
class BzrBadParameter(InternalBzrError):
1477
1532
 
1478
1533
    _fmt = "Bad parameter: %(param)r"
1490
1545
    _fmt = "Parameter %(param)s is neither unicode nor utf8."
1491
1546
 
1492
1547
 
 
1548
class ReusingTransform(BzrError):
 
1549
 
 
1550
    _fmt = "Attempt to reuse a transform that has already been applied."
 
1551
 
 
1552
 
 
1553
class CantMoveRoot(BzrError):
 
1554
 
 
1555
    _fmt = "Moving the root directory is not supported at this time"
 
1556
 
 
1557
 
 
1558
class TransformRenameFailed(BzrError):
 
1559
 
 
1560
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
 
1561
 
 
1562
    def __init__(self, from_path, to_path, why, errno):
 
1563
        self.from_path = from_path
 
1564
        self.to_path = to_path
 
1565
        self.why = why
 
1566
        self.errno = errno
 
1567
 
 
1568
 
1493
1569
class BzrMoveFailedError(BzrError):
1494
1570
 
1495
1571
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1619
1695
    _fmt = "Diff3 is not installed on this machine."
1620
1696
 
1621
1697
 
 
1698
class ExistingContent(BzrError):
 
1699
    # Added in breezy 0.92, used by VersionedFile.add_lines.
 
1700
 
 
1701
    _fmt = "The content being inserted is already present."
 
1702
 
 
1703
 
1622
1704
class ExistingLimbo(BzrError):
1623
1705
 
1624
1706
    _fmt = """This tree contains left-over files from a failed operation.
1640
1722
        BzrError.__init__(self, pending_deletion=pending_deletion)
1641
1723
 
1642
1724
 
 
1725
class ImmortalLimbo(BzrError):
 
1726
 
 
1727
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
 
1728
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
1729
    keep, and delete it when you are done."""
 
1730
 
 
1731
    def __init__(self, limbo_dir):
 
1732
        BzrError.__init__(self)
 
1733
        self.limbo_dir = limbo_dir
 
1734
 
 
1735
 
1643
1736
class ImmortalPendingDeletion(BzrError):
1644
1737
 
1645
1738
    _fmt = ("Unable to delete transform temporary directory "
1772
1865
    """
1773
1866
 
1774
1867
 
1775
 
class SharedRepositoriesUnsupported(UnsupportedOperation):
1776
 
    _fmt = "Shared repositories are not supported by %(format)r."
1777
 
 
1778
 
    def __init__(self, format):
1779
 
        BzrError.__init__(self, format=format)
1780
 
 
1781
 
 
1782
1868
class GhostTagsNotSupported(BzrError):
1783
1869
 
1784
1870
    _fmt = "Ghost tags not supported by format %(format)r."
1866
1952
        self.other = other
1867
1953
 
1868
1954
 
 
1955
class BadInventoryFormat(BzrError):
 
1956
 
 
1957
    _fmt = "Root class for inventory serialization errors"
 
1958
 
 
1959
 
 
1960
class UnexpectedInventoryFormat(BadInventoryFormat):
 
1961
 
 
1962
    _fmt = "The inventory was not in the expected format:\n %(msg)s"
 
1963
 
 
1964
    def __init__(self, msg):
 
1965
        BadInventoryFormat.__init__(self, msg=msg)
 
1966
 
 
1967
 
1869
1968
class RootNotRich(BzrError):
1870
1969
 
1871
1970
    _fmt = """This operation requires rich root data storage"""
1914
2013
        self.revision_id = revision_id
1915
2014
 
1916
2015
 
 
2016
class IllegalUseOfScopeReplacer(InternalBzrError):
 
2017
 
 
2018
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
 
2019
            " %(msg)s%(extra)s")
 
2020
 
 
2021
    def __init__(self, name, msg, extra=None):
 
2022
        BzrError.__init__(self)
 
2023
        self.name = name
 
2024
        self.msg = msg
 
2025
        if extra:
 
2026
            self.extra = ': ' + str(extra)
 
2027
        else:
 
2028
            self.extra = ''
 
2029
 
 
2030
 
 
2031
class InvalidImportLine(InternalBzrError):
 
2032
 
 
2033
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
 
2034
 
 
2035
    def __init__(self, text, msg):
 
2036
        BzrError.__init__(self)
 
2037
        self.text = text
 
2038
        self.msg = msg
 
2039
 
 
2040
 
 
2041
class ImportNameCollision(InternalBzrError):
 
2042
 
 
2043
    _fmt = ("Tried to import an object to the same name as"
 
2044
            " an existing object. %(name)s")
 
2045
 
 
2046
    def __init__(self, name):
 
2047
        BzrError.__init__(self)
 
2048
        self.name = name
 
2049
 
 
2050
 
1917
2051
class NotAMergeDirective(BzrError):
1918
2052
    """File starting with %(firstline)r is not a merge directive"""
1919
2053
 
1928
2062
        " branch location."
1929
2063
 
1930
2064
 
 
2065
class IllegalMergeDirectivePayload(BzrError):
 
2066
    """A merge directive contained something other than a patch or bundle"""
 
2067
 
 
2068
    _fmt = "Bad merge directive payload %(start)r"
 
2069
 
 
2070
    def __init__(self, start):
 
2071
        BzrError(self)
 
2072
        self.start = start
 
2073
 
 
2074
 
1931
2075
class PatchVerificationFailed(BzrError):
1932
2076
    """A patch from a merge directive could not be verified"""
1933
2077
 
1957
2101
        self.location = location
1958
2102
 
1959
2103
 
 
2104
class UnsupportedInventoryKind(BzrError):
 
2105
 
 
2106
    _fmt = """Unsupported entry kind %(kind)s"""
 
2107
 
 
2108
    def __init__(self, kind):
 
2109
        self.kind = kind
 
2110
 
 
2111
 
1960
2112
class BadSubsumeSource(BzrError):
1961
2113
 
1962
2114
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
1986
2138
class TagsNotSupported(BzrError):
1987
2139
 
1988
2140
    _fmt = ("Tags not supported by %(branch)s;"
1989
 
            " you may be able to use 'brz upgrade %(branch_url)s'.")
 
2141
            " you may be able to use brz upgrade.")
1990
2142
 
1991
2143
    def __init__(self, branch):
1992
2144
        self.branch = branch
1993
 
        self.branch_url = branch.user_url
1994
2145
 
1995
2146
 
1996
2147
class TagAlreadyExists(BzrError):
2152
2303
            ' (See brz shelve --list).%(more)s')
2153
2304
 
2154
2305
 
 
2306
class UnableCreateSymlink(BzrError):
 
2307
 
 
2308
    _fmt = 'Unable to create symlink %(path_str)son this platform'
 
2309
 
 
2310
    def __init__(self, path=None):
 
2311
        path_str = ''
 
2312
        if path:
 
2313
            try:
 
2314
                path_str = repr(str(path))
 
2315
            except UnicodeEncodeError:
 
2316
                path_str = repr(path)
 
2317
            path_str += ' '
 
2318
        self.path_str = path_str
 
2319
 
 
2320
 
2155
2321
class UnableEncodePath(BzrError):
2156
2322
 
2157
2323
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2282
2448
        self.format = format
2283
2449
 
2284
2450
 
2285
 
class ChangesAlreadyStored(CommandError):
 
2451
class ChangesAlreadyStored(BzrCommandError):
2286
2452
 
2287
2453
    _fmt = ('Cannot store uncommitted changes because this branch already'
2288
2454
            ' stores uncommitted changes.')
2289
 
 
2290
 
 
2291
 
class RevnoOutOfBounds(InternalBzrError):
2292
 
 
2293
 
    _fmt = ("The requested revision number %(revno)d is outside of the "
2294
 
            "expected boundaries (%(minimum)d <= %(maximum)d).")
2295
 
 
2296
 
    def __init__(self, revno, bounds):
2297
 
        InternalBzrError.__init__(
2298
 
            self, revno=revno, minimum=bounds[0], maximum=bounds[1])