~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
20
 
 
21
20
from bzrlib import (
22
21
    osutils,
23
22
    symbol_versioning,
32
31
 
33
32
 
34
33
# TODO: is there any value in providing the .args field used by standard
35
 
# python exceptions?   A list of values with no names seems less useful 
 
34
# python exceptions?   A list of values with no names seems less useful
36
35
# to me.
37
36
 
38
 
# TODO: Perhaps convert the exception to a string at the moment it's 
 
37
# TODO: Perhaps convert the exception to a string at the moment it's
39
38
# constructed to make sure it will succeed.  But that says nothing about
40
39
# exceptions that are never raised.
41
40
 
62
61
    :cvar _fmt: Format string to display the error; this is expanded
63
62
    by the instance's dict.
64
63
    """
65
 
    
 
64
 
66
65
    internal_error = False
67
66
 
68
67
    def __init__(self, msg=None, **kwds):
73
72
        arguments can be given.  The first is for generic "user" errors which
74
73
        are not intended to be caught and so do not need a specific subclass.
75
74
        The second case is for use with subclasses that provide a _fmt format
76
 
        string to print the arguments.  
 
75
        string to print the arguments.
77
76
 
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 
 
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
81
80
        parameters.
82
81
 
83
82
        :param msg: If given, this is the literal complete text for the error,
84
 
        not subject to expansion.
 
83
           not subject to expansion. 'msg' is used instead of 'message' because
 
84
           python evolved and, in 2.6, forbids the use of 'message'.
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')
108
105
                s = fmt % d
109
106
                # __str__() should always return a 'str' object
110
107
                # never a 'unicode' object.
126
123
            # return a unicode object.
127
124
            u = unicode(u)
128
125
        return u
129
 
    
 
126
 
130
127
    def __str__(self):
131
128
        s = self._format()
132
129
        if isinstance(s, unicode):
136
133
            s = str(s)
137
134
        return s
138
135
 
 
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__ != other.__class__:
 
157
        if self.__class__ is not 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: %(message)s"
221
 
 
222
 
    def __init__(self, message):
 
219
 
 
220
    _fmt = "Internal check failed: %(msg)s"
 
221
 
 
222
    def __init__(self, msg):
223
223
        BzrError.__init__(self)
224
 
        self.message = message
 
224
        self.msg = msg
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.")
636
636
        self.url = url
637
637
 
638
638
 
 
639
class UnstackableLocationError(BzrError):
 
640
 
 
641
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
 
642
 
 
643
    def __init__(self, branch_url, target_url):
 
644
        BzrError.__init__(self)
 
645
        self.branch_url = branch_url
 
646
        self.target_url = target_url
 
647
 
 
648
 
639
649
class UnstackableRepositoryFormat(BzrError):
640
650
 
641
651
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
648
658
 
649
659
 
650
660
class ReadError(PathError):
651
 
    
 
661
 
652
662
    _fmt = """Error reading from %(path)r."""
653
663
 
654
664
 
689
699
 
690
700
# TODO: This is given a URL; we try to unescape it but doing that from inside
691
701
# the exception object is a bit undesirable.
692
 
# TODO: Probably this behavior of should be a common superclass 
 
702
# TODO: Probably this behavior of should be a common superclass
693
703
class NotBranchError(PathError):
694
704
 
695
705
    _fmt = 'Not a branch: "%(path)s".'
764
774
 
765
775
 
766
776
class UnknownFormatError(BzrError):
767
 
    
 
777
 
768
778
    _fmt = "Unknown %(kind)s format: %(format)r"
769
779
 
770
780
    def __init__(self, format, kind='branch'):
773
783
 
774
784
 
775
785
class IncompatibleFormat(BzrError):
776
 
    
 
786
 
777
787
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
778
788
 
779
789
    def __init__(self, format, bzrdir_format):
783
793
 
784
794
 
785
795
class IncompatibleRepositories(BzrError):
 
796
    """Report an error that two repositories are not compatible.
 
797
 
 
798
    Note that the source and target repositories are permitted to be strings:
 
799
    this exception is thrown from the smart server and may refer to a
 
800
    repository the client hasn't opened.
 
801
    """
786
802
 
787
803
    _fmt = "%(target)s\n" \
788
804
            "is not compatible with\n" \
796
812
 
797
813
 
798
814
class IncompatibleRevision(BzrError):
799
 
    
 
815
 
800
816
    _fmt = "Revision is not compatible with %(repo_format)s"
801
817
 
802
818
    def __init__(self, repo_format):
1003
1019
 
1004
1020
class LockContention(LockError):
1005
1021
 
1006
 
    _fmt = 'Could not acquire lock "%(lock)s"'
 
1022
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
1007
1023
    # TODO: show full url for lock, combining the transport and relative
1008
1024
    # bits?
1009
1025
 
1010
1026
    internal_error = False
1011
1027
 
1012
 
    def __init__(self, lock):
 
1028
    def __init__(self, lock, msg=''):
1013
1029
        self.lock = lock
 
1030
        self.msg = msg
1014
1031
 
1015
1032
 
1016
1033
class LockBroken(LockError):
1130
1147
 
1131
1148
class NoSuchRevisionInTree(NoSuchRevision):
1132
1149
    """When using Tree.revision_tree, and the revision is not accessible."""
1133
 
    
 
1150
 
1134
1151
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1135
1152
 
1136
1153
    def __init__(self, tree, revision_id):
1172
1189
class DivergedBranches(BzrError):
1173
1190
 
1174
1191
    _fmt = ("These branches have diverged."
1175
 
            " Use the merge command to reconcile them.")
 
1192
            " Use the missing command to see how.\n"
 
1193
            "Use the merge command to reconcile them.")
1176
1194
 
1177
1195
    def __init__(self, branch1, branch2):
1178
1196
        self.branch1 = branch1
1200
1218
 
1201
1219
 
1202
1220
class NoCommonAncestor(BzrError):
1203
 
    
 
1221
 
1204
1222
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1205
1223
 
1206
1224
    def __init__(self, revision_a, revision_b):
1226
1244
            not_ancestor_id=not_ancestor_id)
1227
1245
 
1228
1246
 
1229
 
class InstallFailed(BzrError):
1230
 
 
1231
 
    def __init__(self, revisions):
1232
 
        revision_str = ", ".join(str(r) for r in revisions)
1233
 
        msg = "Could not install revisions:\n%s" % revision_str
1234
 
        BzrError.__init__(self, msg)
1235
 
        self.revisions = revisions
1236
 
 
1237
 
 
1238
1247
class AmbiguousBase(BzrError):
1239
1248
 
1240
1249
    def __init__(self, bases):
1274
1283
        self.branch = branch
1275
1284
        self.master = master
1276
1285
 
1277
 
        
 
1286
 
1278
1287
class CommitToDoubleBoundBranch(BzrError):
1279
1288
 
1280
1289
    _fmt = ("Cannot commit to branch %(branch)s."
1310
1319
 
1311
1320
class WeaveError(BzrError):
1312
1321
 
1313
 
    _fmt = "Error in processing weave: %(message)s"
 
1322
    _fmt = "Error in processing weave: %(msg)s"
1314
1323
 
1315
 
    def __init__(self, message=None):
 
1324
    def __init__(self, msg=None):
1316
1325
        BzrError.__init__(self)
1317
 
        self.message = message
 
1326
        self.msg = msg
1318
1327
 
1319
1328
 
1320
1329
class WeaveRevisionAlreadyPresent(WeaveError):
1350
1359
class WeaveParentMismatch(WeaveError):
1351
1360
 
1352
1361
    _fmt = "Parents are mismatched between two revisions. %(message)s"
1353
 
    
 
1362
 
1354
1363
 
1355
1364
class WeaveInvalidChecksum(WeaveError):
1356
1365
 
1382
1391
 
1383
1392
 
1384
1393
class VersionedFileError(BzrError):
1385
 
    
 
1394
 
1386
1395
    _fmt = "Versioned file error"
1387
1396
 
1388
1397
 
1389
1398
class RevisionNotPresent(VersionedFileError):
1390
 
    
 
1399
 
1391
1400
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1392
1401
 
1393
1402
    def __init__(self, revision_id, file_id):
1397
1406
 
1398
1407
 
1399
1408
class RevisionAlreadyPresent(VersionedFileError):
1400
 
    
 
1409
 
1401
1410
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1402
1411
 
1403
1412
    def __init__(self, revision_id, file_id):
1412
1421
 
1413
1422
 
1414
1423
class KnitError(InternalBzrError):
1415
 
    
 
1424
 
1416
1425
    _fmt = "Knit error"
1417
1426
 
1418
1427
 
1426
1435
        self.how = how
1427
1436
 
1428
1437
 
 
1438
class SHA1KnitCorrupt(KnitCorrupt):
 
1439
 
 
1440
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
 
1441
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
 
1442
        "sha %(actual)s")
 
1443
 
 
1444
    def __init__(self, filename, actual, expected, key, content):
 
1445
        KnitError.__init__(self)
 
1446
        self.filename = filename
 
1447
        self.actual = actual
 
1448
        self.expected = expected
 
1449
        self.key = key
 
1450
        self.content = content
 
1451
 
 
1452
 
1429
1453
class KnitDataStreamIncompatible(KnitError):
1430
1454
    # Not raised anymore, as we can convert data streams.  In future we may
1431
1455
    # need it again for more exotic cases, so we're keeping it around for now.
1435
1459
    def __init__(self, stream_format, target_format):
1436
1460
        self.stream_format = stream_format
1437
1461
        self.target_format = target_format
1438
 
        
 
1462
 
1439
1463
 
1440
1464
class KnitDataStreamUnknown(KnitError):
1441
1465
    # Indicates a data stream we don't know how to handle.
1444
1468
 
1445
1469
    def __init__(self, stream_format):
1446
1470
        self.stream_format = stream_format
1447
 
        
 
1471
 
1448
1472
 
1449
1473
class KnitHeaderError(KnitError):
1450
1474
 
1460
1484
 
1461
1485
    Currently only 'fulltext' and 'line-delta' are supported.
1462
1486
    """
1463
 
    
 
1487
 
1464
1488
    _fmt = ("Knit index %(filename)s does not have a known method"
1465
1489
            " in options: %(options)r")
1466
1490
 
1470
1494
        self.options = options
1471
1495
 
1472
1496
 
 
1497
class RetryWithNewPacks(BzrError):
 
1498
    """Raised when we realize that the packs on disk have changed.
 
1499
 
 
1500
    This is meant as more of a signaling exception, to trap between where a
 
1501
    local error occurred and the code that can actually handle the error and
 
1502
    code that can retry appropriately.
 
1503
    """
 
1504
 
 
1505
    internal_error = True
 
1506
 
 
1507
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
 
1508
            " %(orig_error)s")
 
1509
 
 
1510
    def __init__(self, context, reload_occurred, exc_info):
 
1511
        """create a new RetryWithNewPacks error.
 
1512
 
 
1513
        :param reload_occurred: Set to True if we know that the packs have
 
1514
            already been reloaded, and we are failing because of an in-memory
 
1515
            cache miss. If set to True then we will ignore if a reload says
 
1516
            nothing has changed, because we assume it has already reloaded. If
 
1517
            False, then a reload with nothing changed will force an error.
 
1518
        :param exc_info: The original exception traceback, so if there is a
 
1519
            problem we can raise the original error (value from sys.exc_info())
 
1520
        """
 
1521
        BzrError.__init__(self)
 
1522
        self.reload_occurred = reload_occurred
 
1523
        self.exc_info = exc_info
 
1524
        self.orig_error = exc_info[1]
 
1525
        # TODO: The global error handler should probably treat this by
 
1526
        #       raising/printing the original exception with a bit about
 
1527
        #       RetryWithNewPacks also not being caught
 
1528
 
 
1529
 
 
1530
class RetryAutopack(RetryWithNewPacks):
 
1531
    """Raised when we are autopacking and we find a missing file.
 
1532
 
 
1533
    Meant as a signaling exception, to tell the autopack code it should try
 
1534
    again.
 
1535
    """
 
1536
 
 
1537
    internal_error = True
 
1538
 
 
1539
    _fmt = ("Pack files have changed, reload and try autopack again."
 
1540
            " context: %(context)s %(orig_error)s")
 
1541
 
 
1542
 
1473
1543
class NoSuchExportFormat(BzrError):
1474
 
    
 
1544
 
1475
1545
    _fmt = "Export format %(format)r not supported"
1476
1546
 
1477
1547
    def __init__(self, format):
1480
1550
 
1481
1551
 
1482
1552
class TransportError(BzrError):
1483
 
    
 
1553
 
1484
1554
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1485
1555
 
1486
1556
    def __init__(self, msg=None, orig_error=None):
1531
1601
 
1532
1602
class SmartMessageHandlerError(InternalBzrError):
1533
1603
 
1534
 
    _fmt = "The message handler raised an exception: %(exc_value)s."
 
1604
    _fmt = ("The message handler raised an exception:\n"
 
1605
            "%(traceback_text)s")
1535
1606
 
1536
1607
    def __init__(self, exc_info):
1537
 
        self.exc_type, self.exc_value, self.tb = exc_info
1538
 
        
 
1608
        import traceback
 
1609
        self.exc_type, self.exc_value, self.exc_tb = exc_info
 
1610
        self.exc_info = exc_info
 
1611
        traceback_strings = traceback.format_exception(
 
1612
                self.exc_type, self.exc_value, self.exc_tb)
 
1613
        self.traceback_text = ''.join(traceback_strings)
 
1614
 
1539
1615
 
1540
1616
# A set of semi-meaningful errors which can be thrown
1541
1617
class TransportNotPossible(TransportError):
1567
1643
            self.port = ':%s' % port
1568
1644
 
1569
1645
 
 
1646
# XXX: This is also used for unexpected end of file, which is different at the
 
1647
# TCP level from "connection reset".
1570
1648
class ConnectionReset(TransportError):
1571
1649
 
1572
1650
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1613
1691
 
1614
1692
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1615
1693
 
1616
 
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
 
1694
    def __init__(self, source, target, is_permanent=False):
1617
1695
        self.source = source
1618
1696
        self.target = target
1619
1697
        if is_permanent:
1620
1698
            self.permanently = ' permanently'
1621
1699
        else:
1622
1700
            self.permanently = ''
1623
 
        self._qualified_proto = qual_proto
1624
1701
        TransportError.__init__(self)
1625
1702
 
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
 
 
1659
1703
 
1660
1704
class TooManyRedirections(TransportError):
1661
1705
 
1673
1717
        if filename is None:
1674
1718
            filename = ""
1675
1719
        message = "Error(s) parsing config file %s:\n%s" % \
1676
 
            (filename, ('\n'.join(e.message for e in errors)))
 
1720
            (filename, ('\n'.join(e.msg for e in errors)))
1677
1721
        BzrError.__init__(self, message)
1678
1722
 
1679
1723
 
1696
1740
 
1697
1741
class WorkingTreeNotRevision(BzrError):
1698
1742
 
1699
 
    _fmt = ("The working tree for %(basedir)s has changed since" 
 
1743
    _fmt = ("The working tree for %(basedir)s has changed since"
1700
1744
            " the last commit, but weave merge requires that it be"
1701
1745
            " unchanged")
1702
1746
 
1864
1908
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1865
1909
 
1866
1910
    def __init__(self, from_path='', to_path='', extra=None):
 
1911
        from bzrlib.osutils import splitpath
1867
1912
        BzrError.__init__(self)
1868
1913
        if extra:
1869
1914
            self.extra = ': ' + str(extra)
1873
1918
        has_from = len(from_path) > 0
1874
1919
        has_to = len(to_path) > 0
1875
1920
        if has_from:
1876
 
            self.from_path = osutils.splitpath(from_path)[-1]
 
1921
            self.from_path = splitpath(from_path)[-1]
1877
1922
        else:
1878
1923
            self.from_path = ''
1879
1924
 
1880
1925
        if has_to:
1881
 
            self.to_path = osutils.splitpath(to_path)[-1]
 
1926
            self.to_path = splitpath(to_path)[-1]
1882
1927
        else:
1883
1928
            self.to_path = ''
1884
1929
 
1967
2012
 
1968
2013
class BadConversionTarget(BzrError):
1969
2014
 
1970
 
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
 
2015
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
 
2016
            "    %(problem)s"
1971
2017
 
1972
 
    def __init__(self, problem, format):
 
2018
    def __init__(self, problem, format, from_format=None):
1973
2019
        BzrError.__init__(self)
1974
2020
        self.problem = problem
1975
2021
        self.format = format
 
2022
        self.from_format = from_format or '(unspecified)'
1976
2023
 
1977
2024
 
1978
2025
class NoDiffFound(BzrError):
2015
2062
    _fmt = """This tree contains left-over files from a failed operation.
2016
2063
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2017
2064
    keep, and delete it when you are done."""
2018
 
    
 
2065
 
2019
2066
    def __init__(self, limbo_dir):
2020
2067
       BzrError.__init__(self)
2021
2068
       self.limbo_dir = limbo_dir
2054
2101
 
2055
2102
class OutOfDateTree(BzrError):
2056
2103
 
2057
 
    _fmt = "Working tree is out of date, please run 'bzr update'."
 
2104
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
2058
2105
 
2059
 
    def __init__(self, tree):
 
2106
    def __init__(self, tree, more=None):
 
2107
        if more is None:
 
2108
            more = ''
 
2109
        else:
 
2110
            more = ' ' + more
2060
2111
        BzrError.__init__(self)
2061
2112
        self.tree = tree
 
2113
        self.more = more
2062
2114
 
2063
2115
 
2064
2116
class PublicBranchOutOfDate(BzrError):
2118
2170
        self.reason = reason
2119
2171
 
2120
2172
 
 
2173
class InconsistentDeltaDelta(InconsistentDelta):
 
2174
    """Used when we get a delta that is not valid."""
 
2175
 
 
2176
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
 
2177
            "\nreason: %(reason)s")
 
2178
 
 
2179
    def __init__(self, delta, reason):
 
2180
        BzrError.__init__(self)
 
2181
        self.delta = delta
 
2182
        self.reason = reason
 
2183
 
 
2184
 
2121
2185
class UpgradeRequired(BzrError):
2122
2186
 
2123
2187
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2132
2196
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2133
2197
 
2134
2198
 
 
2199
class RichRootUpgradeRequired(UpgradeRequired):
 
2200
 
 
2201
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
 
2202
           " a format which supports rich roots.")
 
2203
 
 
2204
 
2135
2205
class LocalRequiresBoundBranch(BzrError):
2136
2206
 
2137
2207
    _fmt = "Cannot perform local-only commits on unbound branches."
2138
2208
 
2139
2209
 
2140
 
class MissingProgressBarFinish(BzrError):
2141
 
 
2142
 
    _fmt = "A nested progress bar was not 'finished' correctly."
2143
 
 
2144
 
 
2145
 
class InvalidProgressBarType(BzrError):
2146
 
 
2147
 
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
2148
 
            " is not a supported type Select one of: %(valid_types)s")
2149
 
 
2150
 
    def __init__(self, bar_type, valid_types):
2151
 
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
2152
 
 
2153
 
 
2154
2210
class UnsupportedOperation(BzrError):
2155
2211
 
2156
2212
    _fmt = ("The method %(mname)s is not supported on"
2173
2229
 
2174
2230
 
2175
2231
class BinaryFile(BzrError):
2176
 
    
 
2232
 
2177
2233
    _fmt = "File is binary but should be text."
2178
2234
 
2179
2235
 
2199
2255
 
2200
2256
 
2201
2257
class NotABundle(BzrError):
2202
 
    
 
2258
 
2203
2259
    _fmt = "Not a bzr revision-bundle: %(text)r"
2204
2260
 
2205
2261
    def __init__(self, text):
2207
2263
        self.text = text
2208
2264
 
2209
2265
 
2210
 
class BadBundle(BzrError): 
2211
 
    
 
2266
class BadBundle(BzrError):
 
2267
 
2212
2268
    _fmt = "Bad bzr revision-bundle: %(text)r"
2213
2269
 
2214
2270
    def __init__(self, text):
2216
2272
        self.text = text
2217
2273
 
2218
2274
 
2219
 
class MalformedHeader(BadBundle): 
2220
 
    
 
2275
class MalformedHeader(BadBundle):
 
2276
 
2221
2277
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2222
2278
 
2223
2279
 
2224
 
class MalformedPatches(BadBundle): 
2225
 
    
 
2280
class MalformedPatches(BadBundle):
 
2281
 
2226
2282
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2227
2283
 
2228
2284
 
2229
 
class MalformedFooter(BadBundle): 
2230
 
    
 
2285
class MalformedFooter(BadBundle):
 
2286
 
2231
2287
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2232
2288
 
2233
2289
 
2234
2290
class UnsupportedEOLMarker(BadBundle):
2235
 
    
2236
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
 
2291
 
 
2292
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
2237
2293
 
2238
2294
    def __init__(self):
2239
 
        # XXX: BadBundle's constructor assumes there's explanatory text, 
 
2295
        # XXX: BadBundle's constructor assumes there's explanatory text,
2240
2296
        # but for this there is not
2241
2297
        BzrError.__init__(self)
2242
2298
 
2243
2299
 
2244
2300
class IncompatibleBundleFormat(BzrError):
2245
 
    
 
2301
 
2246
2302
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2247
2303
 
2248
2304
    def __init__(self, bundle_format, other):
2252
2308
 
2253
2309
 
2254
2310
class BadInventoryFormat(BzrError):
2255
 
    
 
2311
 
2256
2312
    _fmt = "Root class for inventory serialization errors"
2257
2313
 
2258
2314
 
2277
2333
        self.transport = transport
2278
2334
 
2279
2335
 
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
 
 
2289
2336
class UnknownSSH(BzrError):
2290
2337
 
2291
2338
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2311
2358
        self.revision_id = revision_id
2312
2359
        self.ghost_revision_id = ghost_revision_id
2313
2360
 
2314
 
        
 
2361
 
2315
2362
class GhostRevisionUnusableHere(BzrError):
2316
2363
 
2317
2364
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2409
2456
 
2410
2457
 
2411
2458
class UnsupportedInventoryKind(BzrError):
2412
 
    
 
2459
 
2413
2460
    _fmt = """Unsupported entry kind %(kind)s"""
2414
2461
 
2415
2462
    def __init__(self, kind):
2427
2474
 
2428
2475
 
2429
2476
class SubsumeTargetNeedsUpgrade(BzrError):
2430
 
    
 
2477
 
2431
2478
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2432
2479
 
2433
2480
    def __init__(self, other_tree):
2461
2508
    def __init__(self, branch):
2462
2509
        self.branch = branch
2463
2510
 
2464
 
        
 
2511
 
2465
2512
class TagAlreadyExists(BzrError):
2466
2513
 
2467
2514
    _fmt = "Tag %(tag_name)s already exists."
2472
2519
 
2473
2520
class MalformedBugIdentifier(BzrError):
2474
2521
 
2475
 
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2522
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
2523
            'See "bzr help bugs" for more information on this feature.')
2476
2524
 
2477
2525
    def __init__(self, bug_id, reason):
2478
2526
        self.bug_id = bug_id
2499
2547
        self.branch = branch
2500
2548
 
2501
2549
 
 
2550
class InvalidLineInBugsProperty(BzrError):
 
2551
 
 
2552
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
2553
 
 
2554
    def __init__(self, line):
 
2555
        self.line = line
 
2556
 
 
2557
 
 
2558
class InvalidBugStatus(BzrError):
 
2559
 
 
2560
    _fmt = ("Invalid bug status: '%(status)s'")
 
2561
 
 
2562
    def __init__(self, status):
 
2563
        self.status = status
 
2564
 
 
2565
 
2502
2566
class UnexpectedSmartServerResponse(BzrError):
2503
2567
 
2504
2568
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2508
2572
 
2509
2573
 
2510
2574
class ErrorFromSmartServer(BzrError):
 
2575
    """An error was received from a smart server.
 
2576
 
 
2577
    :seealso: UnknownErrorFromSmartServer
 
2578
    """
2511
2579
 
2512
2580
    _fmt = "Error received from smart server: %(error_tuple)r"
2513
2581
 
2522
2590
        self.error_args = error_tuple[1:]
2523
2591
 
2524
2592
 
 
2593
class UnknownErrorFromSmartServer(BzrError):
 
2594
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
 
2595
    error.
 
2596
 
 
2597
    This is distinct from ErrorFromSmartServer so that it is possible to
 
2598
    distinguish between the following two cases:
 
2599
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2600
        and so should provoke a traceback to the user.
 
2601
      - ErrorFromSmartServer was caught but its error_tuple could not be
 
2602
        translated.  This is probably because the server sent us garbage, and
 
2603
        should not provoke a traceback.
 
2604
    """
 
2605
 
 
2606
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
 
2607
 
 
2608
    internal_error = False
 
2609
 
 
2610
    def __init__(self, error_from_smart_server):
 
2611
        """Constructor.
 
2612
 
 
2613
        :param error_from_smart_server: An ErrorFromSmartServer instance.
 
2614
        """
 
2615
        self.error_from_smart_server = error_from_smart_server
 
2616
        self.error_tuple = error_from_smart_server.error_tuple
 
2617
 
 
2618
 
2525
2619
class ContainerError(BzrError):
2526
2620
    """Base class of container errors."""
2527
2621
 
2529
2623
class UnknownContainerFormatError(ContainerError):
2530
2624
 
2531
2625
    _fmt = "Unrecognised container format: %(container_format)r"
2532
 
    
 
2626
 
2533
2627
    def __init__(self, container_format):
2534
2628
        self.container_format = container_format
2535
2629
 
2599
2693
 
2600
2694
class NoMailAddressSpecified(BzrError):
2601
2695
 
2602
 
    _fmt = "No mail-to address specified."
 
2696
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
2603
2697
 
2604
2698
 
2605
2699
class UnknownMailClient(BzrError):
2685
2779
    _fmt = "'%(display_url)s' is already standalone."
2686
2780
 
2687
2781
 
 
2782
class AlreadyWithTrees(BzrDirError):
 
2783
 
 
2784
    _fmt = ("Shared repository '%(display_url)s' already creates "
 
2785
            "working trees.")
 
2786
 
 
2787
 
 
2788
class AlreadyWithNoTrees(BzrDirError):
 
2789
 
 
2790
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
 
2791
            "working trees.")
 
2792
 
 
2793
 
2688
2794
class ReconfigurationNotSupported(BzrDirError):
2689
2795
 
2690
2796
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2697
2803
 
2698
2804
class UncommittedChanges(BzrError):
2699
2805
 
2700
 
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
 
2806
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
 
2807
            ' (See bzr status).%(more)s')
2701
2808
 
2702
 
    def __init__(self, tree):
 
2809
    def __init__(self, tree, more=None):
 
2810
        if more is None:
 
2811
            more = ''
 
2812
        else:
 
2813
            more = ' ' + more
2703
2814
        import bzrlib.urlutils as urlutils
2704
2815
        display_url = urlutils.unescape_for_display(
2705
2816
            tree.bzrdir.root_transport.base, 'ascii')
2706
 
        BzrError.__init__(self, tree=tree, display_url=display_url)
 
2817
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2707
2818
 
2708
2819
 
2709
2820
class MissingTemplateVariable(BzrError):
2744
2855
 
2745
2856
 
2746
2857
class CommandAvailableInPlugin(StandardError):
2747
 
    
 
2858
 
2748
2859
    internal_error = False
2749
2860
 
2750
2861
    def __init__(self, cmd_name, plugin_metadata, provider):
2751
 
        
 
2862
 
2752
2863
        self.plugin_metadata = plugin_metadata
2753
2864
        self.cmd_name = cmd_name
2754
2865
        self.provider = provider
2755
2866
 
2756
2867
    def __str__(self):
2757
2868
 
2758
 
        _fmt = ('"%s" is not a standard bzr command. \n' 
 
2869
        _fmt = ('"%s" is not a standard bzr command. \n'
2759
2870
                'However, the following official plugin provides this command: %s\n'
2760
2871
                'You can install it by going to: %s'
2761
 
                % (self.cmd_name, self.plugin_metadata['name'], 
 
2872
                % (self.cmd_name, self.plugin_metadata['name'],
2762
2873
                    self.plugin_metadata['url']))
2763
2874
 
2764
2875
        return _fmt
2765
2876
 
2766
2877
 
2767
2878
class NoPluginAvailable(BzrError):
2768
 
    pass    
2769
 
 
2770
 
 
2771
 
class NotATerminal(BzrError):
2772
 
 
2773
 
    _fmt = 'Unable to ask for a password without real terminal.'
 
2879
    pass
2774
2880
 
2775
2881
 
2776
2882
class UnableEncodePath(BzrError):
2779
2885
            'user encoding %(user_encoding)s')
2780
2886
 
2781
2887
    def __init__(self, path, kind):
 
2888
        from bzrlib.osutils import get_user_encoding
2782
2889
        self.path = path
2783
2890
        self.kind = kind
2784
2891
        self.user_encoding = osutils.get_user_encoding()
2819
2926
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2820
2927
 
2821
2928
    def __init__(self, host, port, orig_error):
 
2929
        # nb: in python2.4 socket.error doesn't have a useful repr
2822
2930
        BzrError.__init__(self, host=host, port=port,
2823
 
            orig_error=orig_error[1])
 
2931
            orig_error=repr(orig_error.args))
2824
2932
 
2825
2933
 
2826
2934
class UnknownRules(BzrError):
2854
2962
    """A pre_change_branch_tip hook function may raise this to cleanly and
2855
2963
    explicitly abort a change to a branch tip.
2856
2964
    """
2857
 
    
 
2965
 
2858
2966
    _fmt = u"Tip change rejected: %(msg)s"
2859
2967
 
2860
2968
    def __init__(self, msg):
2861
2969
        self.msg = msg
2862
2970
 
 
2971
 
 
2972
class ShelfCorrupt(BzrError):
 
2973
 
 
2974
    _fmt = "Shelf corrupt."
 
2975
 
 
2976
 
 
2977
class NoSuchShelfId(BzrError):
 
2978
 
 
2979
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
 
2980
 
 
2981
    def __init__(self, shelf_id):
 
2982
        BzrError.__init__(self, shelf_id=shelf_id)
 
2983
 
 
2984
 
 
2985
class InvalidShelfId(BzrError):
 
2986
 
 
2987
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
 
2988
 
 
2989
    def __init__(self, invalid_id):
 
2990
        BzrError.__init__(self, invalid_id=invalid_id)
 
2991
 
 
2992
 
 
2993
class JailBreak(BzrError):
 
2994
 
 
2995
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
 
2996
 
 
2997
    def __init__(self, url):
 
2998
        BzrError.__init__(self, url=url)
 
2999
 
 
3000
 
 
3001
class UserAbort(BzrError):
 
3002
 
 
3003
    _fmt = 'The user aborted the operation.'
 
3004
 
 
3005
 
 
3006
class MustHaveWorkingTree(BzrError):
 
3007
 
 
3008
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
 
3009
 
 
3010
    def __init__(self, format, url):
 
3011
        BzrError.__init__(self, format=format, url=url)
 
3012
 
 
3013
 
 
3014
class NoSuchView(BzrError):
 
3015
    """A view does not exist.
 
3016
    """
 
3017
 
 
3018
    _fmt = u"No such view: %(view_name)s."
 
3019
 
 
3020
    def __init__(self, view_name):
 
3021
        self.view_name = view_name
 
3022
 
 
3023
 
 
3024
class ViewsNotSupported(BzrError):
 
3025
    """Views are not supported by a tree format.
 
3026
    """
 
3027
 
 
3028
    _fmt = ("Views are not supported by %(tree)s;"
 
3029
            " use 'bzr upgrade' to change your tree to a later format.")
 
3030
 
 
3031
    def __init__(self, tree):
 
3032
        self.tree = tree
 
3033
 
 
3034
 
 
3035
class FileOutsideView(BzrError):
 
3036
 
 
3037
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
3038
            '%(view_str)s')
 
3039
 
 
3040
    def __init__(self, file_name, view_files):
 
3041
        self.file_name = file_name
 
3042
        self.view_str = ", ".join(view_files)
 
3043
 
 
3044
 
 
3045
class UnresumableWriteGroup(BzrError):
 
3046
 
 
3047
    _fmt = ("Repository %(repository)s cannot resume write group "
 
3048
            "%(write_groups)r: %(reason)s")
 
3049
 
 
3050
    internal_error = True
 
3051
 
 
3052
    def __init__(self, repository, write_groups, reason):
 
3053
        self.repository = repository
 
3054
        self.write_groups = write_groups
 
3055
        self.reason = reason
 
3056
 
 
3057
 
 
3058
class UnsuspendableWriteGroup(BzrError):
 
3059
 
 
3060
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
 
3061
 
 
3062
    internal_error = True
 
3063
 
 
3064
    def __init__(self, repository):
 
3065
        self.repository = repository
 
3066
 
 
3067
 
 
3068
class LossyPushToSameVCS(BzrError):
 
3069
 
 
3070
    _fmt = ("Lossy push not possible between %(source_branch)r and "
 
3071
            "%(target_branch)r that are in the same VCS.")
 
3072
 
 
3073
    internal_error = True
 
3074
 
 
3075
    def __init__(self, source_branch, target_branch):
 
3076
        self.source_branch = source_branch
 
3077
        self.target_branch = target_branch