~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
 
20
 
20
21
from bzrlib import (
21
22
    osutils,
22
23
    symbol_versioning,
31
32
 
32
33
 
33
34
# TODO: is there any value in providing the .args field used by standard
34
 
# python exceptions?   A list of values with no names seems less useful
 
35
# python exceptions?   A list of values with no names seems less useful 
35
36
# to me.
36
37
 
37
 
# TODO: Perhaps convert the exception to a string at the moment it's
 
38
# TODO: Perhaps convert the exception to a string at the moment it's 
38
39
# constructed to make sure it will succeed.  But that says nothing about
39
40
# exceptions that are never raised.
40
41
 
61
62
    :cvar _fmt: Format string to display the error; this is expanded
62
63
    by the instance's dict.
63
64
    """
64
 
 
 
65
    
65
66
    internal_error = False
66
67
 
67
68
    def __init__(self, msg=None, **kwds):
72
73
        arguments can be given.  The first is for generic "user" errors which
73
74
        are not intended to be caught and so do not need a specific subclass.
74
75
        The second case is for use with subclasses that provide a _fmt format
75
 
        string to print the arguments.
 
76
        string to print the arguments.  
76
77
 
77
 
        Keyword arguments are taken as parameters to the error, which can
78
 
        be inserted into the format string template.  It's recommended
79
 
        that subclasses override the __init__ method to require specific
 
78
        Keyword arguments are taken as parameters to the error, which can 
 
79
        be inserted into the format string template.  It's recommended 
 
80
        that subclasses override the __init__ method to require specific 
80
81
        parameters.
81
82
 
82
83
        :param msg: If given, this is the literal complete text for the error,
83
 
           not subject to expansion. 'msg' is used instead of 'message' because
84
 
           python evolved and, in 2.6, forbids the use of 'message'.
 
84
        not subject to expansion.
85
85
        """
86
86
        StandardError.__init__(self)
87
87
        if msg is not None:
102
102
            fmt = self._get_format_string()
103
103
            if fmt:
104
104
                d = dict(self.__dict__)
 
105
                # special case: python2.5 puts the 'message' attribute in a
 
106
                # slot, so it isn't seen in __dict__
 
107
                d['message'] = getattr(self, 'message', 'no message')
105
108
                s = fmt % d
106
109
                # __str__() should always return a 'str' object
107
110
                # never a 'unicode' object.
123
126
            # return a unicode object.
124
127
            u = unicode(u)
125
128
        return u
126
 
 
 
129
    
127
130
    def __str__(self):
128
131
        s = self._format()
129
132
        if isinstance(s, unicode):
133
136
            s = str(s)
134
137
        return s
135
138
 
136
 
    def __repr__(self):
137
 
        return '%s(%s)' % (self.__class__.__name__, str(self))
138
 
 
139
139
    def _get_format_string(self):
140
140
        """Return format string for this exception or None"""
141
141
        fmt = getattr(self, '_fmt', None)
154
154
               )
155
155
 
156
156
    def __eq__(self, other):
157
 
        if self.__class__ is not other.__class__:
 
157
        if self.__class__ != other.__class__:
158
158
            return NotImplemented
159
159
        return self.__dict__ == other.__dict__
160
160
 
204
204
 
205
205
 
206
206
class AlreadyBuilding(BzrError):
207
 
 
 
207
    
208
208
    _fmt = "The tree builder is already building a tree."
209
209
 
210
210
 
216
216
 
217
217
 
218
218
class BzrCheckError(InternalBzrError):
219
 
 
220
 
    _fmt = "Internal check failed: %(msg)s"
221
 
 
222
 
    def __init__(self, msg):
 
219
    
 
220
    _fmt = "Internal check failed: %(message)s"
 
221
 
 
222
    def __init__(self, message):
223
223
        BzrError.__init__(self)
224
 
        self.msg = msg
 
224
        self.message = message
225
225
 
226
226
 
227
227
class DirstateCorrupt(BzrError):
265
265
 
266
266
 
267
267
class InvalidEntryName(InternalBzrError):
268
 
 
 
268
    
269
269
    _fmt = "Invalid entry name: %(name)s"
270
270
 
271
271
    def __init__(self, name):
274
274
 
275
275
 
276
276
class InvalidRevisionNumber(BzrError):
277
 
 
 
277
    
278
278
    _fmt = "Invalid revision number %(revno)s"
279
279
 
280
280
    def __init__(self, revno):
329
329
class NoSuchId(BzrError):
330
330
 
331
331
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
332
 
 
 
332
    
333
333
    def __init__(self, tree, file_id):
334
334
        BzrError.__init__(self)
335
335
        self.file_id = file_id
362
362
class NoWorkingTree(BzrError):
363
363
 
364
364
    _fmt = 'No WorkingTree exists for "%(base)s".'
365
 
 
 
365
    
366
366
    def __init__(self, base):
367
367
        BzrError.__init__(self)
368
368
        self.base = base
477
477
    def __init__(self, name, value):
478
478
        BzrError.__init__(self, name=name, value=value)
479
479
 
480
 
 
 
480
    
481
481
class StrictCommitFailed(BzrError):
482
482
 
483
483
    _fmt = "Commit refused because there are unknown files in the tree"
486
486
# XXX: Should be unified with TransportError; they seem to represent the
487
487
# same thing
488
488
# RBC 20060929: I think that unifiying with TransportError would be a mistake
489
 
# - this is finer than a TransportError - and more useful as such. It
 
489
# - this is finer than a TransportError - and more useful as such. It 
490
490
# differentiates between 'transport has failed' and 'operation on a transport
491
491
# has failed.'
492
492
class PathError(BzrError):
493
 
 
 
493
    
494
494
    _fmt = "Generic path error: %(path)r%(extra)s)"
495
495
 
496
496
    def __init__(self, path, extra=None):
550
550
 
551
551
 
552
552
class ReadingCompleted(InternalBzrError):
553
 
 
 
553
    
554
554
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
555
555
            "called upon it - the request has been completed and no more "
556
556
            "data may be read.")
648
648
 
649
649
 
650
650
class ReadError(PathError):
651
 
 
 
651
    
652
652
    _fmt = """Error reading from %(path)r."""
653
653
 
654
654
 
689
689
 
690
690
# TODO: This is given a URL; we try to unescape it but doing that from inside
691
691
# the exception object is a bit undesirable.
692
 
# TODO: Probably this behavior of should be a common superclass
 
692
# TODO: Probably this behavior of should be a common superclass 
693
693
class NotBranchError(PathError):
694
694
 
695
695
    _fmt = 'Not a branch: "%(path)s".'
764
764
 
765
765
 
766
766
class UnknownFormatError(BzrError):
767
 
 
 
767
    
768
768
    _fmt = "Unknown %(kind)s format: %(format)r"
769
769
 
770
770
    def __init__(self, format, kind='branch'):
773
773
 
774
774
 
775
775
class IncompatibleFormat(BzrError):
776
 
 
 
776
    
777
777
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
778
778
 
779
779
    def __init__(self, format, bzrdir_format):
796
796
 
797
797
 
798
798
class IncompatibleRevision(BzrError):
799
 
 
 
799
    
800
800
    _fmt = "Revision is not compatible with %(repo_format)s"
801
801
 
802
802
    def __init__(self, repo_format):
1003
1003
 
1004
1004
class LockContention(LockError):
1005
1005
 
1006
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
 
1006
    _fmt = 'Could not acquire lock "%(lock)s"'
1007
1007
    # TODO: show full url for lock, combining the transport and relative
1008
1008
    # bits?
1009
1009
 
1010
1010
    internal_error = False
1011
1011
 
1012
 
    def __init__(self, lock, msg=''):
 
1012
    def __init__(self, lock):
1013
1013
        self.lock = lock
1014
 
        self.msg = msg
1015
1014
 
1016
1015
 
1017
1016
class LockBroken(LockError):
1131
1130
 
1132
1131
class NoSuchRevisionInTree(NoSuchRevision):
1133
1132
    """When using Tree.revision_tree, and the revision is not accessible."""
1134
 
 
 
1133
    
1135
1134
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1136
1135
 
1137
1136
    def __init__(self, tree, revision_id):
1201
1200
 
1202
1201
 
1203
1202
class NoCommonAncestor(BzrError):
1204
 
 
 
1203
    
1205
1204
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1206
1205
 
1207
1206
    def __init__(self, revision_a, revision_b):
1275
1274
        self.branch = branch
1276
1275
        self.master = master
1277
1276
 
1278
 
 
 
1277
        
1279
1278
class CommitToDoubleBoundBranch(BzrError):
1280
1279
 
1281
1280
    _fmt = ("Cannot commit to branch %(branch)s."
1311
1310
 
1312
1311
class WeaveError(BzrError):
1313
1312
 
1314
 
    _fmt = "Error in processing weave: %(msg)s"
 
1313
    _fmt = "Error in processing weave: %(message)s"
1315
1314
 
1316
 
    def __init__(self, msg=None):
 
1315
    def __init__(self, message=None):
1317
1316
        BzrError.__init__(self)
1318
 
        self.msg = msg
 
1317
        self.message = message
1319
1318
 
1320
1319
 
1321
1320
class WeaveRevisionAlreadyPresent(WeaveError):
1351
1350
class WeaveParentMismatch(WeaveError):
1352
1351
 
1353
1352
    _fmt = "Parents are mismatched between two revisions. %(message)s"
1354
 
 
 
1353
    
1355
1354
 
1356
1355
class WeaveInvalidChecksum(WeaveError):
1357
1356
 
1383
1382
 
1384
1383
 
1385
1384
class VersionedFileError(BzrError):
1386
 
 
 
1385
    
1387
1386
    _fmt = "Versioned file error"
1388
1387
 
1389
1388
 
1390
1389
class RevisionNotPresent(VersionedFileError):
1391
 
 
 
1390
    
1392
1391
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1393
1392
 
1394
1393
    def __init__(self, revision_id, file_id):
1398
1397
 
1399
1398
 
1400
1399
class RevisionAlreadyPresent(VersionedFileError):
1401
 
 
 
1400
    
1402
1401
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1403
1402
 
1404
1403
    def __init__(self, revision_id, file_id):
1413
1412
 
1414
1413
 
1415
1414
class KnitError(InternalBzrError):
1416
 
 
 
1415
    
1417
1416
    _fmt = "Knit error"
1418
1417
 
1419
1418
 
1427
1426
        self.how = how
1428
1427
 
1429
1428
 
1430
 
class SHA1KnitCorrupt(KnitCorrupt):
1431
 
 
1432
 
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
1433
 
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
1434
 
        "sha %(actual)s")
1435
 
 
1436
 
    def __init__(self, filename, actual, expected, key, content):
1437
 
        KnitError.__init__(self)
1438
 
        self.filename = filename
1439
 
        self.actual = actual
1440
 
        self.expected = expected
1441
 
        self.key = key
1442
 
        self.content = content
1443
 
 
1444
 
 
1445
1429
class KnitDataStreamIncompatible(KnitError):
1446
1430
    # Not raised anymore, as we can convert data streams.  In future we may
1447
1431
    # need it again for more exotic cases, so we're keeping it around for now.
1451
1435
    def __init__(self, stream_format, target_format):
1452
1436
        self.stream_format = stream_format
1453
1437
        self.target_format = target_format
1454
 
 
 
1438
        
1455
1439
 
1456
1440
class KnitDataStreamUnknown(KnitError):
1457
1441
    # Indicates a data stream we don't know how to handle.
1460
1444
 
1461
1445
    def __init__(self, stream_format):
1462
1446
        self.stream_format = stream_format
1463
 
 
 
1447
        
1464
1448
 
1465
1449
class KnitHeaderError(KnitError):
1466
1450
 
1476
1460
 
1477
1461
    Currently only 'fulltext' and 'line-delta' are supported.
1478
1462
    """
1479
 
 
 
1463
    
1480
1464
    _fmt = ("Knit index %(filename)s does not have a known method"
1481
1465
            " in options: %(options)r")
1482
1466
 
1486
1470
        self.options = options
1487
1471
 
1488
1472
 
1489
 
class RetryWithNewPacks(BzrError):
1490
 
    """Raised when we realize that the packs on disk have changed.
1491
 
 
1492
 
    This is meant as more of a signaling exception, to trap between where a
1493
 
    local error occurred and the code that can actually handle the error and
1494
 
    code that can retry appropriately.
1495
 
    """
1496
 
 
1497
 
    internal_error = True
1498
 
 
1499
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1500
 
            " %(orig_error)s")
1501
 
 
1502
 
    def __init__(self, context, reload_occurred, exc_info):
1503
 
        """create a new RetryWithNewPacks error.
1504
 
 
1505
 
        :param reload_occurred: Set to True if we know that the packs have
1506
 
            already been reloaded, and we are failing because of an in-memory
1507
 
            cache miss. If set to True then we will ignore if a reload says
1508
 
            nothing has changed, because we assume it has already reloaded. If
1509
 
            False, then a reload with nothing changed will force an error.
1510
 
        :param exc_info: The original exception traceback, so if there is a
1511
 
            problem we can raise the original error (value from sys.exc_info())
1512
 
        """
1513
 
        BzrError.__init__(self)
1514
 
        self.reload_occurred = reload_occurred
1515
 
        self.exc_info = exc_info
1516
 
        self.orig_error = exc_info[1]
1517
 
        # TODO: The global error handler should probably treat this by
1518
 
        #       raising/printing the original exception with a bit about
1519
 
        #       RetryWithNewPacks also not being caught
1520
 
 
1521
 
 
1522
 
class RetryAutopack(RetryWithNewPacks):
1523
 
    """Raised when we are autopacking and we find a missing file.
1524
 
 
1525
 
    Meant as a signaling exception, to tell the autopack code it should try
1526
 
    again.
1527
 
    """
1528
 
 
1529
 
    internal_error = True
1530
 
 
1531
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1532
 
            " context: %(context)s %(orig_error)s")
1533
 
 
1534
 
 
1535
1473
class NoSuchExportFormat(BzrError):
1536
 
 
 
1474
    
1537
1475
    _fmt = "Export format %(format)r not supported"
1538
1476
 
1539
1477
    def __init__(self, format):
1542
1480
 
1543
1481
 
1544
1482
class TransportError(BzrError):
1545
 
 
 
1483
    
1546
1484
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1547
1485
 
1548
1486
    def __init__(self, msg=None, orig_error=None):
1593
1531
 
1594
1532
class SmartMessageHandlerError(InternalBzrError):
1595
1533
 
1596
 
    _fmt = ("The message handler raised an exception:\n"
1597
 
            "%(traceback_text)s")
 
1534
    _fmt = "The message handler raised an exception: %(exc_value)s."
1598
1535
 
1599
1536
    def __init__(self, exc_info):
1600
 
        import traceback
1601
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1602
 
        self.exc_info = exc_info
1603
 
        traceback_strings = traceback.format_exception(
1604
 
                self.exc_type, self.exc_value, self.exc_tb)
1605
 
        self.traceback_text = ''.join(traceback_strings)
1606
 
 
 
1537
        self.exc_type, self.exc_value, self.tb = exc_info
 
1538
        
1607
1539
 
1608
1540
# A set of semi-meaningful errors which can be thrown
1609
1541
class TransportNotPossible(TransportError):
1635
1567
            self.port = ':%s' % port
1636
1568
 
1637
1569
 
1638
 
# XXX: This is also used for unexpected end of file, which is different at the
1639
 
# TCP level from "connection reset".
1640
1570
class ConnectionReset(TransportError):
1641
1571
 
1642
1572
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1683
1613
 
1684
1614
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1685
1615
 
1686
 
    def __init__(self, source, target, is_permanent=False):
 
1616
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
1687
1617
        self.source = source
1688
1618
        self.target = target
1689
1619
        if is_permanent:
1690
1620
            self.permanently = ' permanently'
1691
1621
        else:
1692
1622
            self.permanently = ''
 
1623
        self._qualified_proto = qual_proto
1693
1624
        TransportError.__init__(self)
1694
1625
 
 
1626
    def _requalify_url(self, url):
 
1627
        """Restore the qualified proto in front of the url"""
 
1628
        # When this exception is raised, source and target are in
 
1629
        # user readable format. But some transports may use a
 
1630
        # different proto (http+urllib:// will present http:// to
 
1631
        # the user. If a qualified proto is specified, the code
 
1632
        # trapping the exception can get the qualified urls to
 
1633
        # properly handle the redirection themself (creating a
 
1634
        # new transport object from the target url for example).
 
1635
        # But checking that the scheme of the original and
 
1636
        # redirected urls are the same can be tricky. (see the
 
1637
        # FIXME in BzrDir.open_from_transport for the unique use
 
1638
        # case so far).
 
1639
        if self._qualified_proto is None:
 
1640
            return url
 
1641
 
 
1642
        # The TODO related to NotBranchError mention that doing
 
1643
        # that kind of manipulation on the urls may not be the
 
1644
        # exception object job. On the other hand, this object is
 
1645
        # the interface between the code and the user so
 
1646
        # presenting the urls in different ways is indeed its
 
1647
        # job...
 
1648
        import urlparse
 
1649
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1650
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1651
                                   query, fragment))
 
1652
 
 
1653
    def get_source_url(self):
 
1654
        return self._requalify_url(self.source)
 
1655
 
 
1656
    def get_target_url(self):
 
1657
        return self._requalify_url(self.target)
 
1658
 
1695
1659
 
1696
1660
class TooManyRedirections(TransportError):
1697
1661
 
1709
1673
        if filename is None:
1710
1674
            filename = ""
1711
1675
        message = "Error(s) parsing config file %s:\n%s" % \
1712
 
            (filename, ('\n'.join(e.msg for e in errors)))
 
1676
            (filename, ('\n'.join(e.message for e in errors)))
1713
1677
        BzrError.__init__(self, message)
1714
1678
 
1715
1679
 
1732
1696
 
1733
1697
class WorkingTreeNotRevision(BzrError):
1734
1698
 
1735
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1699
    _fmt = ("The working tree for %(basedir)s has changed since" 
1736
1700
            " the last commit, but weave merge requires that it be"
1737
1701
            " unchanged")
1738
1702
 
1900
1864
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1901
1865
 
1902
1866
    def __init__(self, from_path='', to_path='', extra=None):
1903
 
        from bzrlib.osutils import splitpath
1904
1867
        BzrError.__init__(self)
1905
1868
        if extra:
1906
1869
            self.extra = ': ' + str(extra)
1910
1873
        has_from = len(from_path) > 0
1911
1874
        has_to = len(to_path) > 0
1912
1875
        if has_from:
1913
 
            self.from_path = splitpath(from_path)[-1]
 
1876
            self.from_path = osutils.splitpath(from_path)[-1]
1914
1877
        else:
1915
1878
            self.from_path = ''
1916
1879
 
1917
1880
        if has_to:
1918
 
            self.to_path = splitpath(to_path)[-1]
 
1881
            self.to_path = osutils.splitpath(to_path)[-1]
1919
1882
        else:
1920
1883
            self.to_path = ''
1921
1884
 
2052
2015
    _fmt = """This tree contains left-over files from a failed operation.
2053
2016
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2054
2017
    keep, and delete it when you are done."""
2055
 
 
 
2018
    
2056
2019
    def __init__(self, limbo_dir):
2057
2020
       BzrError.__init__(self)
2058
2021
       self.limbo_dir = limbo_dir
2174
2137
    _fmt = "Cannot perform local-only commits on unbound branches."
2175
2138
 
2176
2139
 
 
2140
class MissingProgressBarFinish(BzrError):
 
2141
 
 
2142
    _fmt = "A nested progress bar was not 'finished' correctly."
 
2143
 
 
2144
 
2177
2145
class InvalidProgressBarType(BzrError):
2178
2146
 
2179
2147
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
2205
2173
 
2206
2174
 
2207
2175
class BinaryFile(BzrError):
2208
 
 
 
2176
    
2209
2177
    _fmt = "File is binary but should be text."
2210
2178
 
2211
2179
 
2231
2199
 
2232
2200
 
2233
2201
class NotABundle(BzrError):
2234
 
 
 
2202
    
2235
2203
    _fmt = "Not a bzr revision-bundle: %(text)r"
2236
2204
 
2237
2205
    def __init__(self, text):
2239
2207
        self.text = text
2240
2208
 
2241
2209
 
2242
 
class BadBundle(BzrError):
2243
 
 
 
2210
class BadBundle(BzrError): 
 
2211
    
2244
2212
    _fmt = "Bad bzr revision-bundle: %(text)r"
2245
2213
 
2246
2214
    def __init__(self, text):
2248
2216
        self.text = text
2249
2217
 
2250
2218
 
2251
 
class MalformedHeader(BadBundle):
2252
 
 
 
2219
class MalformedHeader(BadBundle): 
 
2220
    
2253
2221
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2254
2222
 
2255
2223
 
2256
 
class MalformedPatches(BadBundle):
2257
 
 
 
2224
class MalformedPatches(BadBundle): 
 
2225
    
2258
2226
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2259
2227
 
2260
2228
 
2261
 
class MalformedFooter(BadBundle):
2262
 
 
 
2229
class MalformedFooter(BadBundle): 
 
2230
    
2263
2231
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2264
2232
 
2265
2233
 
2266
2234
class UnsupportedEOLMarker(BadBundle):
2267
 
 
2268
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
2235
    
 
2236
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
2269
2237
 
2270
2238
    def __init__(self):
2271
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
2239
        # XXX: BadBundle's constructor assumes there's explanatory text, 
2272
2240
        # but for this there is not
2273
2241
        BzrError.__init__(self)
2274
2242
 
2275
2243
 
2276
2244
class IncompatibleBundleFormat(BzrError):
2277
 
 
 
2245
    
2278
2246
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2279
2247
 
2280
2248
    def __init__(self, bundle_format, other):
2284
2252
 
2285
2253
 
2286
2254
class BadInventoryFormat(BzrError):
2287
 
 
 
2255
    
2288
2256
    _fmt = "Root class for inventory serialization errors"
2289
2257
 
2290
2258
 
2309
2277
        self.transport = transport
2310
2278
 
2311
2279
 
 
2280
class NoSmartServer(NotBranchError):
 
2281
 
 
2282
    _fmt = "No smart server available at %(url)s"
 
2283
 
 
2284
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
 
2285
    def __init__(self, url):
 
2286
        self.url = url
 
2287
 
 
2288
 
2312
2289
class UnknownSSH(BzrError):
2313
2290
 
2314
2291
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2334
2311
        self.revision_id = revision_id
2335
2312
        self.ghost_revision_id = ghost_revision_id
2336
2313
 
2337
 
 
 
2314
        
2338
2315
class GhostRevisionUnusableHere(BzrError):
2339
2316
 
2340
2317
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2432
2409
 
2433
2410
 
2434
2411
class UnsupportedInventoryKind(BzrError):
2435
 
 
 
2412
    
2436
2413
    _fmt = """Unsupported entry kind %(kind)s"""
2437
2414
 
2438
2415
    def __init__(self, kind):
2450
2427
 
2451
2428
 
2452
2429
class SubsumeTargetNeedsUpgrade(BzrError):
2453
 
 
 
2430
    
2454
2431
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2455
2432
 
2456
2433
    def __init__(self, other_tree):
2484
2461
    def __init__(self, branch):
2485
2462
        self.branch = branch
2486
2463
 
2487
 
 
 
2464
        
2488
2465
class TagAlreadyExists(BzrError):
2489
2466
 
2490
2467
    _fmt = "Tag %(tag_name)s already exists."
2495
2472
 
2496
2473
class MalformedBugIdentifier(BzrError):
2497
2474
 
2498
 
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
2499
 
            'See "bzr help bugs" for more information on this feature.')
 
2475
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2500
2476
 
2501
2477
    def __init__(self, bug_id, reason):
2502
2478
        self.bug_id = bug_id
2523
2499
        self.branch = branch
2524
2500
 
2525
2501
 
2526
 
class InvalidLineInBugsProperty(BzrError):
2527
 
 
2528
 
    _fmt = ("Invalid line in bugs property: '%(line)s'")
2529
 
 
2530
 
    def __init__(self, line):
2531
 
        self.line = line
2532
 
 
2533
 
 
2534
 
class InvalidBugStatus(BzrError):
2535
 
 
2536
 
    _fmt = ("Invalid bug status: '%(status)s'")
2537
 
 
2538
 
    def __init__(self, status):
2539
 
        self.status = status
2540
 
 
2541
 
 
2542
2502
class UnexpectedSmartServerResponse(BzrError):
2543
2503
 
2544
2504
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2548
2508
 
2549
2509
 
2550
2510
class ErrorFromSmartServer(BzrError):
2551
 
    """An error was received from a smart server.
2552
 
 
2553
 
    :seealso: UnknownErrorFromSmartServer
2554
 
    """
2555
2511
 
2556
2512
    _fmt = "Error received from smart server: %(error_tuple)r"
2557
2513
 
2566
2522
        self.error_args = error_tuple[1:]
2567
2523
 
2568
2524
 
2569
 
class UnknownErrorFromSmartServer(BzrError):
2570
 
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
2571
 
    error.
2572
 
 
2573
 
    This is distinct from ErrorFromSmartServer so that it is possible to
2574
 
    distinguish between the following two cases:
2575
 
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
2576
 
        and so should provoke a traceback to the user.
2577
 
      - ErrorFromSmartServer was caught but its error_tuple could not be
2578
 
        translated.  This is probably because the server sent us garbage, and
2579
 
        should not provoke a traceback.
2580
 
    """
2581
 
 
2582
 
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2583
 
 
2584
 
    internal_error = False
2585
 
 
2586
 
    def __init__(self, error_from_smart_server):
2587
 
        """Constructor.
2588
 
 
2589
 
        :param error_from_smart_server: An ErrorFromSmartServer instance.
2590
 
        """
2591
 
        self.error_from_smart_server = error_from_smart_server
2592
 
        self.error_tuple = error_from_smart_server.error_tuple
2593
 
 
2594
 
 
2595
2525
class ContainerError(BzrError):
2596
2526
    """Base class of container errors."""
2597
2527
 
2599
2529
class UnknownContainerFormatError(ContainerError):
2600
2530
 
2601
2531
    _fmt = "Unrecognised container format: %(container_format)r"
2602
 
 
 
2532
    
2603
2533
    def __init__(self, container_format):
2604
2534
        self.container_format = container_format
2605
2535
 
2669
2599
 
2670
2600
class NoMailAddressSpecified(BzrError):
2671
2601
 
2672
 
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
 
2602
    _fmt = "No mail-to address specified."
2673
2603
 
2674
2604
 
2675
2605
class UnknownMailClient(BzrError):
2755
2685
    _fmt = "'%(display_url)s' is already standalone."
2756
2686
 
2757
2687
 
2758
 
class AlreadyWithTrees(BzrDirError):
2759
 
 
2760
 
    _fmt = ("Shared repository '%(display_url)s' already creates "
2761
 
            "working trees.")
2762
 
 
2763
 
 
2764
 
class AlreadyWithNoTrees(BzrDirError):
2765
 
 
2766
 
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
2767
 
            "working trees.")
2768
 
 
2769
 
 
2770
2688
class ReconfigurationNotSupported(BzrDirError):
2771
2689
 
2772
2690
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2826
2744
 
2827
2745
 
2828
2746
class CommandAvailableInPlugin(StandardError):
2829
 
 
 
2747
    
2830
2748
    internal_error = False
2831
2749
 
2832
2750
    def __init__(self, cmd_name, plugin_metadata, provider):
2833
 
 
 
2751
        
2834
2752
        self.plugin_metadata = plugin_metadata
2835
2753
        self.cmd_name = cmd_name
2836
2754
        self.provider = provider
2837
2755
 
2838
2756
    def __str__(self):
2839
2757
 
2840
 
        _fmt = ('"%s" is not a standard bzr command. \n'
 
2758
        _fmt = ('"%s" is not a standard bzr command. \n' 
2841
2759
                'However, the following official plugin provides this command: %s\n'
2842
2760
                'You can install it by going to: %s'
2843
 
                % (self.cmd_name, self.plugin_metadata['name'],
 
2761
                % (self.cmd_name, self.plugin_metadata['name'], 
2844
2762
                    self.plugin_metadata['url']))
2845
2763
 
2846
2764
        return _fmt
2847
2765
 
2848
2766
 
2849
2767
class NoPluginAvailable(BzrError):
2850
 
    pass
 
2768
    pass    
2851
2769
 
2852
2770
 
2853
2771
class NotATerminal(BzrError):
2861
2779
            'user encoding %(user_encoding)s')
2862
2780
 
2863
2781
    def __init__(self, path, kind):
2864
 
        from bzrlib.osutils import get_user_encoding
2865
2782
        self.path = path
2866
2783
        self.kind = kind
2867
2784
        self.user_encoding = osutils.get_user_encoding()
2937
2854
    """A pre_change_branch_tip hook function may raise this to cleanly and
2938
2855
    explicitly abort a change to a branch tip.
2939
2856
    """
2940
 
 
 
2857
    
2941
2858
    _fmt = u"Tip change rejected: %(msg)s"
2942
2859
 
2943
2860
    def __init__(self, msg):
2944
2861
        self.msg = msg
2945
2862
 
2946
 
 
2947
 
class ShelfCorrupt(BzrError):
2948
 
 
2949
 
    _fmt = "Shelf corrupt."
2950
 
 
2951
 
 
2952
 
class NoSuchShelfId(BzrError):
2953
 
 
2954
 
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
2955
 
 
2956
 
    def __init__(self, shelf_id):
2957
 
        BzrError.__init__(self, shelf_id=shelf_id)
2958
 
 
2959
 
 
2960
 
class InvalidShelfId(BzrError):
2961
 
 
2962
 
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
2963
 
 
2964
 
    def __init__(self, invalid_id):
2965
 
        BzrError.__init__(self, invalid_id=invalid_id)
2966
 
 
2967
 
 
2968
 
class UserAbort(BzrError):
2969
 
 
2970
 
    _fmt = 'The user aborted the operation.'
2971
 
 
2972
 
 
2973
 
class MustHaveWorkingTree(BzrError):
2974
 
 
2975
 
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
2976
 
 
2977
 
    def __init__(self, format, url):
2978
 
        BzrError.__init__(self, format=format, url=url)
2979
 
 
2980
 
 
2981
 
class NoSuchView(BzrError):
2982
 
    """A view does not exist.
2983
 
    """
2984
 
 
2985
 
    _fmt = u"No such view: %(view_name)s."
2986
 
 
2987
 
    def __init__(self, view_name):
2988
 
        self.view_name = view_name
2989
 
 
2990
 
 
2991
 
class ViewsNotSupported(BzrError):
2992
 
    """Views are not supported by a tree format.
2993
 
    """
2994
 
 
2995
 
    _fmt = ("Views are not supported by %(tree)s;"
2996
 
            " use 'bzr upgrade' to change your tree to a later format.")
2997
 
 
2998
 
    def __init__(self, tree):
2999
 
        self.tree = tree
3000
 
 
3001
 
 
3002
 
class FileOutsideView(BzrError):
3003
 
 
3004
 
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
3005
 
            '%(view_str)s')
3006
 
 
3007
 
    def __init__(self, file_name, view_files):
3008
 
        self.file_name = file_name
3009
 
        self.view_str = ", ".join(view_files)
3010
 
 
3011
 
 
3012
 
class UnresumableWriteGroup(BzrError):
3013
 
 
3014
 
    _fmt = ("Repository %(repository)s cannot resume write group "
3015
 
            "%(write_groups)r: %(reason)s")
3016
 
 
3017
 
    internal_error = True
3018
 
 
3019
 
    def __init__(self, repository, write_groups, reason):
3020
 
        self.repository = repository
3021
 
        self.write_groups = write_groups
3022
 
        self.reason = reason
3023
 
 
3024
 
 
3025
 
class UnsuspendableWriteGroup(BzrError):
3026
 
 
3027
 
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
3028
 
 
3029
 
    internal_error = True
3030
 
 
3031
 
    def __init__(self, repository):
3032
 
        self.repository = repository