/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 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

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:
995
973
class AppendRevisionsOnlyViolation(BzrError):
996
974
 
997
975
    _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".')
 
976
            ' which is not permitted by the append_revisions_only setting on'
 
977
            ' branch "%(location)s".')
1000
978
 
1001
979
    def __init__(self, location):
1002
 
       import breezy.urlutils as urlutils
1003
 
       location = urlutils.unescape_for_display(location, 'ascii')
1004
 
       BzrError.__init__(self, location=location)
 
980
        import breezy.urlutils as urlutils
 
981
        location = urlutils.unescape_for_display(location, 'ascii')
 
982
        BzrError.__init__(self, location=location)
1005
983
 
1006
984
 
1007
985
class DivergedBranches(BzrError):
1047
1025
class NoCommonRoot(BzrError):
1048
1026
 
1049
1027
    _fmt = ("Revisions are not derived from the same root: "
1050
 
           "%(revision_a)s %(revision_b)s.")
 
1028
            "%(revision_a)s %(revision_b)s.")
1051
1029
 
1052
1030
    def __init__(self, revision_a, revision_b):
1053
1031
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
1059
1037
 
1060
1038
    def __init__(self, rev_id, not_ancestor_id):
1061
1039
        BzrError.__init__(self, rev_id=rev_id,
1062
 
            not_ancestor_id=not_ancestor_id)
 
1040
                          not_ancestor_id=not_ancestor_id)
1063
1041
 
1064
1042
 
1065
1043
class NoCommits(BranchError):
1073
1051
        BzrError.__init__(self, "Store %s is not listable" % store)
1074
1052
 
1075
1053
 
1076
 
 
1077
1054
class UnlistableBranch(BzrError):
1078
1055
 
1079
1056
    def __init__(self, br):
1221
1198
        if orig_error is None:
1222
1199
            orig_error = ''
1223
1200
        if msg is None:
1224
 
            msg =  ''
 
1201
            msg = ''
1225
1202
        self.msg = msg
1226
1203
        self.orig_error = orig_error
1227
1204
        BzrError.__init__(self)
1272
1249
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1273
1250
        self.exc_info = exc_info
1274
1251
        traceback_strings = traceback.format_exception(
1275
 
                self.exc_type, self.exc_value, self.exc_tb)
 
1252
            self.exc_type, self.exc_value, self.exc_tb)
1276
1253
        self.traceback_text = ''.join(traceback_strings)
1277
1254
 
1278
1255
 
1416
1393
        BzrError.__init__(self, basedir=tree.basedir)
1417
1394
 
1418
1395
 
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
1396
class GraphCycleError(BzrError):
1426
1397
 
1427
1398
    _fmt = "Cycle in graph %(graph)r"
1585
1556
class BzrMoveFailedError(BzrError):
1586
1557
 
1587
1558
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1588
 
        "%(_has_extra)s%(extra)s")
 
1559
            "%(_has_extra)s%(extra)s")
1589
1560
 
1590
1561
    def __init__(self, from_path='', to_path='', extra=None):
1591
1562
        from breezy.osutils import splitpath
1621
1592
class BzrRenameFailedError(BzrMoveFailedError):
1622
1593
 
1623
1594
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1624
 
        "%(_has_extra)s%(extra)s")
 
1595
            "%(_has_extra)s%(extra)s")
1625
1596
 
1626
1597
    def __init__(self, from_path, to_path, extra=None):
1627
1598
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1673
1644
class BadConversionTarget(BzrError):
1674
1645
 
1675
1646
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1676
 
            "    %(problem)s"
 
1647
        "    %(problem)s"
1677
1648
 
1678
1649
    def __init__(self, problem, format, from_format=None):
1679
1650
        BzrError.__init__(self)
1724
1695
    keep, and delete it when you are done."""
1725
1696
 
1726
1697
    def __init__(self, limbo_dir):
1727
 
       BzrError.__init__(self)
1728
 
       self.limbo_dir = limbo_dir
 
1698
        BzrError.__init__(self)
 
1699
        self.limbo_dir = limbo_dir
1729
1700
 
1730
1701
 
1731
1702
class ExistingPendingDeletion(BzrError):
1735
1706
    wish to keep, and delete it when you are done."""
1736
1707
 
1737
1708
    def __init__(self, pending_deletion):
1738
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
 
1709
        BzrError.__init__(self, pending_deletion=pending_deletion)
1739
1710
 
1740
1711
 
1741
1712
class ImmortalLimbo(BzrError):
1745
1716
    keep, and delete it when you are done."""
1746
1717
 
1747
1718
    def __init__(self, limbo_dir):
1748
 
       BzrError.__init__(self)
1749
 
       self.limbo_dir = limbo_dir
 
1719
        BzrError.__init__(self)
 
1720
        self.limbo_dir = limbo_dir
1750
1721
 
1751
1722
 
1752
1723
class ImmortalPendingDeletion(BzrError):
1753
1724
 
1754
1725
    _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.")
 
1726
            "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
 
1727
            "contains any files you wish to keep, and delete it when you are done.")
1757
1728
 
1758
1729
    def __init__(self, pending_deletion):
1759
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
 
1730
        BzrError.__init__(self, pending_deletion=pending_deletion)
1760
1731
 
1761
1732
 
1762
1733
class OutOfDateTree(BzrError):
1848
1819
class RichRootUpgradeRequired(UpgradeRequired):
1849
1820
 
1850
1821
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1851
 
           " a format which supports rich roots.")
 
1822
            " a format which supports rich roots.")
1852
1823
 
1853
1824
 
1854
1825
class LocalRequiresBoundBranch(BzrError):
1867
1838
        self.tname = type(method_self).__name__
1868
1839
 
1869
1840
 
 
1841
class FetchLimitUnsupported(UnsupportedOperation):
 
1842
 
 
1843
    fmt = ("InterBranch %(interbranch)r does not support fetching limits.")
 
1844
 
 
1845
    def __init__(self, interbranch):
 
1846
        BzrError.__init__(self, interbranch=interbranch)
 
1847
 
 
1848
 
1870
1849
class NonAsciiRevisionId(UnsupportedOperation):
1871
1850
    """Raised when a commit is attempting to set a non-ascii revision id
1872
1851
       but cant.
1873
1852
    """
1874
1853
 
1875
1854
 
 
1855
class SharedRepositoriesUnsupported(UnsupportedOperation):
 
1856
    _fmt = "Shared repositories are not supported by %(format)r."
 
1857
 
 
1858
    def __init__(self, format):
 
1859
        BzrError.__init__(self, format=format)
 
1860
 
 
1861
 
1876
1862
class GhostTagsNotSupported(BzrError):
1877
1863
 
1878
1864
    _fmt = "Ghost tags not supported by format %(format)r."
2021
2007
        self.revision_id = revision_id
2022
2008
 
2023
2009
 
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
2010
class NotAMergeDirective(BzrError):
2060
2011
    """File starting with %(firstline)r is not a merge directive"""
 
2012
 
2061
2013
    def __init__(self, firstline):
2062
2014
        BzrError.__init__(self, firstline=firstline)
2063
2015
 
2145
2097
class TagsNotSupported(BzrError):
2146
2098
 
2147
2099
    _fmt = ("Tags not supported by %(branch)s;"
2148
 
            " you may be able to use brz upgrade.")
 
2100
            " you may be able to use 'brz upgrade %(branch_url)s'.")
2149
2101
 
2150
2102
    def __init__(self, branch):
2151
2103
        self.branch = branch
 
2104
        self.branch_url = branch.user_url
2152
2105
 
2153
2106
 
2154
2107
class TagAlreadyExists(BzrError):
2310
2263
            ' (See brz shelve --list).%(more)s')
2311
2264
 
2312
2265
 
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
2266
class UnableEncodePath(BzrError):
2329
2267
 
2330
2268
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2352
2290
    def __init__(self, host, port, orig_error):
2353
2291
        # nb: in python2.4 socket.error doesn't have a useful repr
2354
2292
        BzrError.__init__(self, host=host, port=port,
2355
 
            orig_error=repr(orig_error.args))
 
2293
                          orig_error=repr(orig_error.args))
2356
2294
 
2357
2295
 
2358
2296
class TipChangeRejected(BzrError):
2437
2375
class RecursiveBind(BzrError):
2438
2376
 
2439
2377
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2440
 
        'Please use `brz unbind` to fix.')
 
2378
            'Please use `brz unbind` to fix.')
2441
2379
 
2442
2380
    def __init__(self, branch_url):
2443
2381
        self.branch_url = branch_url
2459
2397
 
2460
2398
    _fmt = ('Cannot store uncommitted changes because this branch already'
2461
2399
            ' stores uncommitted changes.')
 
2400
 
 
2401
 
 
2402
class RevnoOutOfBounds(InternalBzrError):
 
2403
 
 
2404
    _fmt = ("The requested revision number %(revno)d is outside of the "
 
2405
            "expected boundaries (%(minimum)d <= %(maximum)d).")
 
2406
 
 
2407
    def __init__(self, revno, bounds):
 
2408
        InternalBzrError.__init__(
 
2409
            self, revno=revno, minimum=bounds[0], maximum=bounds[1])