/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-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

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
 
    )
25
20
 
26
21
# TODO: is there any value in providing the .args field used by standard
27
22
# python exceptions?   A list of values with no names seems less useful
108
103
               getattr(self, '_fmt', None),
109
104
               err)
110
105
 
111
 
    if PY3:
112
 
        __str__ = _format
113
 
    else:
114
 
        def __str__(self):
115
 
            return self._format().encode('utf-8')
116
 
 
117
 
        __unicode__ = _format
 
106
    __str__ = _format
118
107
 
119
108
    def __repr__(self):
120
109
        return '%s(%s)' % (self.__class__.__name__, str(self))
124
113
        fmt = getattr(self, '_fmt', None)
125
114
        if fmt is not None:
126
115
            from breezy.i18n import gettext
127
 
            return gettext(fmt) # _fmt strings should be ascii
 
116
            return gettext(fmt)  # _fmt strings should be ascii
128
117
 
129
118
    def __eq__(self, other):
130
119
        if self.__class__ is not other.__class__:
182
171
        self.transport = transport
183
172
 
184
173
 
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
 
 
194
174
class InvalidRevisionNumber(BzrError):
195
175
 
196
176
    _fmt = "Invalid revision number %(revno)s"
222
202
class RootMissing(InternalBzrError):
223
203
 
224
204
    _fmt = ("The root entry of a tree must be the first entry supplied to "
225
 
        "the commit builder.")
 
205
            "the commit builder.")
226
206
 
227
207
 
228
208
class NoPublicBranch(BzrError):
245
225
        self.tree = tree
246
226
 
247
227
 
248
 
class NoSuchIdInRepository(NoSuchId):
249
 
 
250
 
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
251
 
            ' %(repository)r')
252
 
 
253
 
    def __init__(self, repository, file_id):
254
 
        BzrError.__init__(self, repository=repository, file_id=file_id)
255
 
 
256
 
 
257
228
class NotStacked(BranchError):
258
229
 
259
230
    _fmt = "The branch '%(branch)s' is not stacked."
293
264
        self.base = base
294
265
 
295
266
 
 
267
class NoWhoami(BzrError):
 
268
 
 
269
    _fmt = ('Unable to determine your name.\n'
 
270
            "Please, set your name with the 'whoami' command.\n"
 
271
            'E.g. brz whoami "Your Name <name@example.com>"')
 
272
 
 
273
 
296
274
class BzrCommandError(BzrError):
297
275
    """Error from user command"""
298
276
 
407
385
class UnavailableRepresentation(InternalBzrError):
408
386
 
409
387
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
410
 
        "is encoded as '%(native)s'.")
 
388
            "is encoded as '%(native)s'.")
411
389
 
412
390
    def __init__(self, key, wanted, native):
413
391
        InternalBzrError.__init__(self)
437
415
class UnstackableRepositoryFormat(BzrError):
438
416
 
439
417
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
440
 
        "You will need to upgrade the repository to permit branch stacking.")
 
418
            "You will need to upgrade the repository to permit branch stacking.")
441
419
 
442
420
    def __init__(self, format, url):
443
421
        BzrError.__init__(self)
493
471
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
494
472
 
495
473
    def __init__(self, path, detail=None, controldir=None):
496
 
       from . import urlutils
497
 
       path = urlutils.unescape_for_display(path, 'ascii')
498
 
       if detail is not None:
499
 
           detail = ': ' + detail
500
 
       self.detail = detail
501
 
       self.controldir = controldir
502
 
       PathError.__init__(self, path=path)
 
474
        from . import urlutils
 
475
        path = urlutils.unescape_for_display(path, 'ascii')
 
476
        if detail is not None:
 
477
            detail = ': ' + detail
 
478
        self.detail = detail
 
479
        self.controldir = controldir
 
480
        PathError.__init__(self, path=path)
503
481
 
504
482
    def __repr__(self):
505
483
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
507
485
    def _get_format_string(self):
508
486
        # GZ 2017-06-08: Not the best place to lazy fill detail in.
509
487
        if self.detail is None:
510
 
           self.detail = self._get_detail()
 
488
            self.detail = self._get_detail()
511
489
        return super(NotBranchError, self)._get_format_string()
512
490
 
513
491
    def _get_detail(self):
535
513
    _fmt = 'No submit branch available for branch "%(path)s"'
536
514
 
537
515
    def __init__(self, branch):
538
 
       from . import urlutils
539
 
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
 
516
        from . import urlutils
 
517
        self.path = urlutils.unescape_for_display(branch.base, 'ascii')
540
518
 
541
519
 
542
520
class AlreadyControlDirError(PathError):
569
547
(use brz checkout if you wish to build a working tree): "%(path)s"'
570
548
 
571
549
 
572
 
class AtomicFileAlreadyClosed(PathError):
573
 
 
574
 
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
575
 
            ' "%(path)s"')
576
 
 
577
 
    def __init__(self, path, function):
578
 
        PathError.__init__(self, path=path, extra=None)
579
 
        self.function = function
580
 
 
581
 
 
582
550
class InaccessibleParent(PathError):
583
551
 
584
552
    _fmt = ('Parent not accessible given base "%(base)s" and'
592
560
class NoRepositoryPresent(BzrError):
593
561
 
594
562
    _fmt = 'No repository present: "%(path)s"'
 
563
 
595
564
    def __init__(self, controldir):
596
565
        BzrError.__init__(self)
597
566
        self.path = controldir.transport.clone('..').base
611
580
        self.format = format
612
581
 
613
582
 
 
583
class LineEndingError(BzrError):
 
584
 
 
585
    _fmt = ("Line ending corrupted for file: %(file)s; "
 
586
            "Maybe your files got corrupted in transport?")
 
587
 
 
588
    def __init__(self, file):
 
589
        self.file = file
 
590
 
 
591
 
614
592
class IncompatibleFormat(BzrError):
615
593
 
616
594
    _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
642
620
    """
643
621
 
644
622
    _fmt = "%(target)s\n" \
645
 
            "is not compatible with\n" \
646
 
            "%(source)s\n" \
647
 
            "%(details)s"
 
623
        "is not compatible with\n" \
 
624
        "%(source)s\n" \
 
625
        "%(details)s"
648
626
 
649
627
    def __init__(self, source, target, details=None):
650
628
        if details is None:
978
956
        self.revision_id = revision_id
979
957
 
980
958
 
981
 
class InvalidRevisionSpec(BzrError):
982
 
 
983
 
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
984
 
            " %(branch_url)s%(extra)s")
985
 
 
986
 
    def __init__(self, spec, branch, extra=None):
987
 
        BzrError.__init__(self, branch=branch, spec=spec)
988
 
        self.branch_url = getattr(branch, 'user_url', str(branch))
989
 
        if extra:
990
 
            self.extra = '\n' + str(extra)
991
 
        else:
992
 
            self.extra = ''
993
 
 
994
 
 
995
959
class AppendRevisionsOnlyViolation(BzrError):
996
960
 
997
961
    _fmt = ('Operation denied because it would change the main history,'
998
 
           ' which is not permitted by the append_revisions_only setting on'
999
 
           ' branch "%(location)s".')
 
962
            ' which is not permitted by the append_revisions_only setting on'
 
963
            ' branch "%(location)s".')
1000
964
 
1001
965
    def __init__(self, location):
1002
 
       import breezy.urlutils as urlutils
1003
 
       location = urlutils.unescape_for_display(location, 'ascii')
1004
 
       BzrError.__init__(self, location=location)
 
966
        import breezy.urlutils as urlutils
 
967
        location = urlutils.unescape_for_display(location, 'ascii')
 
968
        BzrError.__init__(self, location=location)
1005
969
 
1006
970
 
1007
971
class DivergedBranches(BzrError):
1047
1011
class NoCommonRoot(BzrError):
1048
1012
 
1049
1013
    _fmt = ("Revisions are not derived from the same root: "
1050
 
           "%(revision_a)s %(revision_b)s.")
 
1014
            "%(revision_a)s %(revision_b)s.")
1051
1015
 
1052
1016
    def __init__(self, revision_a, revision_b):
1053
1017
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
1059
1023
 
1060
1024
    def __init__(self, rev_id, not_ancestor_id):
1061
1025
        BzrError.__init__(self, rev_id=rev_id,
1062
 
            not_ancestor_id=not_ancestor_id)
 
1026
                          not_ancestor_id=not_ancestor_id)
1063
1027
 
1064
1028
 
1065
1029
class NoCommits(BranchError):
1073
1037
        BzrError.__init__(self, "Store %s is not listable" % store)
1074
1038
 
1075
1039
 
1076
 
 
1077
1040
class UnlistableBranch(BzrError):
1078
1041
 
1079
1042
    def __init__(self, br):
1221
1184
        if orig_error is None:
1222
1185
            orig_error = ''
1223
1186
        if msg is None:
1224
 
            msg =  ''
 
1187
            msg = ''
1225
1188
        self.msg = msg
1226
1189
        self.orig_error = orig_error
1227
1190
        BzrError.__init__(self)
1272
1235
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1273
1236
        self.exc_info = exc_info
1274
1237
        traceback_strings = traceback.format_exception(
1275
 
                self.exc_type, self.exc_value, self.exc_tb)
 
1238
            self.exc_type, self.exc_value, self.exc_tb)
1276
1239
        self.traceback_text = ''.join(traceback_strings)
1277
1240
 
1278
1241
 
1416
1379
        BzrError.__init__(self, basedir=tree.basedir)
1417
1380
 
1418
1381
 
1419
 
class CantReprocessAndShowBase(BzrError):
1420
 
 
1421
 
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
1422
 
           "the relationship of conflicting lines to the base")
1423
 
 
1424
 
 
1425
1382
class GraphCycleError(BzrError):
1426
1383
 
1427
1384
    _fmt = "Cycle in graph %(graph)r"
1585
1542
class BzrMoveFailedError(BzrError):
1586
1543
 
1587
1544
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1588
 
        "%(_has_extra)s%(extra)s")
 
1545
            "%(_has_extra)s%(extra)s")
1589
1546
 
1590
1547
    def __init__(self, from_path='', to_path='', extra=None):
1591
1548
        from breezy.osutils import splitpath
1621
1578
class BzrRenameFailedError(BzrMoveFailedError):
1622
1579
 
1623
1580
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1624
 
        "%(_has_extra)s%(extra)s")
 
1581
            "%(_has_extra)s%(extra)s")
1625
1582
 
1626
1583
    def __init__(self, from_path, to_path, extra=None):
1627
1584
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1673
1630
class BadConversionTarget(BzrError):
1674
1631
 
1675
1632
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1676
 
            "    %(problem)s"
 
1633
        "    %(problem)s"
1677
1634
 
1678
1635
    def __init__(self, problem, format, from_format=None):
1679
1636
        BzrError.__init__(self)
1724
1681
    keep, and delete it when you are done."""
1725
1682
 
1726
1683
    def __init__(self, limbo_dir):
1727
 
       BzrError.__init__(self)
1728
 
       self.limbo_dir = limbo_dir
 
1684
        BzrError.__init__(self)
 
1685
        self.limbo_dir = limbo_dir
1729
1686
 
1730
1687
 
1731
1688
class ExistingPendingDeletion(BzrError):
1735
1692
    wish to keep, and delete it when you are done."""
1736
1693
 
1737
1694
    def __init__(self, pending_deletion):
1738
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
 
1695
        BzrError.__init__(self, pending_deletion=pending_deletion)
1739
1696
 
1740
1697
 
1741
1698
class ImmortalLimbo(BzrError):
1745
1702
    keep, and delete it when you are done."""
1746
1703
 
1747
1704
    def __init__(self, limbo_dir):
1748
 
       BzrError.__init__(self)
1749
 
       self.limbo_dir = limbo_dir
 
1705
        BzrError.__init__(self)
 
1706
        self.limbo_dir = limbo_dir
1750
1707
 
1751
1708
 
1752
1709
class ImmortalPendingDeletion(BzrError):
1753
1710
 
1754
1711
    _fmt = ("Unable to delete transform temporary directory "
1755
 
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
1756
 
    "contains any files you wish to keep, and delete it when you are done.")
 
1712
            "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
 
1713
            "contains any files you wish to keep, and delete it when you are done.")
1757
1714
 
1758
1715
    def __init__(self, pending_deletion):
1759
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
 
1716
        BzrError.__init__(self, pending_deletion=pending_deletion)
1760
1717
 
1761
1718
 
1762
1719
class OutOfDateTree(BzrError):
1848
1805
class RichRootUpgradeRequired(UpgradeRequired):
1849
1806
 
1850
1807
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1851
 
           " a format which supports rich roots.")
 
1808
            " a format which supports rich roots.")
1852
1809
 
1853
1810
 
1854
1811
class LocalRequiresBoundBranch(BzrError):
1867
1824
        self.tname = type(method_self).__name__
1868
1825
 
1869
1826
 
 
1827
class FetchLimitUnsupported(UnsupportedOperation):
 
1828
 
 
1829
    fmt = ("InterBranch %(interbranch)r does not support fetching limits.")
 
1830
 
 
1831
    def __init__(self, interbranch):
 
1832
        BzrError.__init__(self, interbranch=interbranch)
 
1833
 
 
1834
 
1870
1835
class NonAsciiRevisionId(UnsupportedOperation):
1871
1836
    """Raised when a commit is attempting to set a non-ascii revision id
1872
1837
       but cant.
1873
1838
    """
1874
1839
 
1875
1840
 
 
1841
class SharedRepositoriesUnsupported(UnsupportedOperation):
 
1842
    _fmt = "Shared repositories are not supported by %(format)r."
 
1843
 
 
1844
    def __init__(self, format):
 
1845
        BzrError.__init__(self, format=format)
 
1846
 
 
1847
 
1876
1848
class GhostTagsNotSupported(BzrError):
1877
1849
 
1878
1850
    _fmt = "Ghost tags not supported by format %(format)r."
2021
1993
        self.revision_id = revision_id
2022
1994
 
2023
1995
 
2024
 
class IllegalUseOfScopeReplacer(InternalBzrError):
2025
 
 
2026
 
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2027
 
            " %(msg)s%(extra)s")
2028
 
 
2029
 
    def __init__(self, name, msg, extra=None):
2030
 
        BzrError.__init__(self)
2031
 
        self.name = name
2032
 
        self.msg = msg
2033
 
        if extra:
2034
 
            self.extra = ': ' + str(extra)
2035
 
        else:
2036
 
            self.extra = ''
2037
 
 
2038
 
 
2039
 
class InvalidImportLine(InternalBzrError):
2040
 
 
2041
 
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
2042
 
 
2043
 
    def __init__(self, text, msg):
2044
 
        BzrError.__init__(self)
2045
 
        self.text = text
2046
 
        self.msg = msg
2047
 
 
2048
 
 
2049
 
class ImportNameCollision(InternalBzrError):
2050
 
 
2051
 
    _fmt = ("Tried to import an object to the same name as"
2052
 
            " an existing object. %(name)s")
2053
 
 
2054
 
    def __init__(self, name):
2055
 
        BzrError.__init__(self)
2056
 
        self.name = name
2057
 
 
2058
 
 
2059
1996
class NotAMergeDirective(BzrError):
2060
1997
    """File starting with %(firstline)r is not a merge directive"""
 
1998
 
2061
1999
    def __init__(self, firstline):
2062
2000
        BzrError.__init__(self, firstline=firstline)
2063
2001
 
2145
2083
class TagsNotSupported(BzrError):
2146
2084
 
2147
2085
    _fmt = ("Tags not supported by %(branch)s;"
2148
 
            " you may be able to use brz upgrade.")
 
2086
            " you may be able to use 'brz upgrade %(branch_url)s'.")
2149
2087
 
2150
2088
    def __init__(self, branch):
2151
2089
        self.branch = branch
 
2090
        self.branch_url = branch.user_url
2152
2091
 
2153
2092
 
2154
2093
class TagAlreadyExists(BzrError):
2310
2249
            ' (See brz shelve --list).%(more)s')
2311
2250
 
2312
2251
 
2313
 
class UnableCreateSymlink(BzrError):
2314
 
 
2315
 
    _fmt = 'Unable to create symlink %(path_str)son this platform'
2316
 
 
2317
 
    def __init__(self, path=None):
2318
 
        path_str = ''
2319
 
        if path:
2320
 
            try:
2321
 
                path_str = repr(str(path))
2322
 
            except UnicodeEncodeError:
2323
 
                path_str = repr(path)
2324
 
            path_str += ' '
2325
 
        self.path_str = path_str
2326
 
 
2327
 
 
2328
2252
class UnableEncodePath(BzrError):
2329
2253
 
2330
2254
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2352
2276
    def __init__(self, host, port, orig_error):
2353
2277
        # nb: in python2.4 socket.error doesn't have a useful repr
2354
2278
        BzrError.__init__(self, host=host, port=port,
2355
 
            orig_error=repr(orig_error.args))
 
2279
                          orig_error=repr(orig_error.args))
2356
2280
 
2357
2281
 
2358
2282
class TipChangeRejected(BzrError):
2437
2361
class RecursiveBind(BzrError):
2438
2362
 
2439
2363
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2440
 
        'Please use `brz unbind` to fix.')
 
2364
            'Please use `brz unbind` to fix.')
2441
2365
 
2442
2366
    def __init__(self, branch_url):
2443
2367
        self.branch_url = branch_url
2459
2383
 
2460
2384
    _fmt = ('Cannot store uncommitted changes because this branch already'
2461
2385
            ' stores uncommitted changes.')
 
2386
 
 
2387
 
 
2388
class RevnoOutOfBounds(InternalBzrError):
 
2389
 
 
2390
    _fmt = ("The requested revision number %(revno)d is outside of the "
 
2391
            "expected boundaries (%(minimum)d <= %(maximum)d).")
 
2392
 
 
2393
    def __init__(self, revno, bounds):
 
2394
        InternalBzrError.__init__(
 
2395
            self, revno=revno, minimum=bounds[0], maximum=bounds[1])