~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-10-02 17:28:44 UTC
  • mfrom: (3744.2.2 merge_reprocess)
  • Revision ID: pqm@pqm.ubuntu.com-20081002172844-d6df1l8dzpsqzyup
(jam) For 'bzr merge' enable '--reprocess' by default whenever
        '--show-base' is not set.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
 
54
55
    Base class for errors raised by bzrlib.
55
56
 
56
57
    :cvar internal_error: if True this was probably caused by a bzr bug and
57
 
        should be displayed with a traceback; if False (or absent) this was
58
 
        probably a user or environment error and they don't need the gory
59
 
        details.  (That can be overridden by -Derror on the command line.)
 
58
    should be displayed with a traceback; if False (or absent) this was
 
59
    probably a user or environment error and they don't need the gory details.
 
60
    (That can be overridden by -Derror on the command line.)
60
61
 
61
62
    :cvar _fmt: Format string to display the error; this is expanded
62
 
        by the instance's dict.
 
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,
133
134
            s = str(s)
134
135
        return s
135
136
 
136
 
    def __repr__(self):
137
 
        return '%s(%s)' % (self.__class__.__name__, str(self))
138
 
 
139
137
    def _get_format_string(self):
140
138
        """Return format string for this exception or None"""
141
139
        fmt = getattr(self, '_fmt', None)
154
152
               )
155
153
 
156
154
    def __eq__(self, other):
157
 
        if self.__class__ is not other.__class__:
 
155
        if self.__class__ != other.__class__:
158
156
            return NotImplemented
159
157
        return self.__dict__ == other.__dict__
160
158
 
265
263
 
266
264
 
267
265
class InvalidEntryName(InternalBzrError):
268
 
 
 
266
    
269
267
    _fmt = "Invalid entry name: %(name)s"
270
268
 
271
269
    def __init__(self, name):
274
272
 
275
273
 
276
274
class InvalidRevisionNumber(BzrError):
277
 
 
 
275
    
278
276
    _fmt = "Invalid revision number %(revno)s"
279
277
 
280
278
    def __init__(self, revno):
304
302
class RootMissing(InternalBzrError):
305
303
 
306
304
    _fmt = ("The root entry of a tree must be the first entry supplied to "
307
 
        "the commit builder.")
 
305
        "record_entry_contents.")
308
306
 
309
307
 
310
308
class NoPublicBranch(BzrError):
329
327
class NoSuchId(BzrError):
330
328
 
331
329
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
332
 
 
 
330
    
333
331
    def __init__(self, tree, file_id):
334
332
        BzrError.__init__(self)
335
333
        self.file_id = file_id
362
360
class NoWorkingTree(BzrError):
363
361
 
364
362
    _fmt = 'No WorkingTree exists for "%(base)s".'
365
 
 
 
363
    
366
364
    def __init__(self, base):
367
365
        BzrError.__init__(self)
368
366
        self.base = base
477
475
    def __init__(self, name, value):
478
476
        BzrError.__init__(self, name=name, value=value)
479
477
 
480
 
 
 
478
    
481
479
class StrictCommitFailed(BzrError):
482
480
 
483
481
    _fmt = "Commit refused because there are unknown files in the tree"
486
484
# XXX: Should be unified with TransportError; they seem to represent the
487
485
# same thing
488
486
# 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
 
487
# - this is finer than a TransportError - and more useful as such. It 
490
488
# differentiates between 'transport has failed' and 'operation on a transport
491
489
# has failed.'
492
490
class PathError(BzrError):
493
 
 
 
491
    
494
492
    _fmt = "Generic path error: %(path)r%(extra)s)"
495
493
 
496
494
    def __init__(self, path, extra=None):
550
548
 
551
549
 
552
550
class ReadingCompleted(InternalBzrError):
553
 
 
 
551
    
554
552
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
555
553
            "called upon it - the request has been completed and no more "
556
554
            "data may be read.")
621
619
 
622
620
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
623
621
 
624
 
    def __init__(self, url, extra=""):
 
622
    def __init__(self, url, extra):
625
623
        PathError.__init__(self, url, extra=extra)
626
624
 
627
625
 
636
634
        self.url = url
637
635
 
638
636
 
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
 
 
649
637
class UnstackableRepositoryFormat(BzrError):
650
638
 
651
639
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
658
646
 
659
647
 
660
648
class ReadError(PathError):
661
 
 
 
649
    
662
650
    _fmt = """Error reading from %(path)r."""
663
651
 
664
652
 
680
668
 
681
669
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
682
670
 
683
 
    internal_error = False
 
671
    internal_error = True
684
672
 
685
673
    def __init__(self, path, base, extra=None):
686
674
        BzrError.__init__(self)
699
687
 
700
688
# TODO: This is given a URL; we try to unescape it but doing that from inside
701
689
# the exception object is a bit undesirable.
702
 
# TODO: Probably this behavior of should be a common superclass
 
690
# TODO: Probably this behavior of should be a common superclass 
703
691
class NotBranchError(PathError):
704
692
 
705
 
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
 
693
    _fmt = 'Not a branch: "%(path)s".'
706
694
 
707
 
    def __init__(self, path, detail=None, bzrdir=None):
 
695
    def __init__(self, path):
708
696
       import bzrlib.urlutils as urlutils
709
 
       path = urlutils.unescape_for_display(path, 'ascii')
710
 
       if detail is not None:
711
 
           detail = ': ' + detail
712
 
       self.detail = detail
713
 
       self.bzrdir = bzrdir
714
 
       PathError.__init__(self, path=path)
715
 
 
716
 
    def __repr__(self):
717
 
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
718
 
 
719
 
    def _format(self):
720
 
        # XXX: Ideally self.detail would be a property, but Exceptions in
721
 
        # Python 2.4 have to be old-style classes so properties don't work.
722
 
        # Instead we override _format.
723
 
        if self.detail is None:
724
 
            if self.bzrdir is not None:
725
 
                try:
726
 
                    self.bzrdir.open_repository()
727
 
                except NoRepositoryPresent:
728
 
                    self.detail = ''
729
 
                except Exception:
730
 
                    # Just ignore unexpected errors.  Raising arbitrary errors
731
 
                    # during str(err) can provoke strange bugs.  Concretely
732
 
                    # Launchpad's codehosting managed to raise NotBranchError
733
 
                    # here, and then get stuck in an infinite loop/recursion
734
 
                    # trying to str() that error.  All this error really cares
735
 
                    # about that there's no working repository there, and if
736
 
                    # open_repository() fails, there probably isn't.
737
 
                    self.detail = ''
738
 
                else:
739
 
                    self.detail = ': location is a repository'
740
 
            else:
741
 
                self.detail = ''
742
 
        return PathError._format(self)
 
697
       self.path = urlutils.unescape_for_display(path, 'ascii')
743
698
 
744
699
 
745
700
class NoSubmitBranch(PathError):
794
749
 
795
750
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
796
751
 
797
 
    # use PathNotChild instead
798
 
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 3, 0)))
799
752
    def __init__(self, branch, path):
800
753
        BzrError.__init__(self)
801
754
        self.branch = branch
809
762
 
810
763
 
811
764
class UnknownFormatError(BzrError):
812
 
 
 
765
    
813
766
    _fmt = "Unknown %(kind)s format: %(format)r"
814
767
 
815
768
    def __init__(self, format, kind='branch'):
818
771
 
819
772
 
820
773
class IncompatibleFormat(BzrError):
821
 
 
 
774
    
822
775
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
823
776
 
824
777
    def __init__(self, format, bzrdir_format):
828
781
 
829
782
 
830
783
class IncompatibleRepositories(BzrError):
831
 
    """Report an error that two repositories are not compatible.
832
 
 
833
 
    Note that the source and target repositories are permitted to be strings:
834
 
    this exception is thrown from the smart server and may refer to a
835
 
    repository the client hasn't opened.
836
 
    """
837
784
 
838
785
    _fmt = "%(target)s\n" \
839
786
            "is not compatible with\n" \
847
794
 
848
795
 
849
796
class IncompatibleRevision(BzrError):
850
 
 
 
797
    
851
798
    _fmt = "Revision is not compatible with %(repo_format)s"
852
799
 
853
800
    def __init__(self, repo_format):
864
811
        """Construct a new AlreadyVersionedError.
865
812
 
866
813
        :param path: This is the path which is versioned,
867
 
            which should be in a user friendly form.
 
814
        which should be in a user friendly form.
868
815
        :param context_info: If given, this is information about the context,
869
 
            which could explain why this is expected to not be versioned.
 
816
        which could explain why this is expected to not be versioned.
870
817
        """
871
818
        BzrError.__init__(self)
872
819
        self.path = path
885
832
        """Construct a new NotVersionedError.
886
833
 
887
834
        :param path: This is the path which is not versioned,
888
 
            which should be in a user friendly form.
 
835
        which should be in a user friendly form.
889
836
        :param context_info: If given, this is information about the context,
890
 
            which could explain why this is expected to be versioned.
 
837
        which could explain why this is expected to be versioned.
891
838
        """
892
839
        BzrError.__init__(self)
893
840
        self.path = path
961
908
    # original exception is available as e.original_error
962
909
    #
963
910
    # New code should prefer to raise specific subclasses
964
 
    def __init__(self, msg):
965
 
        self.msg = msg
 
911
    def __init__(self, message):
 
912
        # Python 2.5 uses a slot for StandardError.message,
 
913
        # so use a different variable name.  We now work around this in
 
914
        # BzrError.__str__, but this member name is kept for compatability.
 
915
        self.msg = message
966
916
 
967
917
 
968
918
class LockActive(LockError):
1051
1001
 
1052
1002
class LockContention(LockError):
1053
1003
 
1054
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
 
1004
    _fmt = 'Could not acquire lock "%(lock)s"'
 
1005
    # TODO: show full url for lock, combining the transport and relative
 
1006
    # bits?
1055
1007
 
1056
1008
    internal_error = False
1057
1009
 
1058
 
    def __init__(self, lock, msg=''):
 
1010
    def __init__(self, lock):
1059
1011
        self.lock = lock
1060
 
        self.msg = msg
1061
1012
 
1062
1013
 
1063
1014
class LockBroken(LockError):
1084
1035
        self.target = target
1085
1036
 
1086
1037
 
1087
 
class LockCorrupt(LockError):
1088
 
 
1089
 
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
1090
 
            "Use 'bzr break-lock' to clear it")
1091
 
 
1092
 
    internal_error = False
1093
 
 
1094
 
    def __init__(self, corruption_info, file_data=None):
1095
 
        self.corruption_info = corruption_info
1096
 
        self.file_data = file_data
1097
 
 
1098
 
 
1099
1038
class LockNotHeld(LockError):
1100
1039
 
1101
1040
    _fmt = "Lock not held: %(lock)s"
1140
1079
        BzrError.__init__(self, files=files, files_str=files_str)
1141
1080
 
1142
1081
 
1143
 
class ExcludesUnsupported(BzrError):
1144
 
 
1145
 
    _fmt = ('Excluding paths during commit is not supported by '
1146
 
            'repository at %(repository)r.')
1147
 
 
1148
 
    def __init__(self, repository):
1149
 
        BzrError.__init__(self, repository=repository)
1150
 
 
1151
 
 
1152
1082
class BadCommitMessageEncoding(BzrError):
1153
1083
 
1154
1084
    _fmt = 'The specified commit message contains characters unsupported by '\
1198
1128
 
1199
1129
class NoSuchRevisionInTree(NoSuchRevision):
1200
1130
    """When using Tree.revision_tree, and the revision is not accessible."""
1201
 
 
 
1131
    
1202
1132
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1203
1133
 
1204
1134
    def __init__(self, tree, revision_id):
1209
1139
 
1210
1140
class InvalidRevisionSpec(BzrError):
1211
1141
 
1212
 
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
1213
 
            " %(branch_url)s%(extra)s")
 
1142
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
 
1143
            " %(branch)s%(extra)s")
1214
1144
 
1215
1145
    def __init__(self, spec, branch, extra=None):
1216
1146
        BzrError.__init__(self, branch=branch, spec=spec)
1217
 
        self.branch_url = getattr(branch, 'user_url', str(branch))
1218
1147
        if extra:
1219
1148
            self.extra = '\n' + str(extra)
1220
1149
        else:
1241
1170
class DivergedBranches(BzrError):
1242
1171
 
1243
1172
    _fmt = ("These branches have diverged."
1244
 
            " Use the missing command to see how.\n"
1245
 
            "Use the merge command to reconcile them.")
 
1173
            " Use the merge command to reconcile them.")
1246
1174
 
1247
1175
    def __init__(self, branch1, branch2):
1248
1176
        self.branch1 = branch1
1270
1198
 
1271
1199
 
1272
1200
class NoCommonAncestor(BzrError):
1273
 
 
 
1201
    
1274
1202
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1275
1203
 
1276
1204
    def __init__(self, revision_a, revision_b):
1296
1224
            not_ancestor_id=not_ancestor_id)
1297
1225
 
1298
1226
 
 
1227
class InstallFailed(BzrError):
 
1228
 
 
1229
    def __init__(self, revisions):
 
1230
        revision_str = ", ".join(str(r) for r in revisions)
 
1231
        msg = "Could not install revisions:\n%s" % revision_str
 
1232
        BzrError.__init__(self, msg)
 
1233
        self.revisions = revisions
 
1234
 
 
1235
 
1299
1236
class AmbiguousBase(BzrError):
1300
1237
 
1301
1238
    def __init__(self, bases):
1302
 
        symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
1303
 
            "as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
 
1239
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
1240
                DeprecationWarning)
1304
1241
        msg = ("The correct base is unclear, because %s are all equally close"
1305
1242
                % ", ".join(bases))
1306
1243
        BzrError.__init__(self, msg)
1328
1265
class BoundBranchOutOfDate(BzrError):
1329
1266
 
1330
1267
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1331
 
            " %(master)s.%(extra_help)s")
 
1268
            " %(master)s.")
1332
1269
 
1333
1270
    def __init__(self, branch, master):
1334
1271
        BzrError.__init__(self)
1335
1272
        self.branch = branch
1336
1273
        self.master = master
1337
 
        self.extra_help = ''
1338
 
 
1339
 
 
 
1274
 
 
1275
        
1340
1276
class CommitToDoubleBoundBranch(BzrError):
1341
1277
 
1342
1278
    _fmt = ("Cannot commit to branch %(branch)s."
1411
1347
 
1412
1348
class WeaveParentMismatch(WeaveError):
1413
1349
 
1414
 
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
1415
 
 
 
1350
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
1351
    
1416
1352
 
1417
1353
class WeaveInvalidChecksum(WeaveError):
1418
1354
 
1419
 
    _fmt = "Text did not match its checksum: %(msg)s"
 
1355
    _fmt = "Text did not match it's checksum: %(message)s"
1420
1356
 
1421
1357
 
1422
1358
class WeaveTextDiffers(WeaveError):
1444
1380
 
1445
1381
 
1446
1382
class VersionedFileError(BzrError):
1447
 
 
 
1383
    
1448
1384
    _fmt = "Versioned file error"
1449
1385
 
1450
1386
 
1451
1387
class RevisionNotPresent(VersionedFileError):
1452
 
 
 
1388
    
1453
1389
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1454
1390
 
1455
1391
    def __init__(self, revision_id, file_id):
1459
1395
 
1460
1396
 
1461
1397
class RevisionAlreadyPresent(VersionedFileError):
1462
 
 
 
1398
    
1463
1399
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1464
1400
 
1465
1401
    def __init__(self, revision_id, file_id):
1470
1406
 
1471
1407
class VersionedFileInvalidChecksum(VersionedFileError):
1472
1408
 
1473
 
    _fmt = "Text did not match its checksum: %(msg)s"
 
1409
    _fmt = "Text did not match its checksum: %(message)s"
1474
1410
 
1475
1411
 
1476
1412
class KnitError(InternalBzrError):
1477
 
 
 
1413
    
1478
1414
    _fmt = "Knit error"
1479
1415
 
1480
1416
 
1488
1424
        self.how = how
1489
1425
 
1490
1426
 
1491
 
class SHA1KnitCorrupt(KnitCorrupt):
1492
 
 
1493
 
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
1494
 
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
1495
 
        "sha %(actual)s")
1496
 
 
1497
 
    def __init__(self, filename, actual, expected, key, content):
1498
 
        KnitError.__init__(self)
1499
 
        self.filename = filename
1500
 
        self.actual = actual
1501
 
        self.expected = expected
1502
 
        self.key = key
1503
 
        self.content = content
1504
 
 
1505
 
 
1506
1427
class KnitDataStreamIncompatible(KnitError):
1507
1428
    # Not raised anymore, as we can convert data streams.  In future we may
1508
1429
    # need it again for more exotic cases, so we're keeping it around for now.
1512
1433
    def __init__(self, stream_format, target_format):
1513
1434
        self.stream_format = stream_format
1514
1435
        self.target_format = target_format
1515
 
 
 
1436
        
1516
1437
 
1517
1438
class KnitDataStreamUnknown(KnitError):
1518
1439
    # Indicates a data stream we don't know how to handle.
1521
1442
 
1522
1443
    def __init__(self, stream_format):
1523
1444
        self.stream_format = stream_format
1524
 
 
 
1445
        
1525
1446
 
1526
1447
class KnitHeaderError(KnitError):
1527
1448
 
1537
1458
 
1538
1459
    Currently only 'fulltext' and 'line-delta' are supported.
1539
1460
    """
1540
 
 
 
1461
    
1541
1462
    _fmt = ("Knit index %(filename)s does not have a known method"
1542
1463
            " in options: %(options)r")
1543
1464
 
1547
1468
        self.options = options
1548
1469
 
1549
1470
 
1550
 
class RetryWithNewPacks(BzrError):
1551
 
    """Raised when we realize that the packs on disk have changed.
1552
 
 
1553
 
    This is meant as more of a signaling exception, to trap between where a
1554
 
    local error occurred and the code that can actually handle the error and
1555
 
    code that can retry appropriately.
1556
 
    """
1557
 
 
1558
 
    internal_error = True
1559
 
 
1560
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1561
 
            " %(orig_error)s")
1562
 
 
1563
 
    def __init__(self, context, reload_occurred, exc_info):
1564
 
        """create a new RetryWithNewPacks error.
1565
 
 
1566
 
        :param reload_occurred: Set to True if we know that the packs have
1567
 
            already been reloaded, and we are failing because of an in-memory
1568
 
            cache miss. If set to True then we will ignore if a reload says
1569
 
            nothing has changed, because we assume it has already reloaded. If
1570
 
            False, then a reload with nothing changed will force an error.
1571
 
        :param exc_info: The original exception traceback, so if there is a
1572
 
            problem we can raise the original error (value from sys.exc_info())
1573
 
        """
1574
 
        BzrError.__init__(self)
1575
 
        self.reload_occurred = reload_occurred
1576
 
        self.exc_info = exc_info
1577
 
        self.orig_error = exc_info[1]
1578
 
        # TODO: The global error handler should probably treat this by
1579
 
        #       raising/printing the original exception with a bit about
1580
 
        #       RetryWithNewPacks also not being caught
1581
 
 
1582
 
 
1583
 
class RetryAutopack(RetryWithNewPacks):
1584
 
    """Raised when we are autopacking and we find a missing file.
1585
 
 
1586
 
    Meant as a signaling exception, to tell the autopack code it should try
1587
 
    again.
1588
 
    """
1589
 
 
1590
 
    internal_error = True
1591
 
 
1592
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1593
 
            " context: %(context)s %(orig_error)s")
1594
 
 
1595
 
 
1596
1471
class NoSuchExportFormat(BzrError):
1597
 
 
 
1472
    
1598
1473
    _fmt = "Export format %(format)r not supported"
1599
1474
 
1600
1475
    def __init__(self, format):
1603
1478
 
1604
1479
 
1605
1480
class TransportError(BzrError):
1606
 
 
 
1481
    
1607
1482
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1608
1483
 
1609
1484
    def __init__(self, msg=None, orig_error=None):
1654
1529
 
1655
1530
class SmartMessageHandlerError(InternalBzrError):
1656
1531
 
1657
 
    _fmt = ("The message handler raised an exception:\n"
1658
 
            "%(traceback_text)s")
 
1532
    _fmt = "The message handler raised an exception: %(exc_value)s."
1659
1533
 
1660
1534
    def __init__(self, exc_info):
1661
 
        import traceback
1662
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1663
 
        self.exc_info = exc_info
1664
 
        traceback_strings = traceback.format_exception(
1665
 
                self.exc_type, self.exc_value, self.exc_tb)
1666
 
        self.traceback_text = ''.join(traceback_strings)
1667
 
 
 
1535
        self.exc_type, self.exc_value, self.tb = exc_info
 
1536
        
1668
1537
 
1669
1538
# A set of semi-meaningful errors which can be thrown
1670
1539
class TransportNotPossible(TransportError):
1696
1565
            self.port = ':%s' % port
1697
1566
 
1698
1567
 
1699
 
# XXX: This is also used for unexpected end of file, which is different at the
1700
 
# TCP level from "connection reset".
1701
1568
class ConnectionReset(TransportError):
1702
1569
 
1703
1570
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1715
1582
 
1716
1583
class InvalidHttpResponse(TransportError):
1717
1584
 
1718
 
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
 
1585
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1719
1586
 
1720
1587
    def __init__(self, path, msg, orig_error=None):
1721
1588
        self.path = path
1722
 
        if orig_error is None:
1723
 
            orig_error = ''
1724
 
        else:
1725
 
            # This is reached for obscure and unusual errors so we want to
1726
 
            # preserve as much info as possible to ease debug.
1727
 
            orig_error = ': %r' % (orig_error,)
1728
1589
        TransportError.__init__(self, msg, orig_error=orig_error)
1729
1590
 
1730
1591
 
1737
1598
        InvalidHttpResponse.__init__(self, path, msg)
1738
1599
 
1739
1600
 
1740
 
class HttpBoundaryMissing(InvalidHttpResponse):
1741
 
    """A multipart response ends with no boundary marker.
1742
 
 
1743
 
    This is a special case caused by buggy proxies, described in
1744
 
    <https://bugs.launchpad.net/bzr/+bug/198646>.
1745
 
    """
1746
 
 
1747
 
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
1748
 
 
1749
 
    def __init__(self, path, msg):
1750
 
        InvalidHttpResponse.__init__(self, path, msg)
1751
 
 
1752
 
 
1753
1601
class InvalidHttpContentType(InvalidHttpResponse):
1754
1602
 
1755
1603
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1763
1611
 
1764
1612
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1765
1613
 
1766
 
    def __init__(self, source, target, is_permanent=False):
 
1614
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
1767
1615
        self.source = source
1768
1616
        self.target = target
1769
1617
        if is_permanent:
1770
1618
            self.permanently = ' permanently'
1771
1619
        else:
1772
1620
            self.permanently = ''
 
1621
        self._qualified_proto = qual_proto
1773
1622
        TransportError.__init__(self)
1774
1623
 
 
1624
    def _requalify_url(self, url):
 
1625
        """Restore the qualified proto in front of the url"""
 
1626
        # When this exception is raised, source and target are in
 
1627
        # user readable format. But some transports may use a
 
1628
        # different proto (http+urllib:// will present http:// to
 
1629
        # the user. If a qualified proto is specified, the code
 
1630
        # trapping the exception can get the qualified urls to
 
1631
        # properly handle the redirection themself (creating a
 
1632
        # new transport object from the target url for example).
 
1633
        # But checking that the scheme of the original and
 
1634
        # redirected urls are the same can be tricky. (see the
 
1635
        # FIXME in BzrDir.open_from_transport for the unique use
 
1636
        # case so far).
 
1637
        if self._qualified_proto is None:
 
1638
            return url
 
1639
 
 
1640
        # The TODO related to NotBranchError mention that doing
 
1641
        # that kind of manipulation on the urls may not be the
 
1642
        # exception object job. On the other hand, this object is
 
1643
        # the interface between the code and the user so
 
1644
        # presenting the urls in different ways is indeed its
 
1645
        # job...
 
1646
        import urlparse
 
1647
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1648
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1649
                                   query, fragment))
 
1650
 
 
1651
    def get_source_url(self):
 
1652
        return self._requalify_url(self.source)
 
1653
 
 
1654
    def get_target_url(self):
 
1655
        return self._requalify_url(self.target)
 
1656
 
1775
1657
 
1776
1658
class TooManyRedirections(TransportError):
1777
1659
 
1783
1665
    _fmt = "Working tree has conflicts."
1784
1666
 
1785
1667
 
1786
 
class ConfigContentError(BzrError):
1787
 
 
1788
 
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
1789
 
 
1790
 
    def __init__(self, filename):
1791
 
        BzrError.__init__(self)
1792
 
        self.filename = filename
1793
 
 
1794
 
 
1795
1668
class ParseConfigError(BzrError):
1796
1669
 
1797
 
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
1798
 
 
1799
1670
    def __init__(self, errors, filename):
1800
 
        BzrError.__init__(self)
1801
 
        self.filename = filename
1802
 
        self.errors = '\n'.join(e.msg for e in errors)
1803
 
 
1804
 
 
1805
 
class ConfigOptionValueError(BzrError):
1806
 
 
1807
 
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
1808
 
 
1809
 
    def __init__(self, name, value):
1810
 
        BzrError.__init__(self, name=name, value=value)
 
1671
        if filename is None:
 
1672
            filename = ""
 
1673
        message = "Error(s) parsing config file %s:\n%s" % \
 
1674
            (filename, ('\n'.join(e.msg for e in errors)))
 
1675
        BzrError.__init__(self, message)
1811
1676
 
1812
1677
 
1813
1678
class NoEmailInUsername(BzrError):
1821
1686
 
1822
1687
class SigningFailed(BzrError):
1823
1688
 
1824
 
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
 
1689
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
1825
1690
 
1826
1691
    def __init__(self, command_line):
1827
1692
        BzrError.__init__(self, command_line=command_line)
1828
1693
 
1829
1694
 
1830
 
class SignatureVerificationFailed(BzrError):
1831
 
 
1832
 
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
1833
 
 
1834
 
    def __init__(self, error):
1835
 
        BzrError.__init__(self, error=error)
1836
 
 
1837
 
 
1838
 
class DependencyNotPresent(BzrError):
1839
 
 
1840
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1841
 
 
1842
 
    def __init__(self, library, error):
1843
 
        BzrError.__init__(self, library=library, error=error)
1844
 
 
1845
 
 
1846
 
class GpgmeNotInstalled(DependencyNotPresent):
1847
 
 
1848
 
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
1849
 
 
1850
 
    def __init__(self, error):
1851
 
        DependencyNotPresent.__init__(self, 'gpgme', error)
1852
 
 
1853
 
 
1854
1695
class WorkingTreeNotRevision(BzrError):
1855
1696
 
1856
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1697
    _fmt = ("The working tree for %(basedir)s has changed since" 
1857
1698
            " the last commit, but weave merge requires that it be"
1858
1699
            " unchanged")
1859
1700
 
2016
1857
    _fmt = "Moving the root directory is not supported at this time"
2017
1858
 
2018
1859
 
2019
 
class TransformRenameFailed(BzrError):
2020
 
 
2021
 
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
2022
 
 
2023
 
    def __init__(self, from_path, to_path, why, errno):
2024
 
        self.from_path = from_path
2025
 
        self.to_path = to_path
2026
 
        self.why = why
2027
 
        self.errno = errno
2028
 
 
2029
 
 
2030
1860
class BzrMoveFailedError(BzrError):
2031
1861
 
2032
 
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
2033
 
        "%(_has_extra)s%(extra)s")
 
1862
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
2034
1863
 
2035
1864
    def __init__(self, from_path='', to_path='', extra=None):
2036
1865
        from bzrlib.osutils import splitpath
2037
1866
        BzrError.__init__(self)
2038
1867
        if extra:
2039
 
            self.extra, self._has_extra = extra, ': '
 
1868
            self.extra = ': ' + str(extra)
2040
1869
        else:
2041
 
            self.extra = self._has_extra = ''
 
1870
            self.extra = ''
2042
1871
 
2043
1872
        has_from = len(from_path) > 0
2044
1873
        has_to = len(to_path) > 0
2065
1894
 
2066
1895
class BzrRenameFailedError(BzrMoveFailedError):
2067
1896
 
2068
 
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
2069
 
        "%(_has_extra)s%(extra)s")
 
1897
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
2070
1898
 
2071
1899
    def __init__(self, from_path, to_path, extra=None):
2072
1900
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
2073
1901
 
2074
 
 
2075
1902
class BzrRemoveChangedFilesError(BzrError):
2076
1903
    """Used when user is trying to remove changed files."""
2077
1904
 
2080
1907
        "Use --keep to not delete them, or --force to delete them regardless.")
2081
1908
 
2082
1909
    def __init__(self, tree_delta):
2083
 
        symbol_versioning.warn(symbol_versioning.deprecated_in((2, 3, 0)) %
2084
 
            "BzrRemoveChangedFilesError", DeprecationWarning, stacklevel=2)
2085
1910
        BzrError.__init__(self)
2086
1911
        self.changes_as_text = tree_delta.get_changes_as_text()
2087
1912
        #self.paths_as_string = '\n'.join(changed_files)
2095
1920
 
2096
1921
class BzrBadParameterMissing(BzrBadParameter):
2097
1922
 
2098
 
    _fmt = "Parameter %(param)s is required but not present."
 
1923
    _fmt = "Parameter $(param)s is required but not present."
2099
1924
 
2100
1925
 
2101
1926
class BzrBadParameterUnicode(BzrBadParameter):
2109
1934
    _fmt = "Parameter %(param)s contains a newline."
2110
1935
 
2111
1936
 
 
1937
class DependencyNotPresent(BzrError):
 
1938
 
 
1939
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1940
 
 
1941
    def __init__(self, library, error):
 
1942
        BzrError.__init__(self, library=library, error=error)
 
1943
 
 
1944
 
2112
1945
class ParamikoNotPresent(DependencyNotPresent):
2113
1946
 
2114
1947
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
2133
1966
 
2134
1967
class BadConversionTarget(BzrError):
2135
1968
 
2136
 
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
2137
 
            "    %(problem)s"
 
1969
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
2138
1970
 
2139
 
    def __init__(self, problem, format, from_format=None):
 
1971
    def __init__(self, problem, format):
2140
1972
        BzrError.__init__(self)
2141
1973
        self.problem = problem
2142
1974
        self.format = format
2143
 
        self.from_format = from_format or '(unspecified)'
2144
1975
 
2145
1976
 
2146
1977
class NoDiffFound(BzrError):
2183
2014
    _fmt = """This tree contains left-over files from a failed operation.
2184
2015
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2185
2016
    keep, and delete it when you are done."""
2186
 
 
 
2017
    
2187
2018
    def __init__(self, limbo_dir):
2188
2019
       BzrError.__init__(self)
2189
2020
       self.limbo_dir = limbo_dir
2222
2053
 
2223
2054
class OutOfDateTree(BzrError):
2224
2055
 
2225
 
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
 
2056
    _fmt = "Working tree is out of date, please run 'bzr update'."
2226
2057
 
2227
 
    def __init__(self, tree, more=None):
2228
 
        if more is None:
2229
 
            more = ''
2230
 
        else:
2231
 
            more = ' ' + more
 
2058
    def __init__(self, tree):
2232
2059
        BzrError.__init__(self)
2233
2060
        self.tree = tree
2234
 
        self.more = more
2235
2061
 
2236
2062
 
2237
2063
class PublicBranchOutOfDate(BzrError):
2275
2101
 
2276
2102
    def __init__(self, repo):
2277
2103
        BzrError.__init__(self)
2278
 
        self.repo_path = repo.user_url
 
2104
        self.repo_path = repo.bzrdir.root_transport.base
2279
2105
 
2280
2106
 
2281
2107
class InconsistentDelta(BzrError):
2291
2117
        self.reason = reason
2292
2118
 
2293
2119
 
2294
 
class InconsistentDeltaDelta(InconsistentDelta):
2295
 
    """Used when we get a delta that is not valid."""
2296
 
 
2297
 
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
2298
 
            "\nreason: %(reason)s")
2299
 
 
2300
 
    def __init__(self, delta, reason):
2301
 
        BzrError.__init__(self)
2302
 
        self.delta = delta
2303
 
        self.reason = reason
2304
 
 
2305
 
 
2306
2120
class UpgradeRequired(BzrError):
2307
2121
 
2308
2122
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2317
2131
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2318
2132
 
2319
2133
 
2320
 
class RichRootUpgradeRequired(UpgradeRequired):
2321
 
 
2322
 
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
2323
 
           " a format which supports rich roots.")
2324
 
 
2325
 
 
2326
2134
class LocalRequiresBoundBranch(BzrError):
2327
2135
 
2328
2136
    _fmt = "Cannot perform local-only commits on unbound branches."
2329
2137
 
2330
2138
 
 
2139
class MissingProgressBarFinish(BzrError):
 
2140
 
 
2141
    _fmt = "A nested progress bar was not 'finished' correctly."
 
2142
 
 
2143
 
 
2144
class InvalidProgressBarType(BzrError):
 
2145
 
 
2146
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
 
2147
            " is not a supported type Select one of: %(valid_types)s")
 
2148
 
 
2149
    def __init__(self, bar_type, valid_types):
 
2150
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
2151
 
 
2152
 
2331
2153
class UnsupportedOperation(BzrError):
2332
2154
 
2333
2155
    _fmt = ("The method %(mname)s is not supported on"
2350
2172
 
2351
2173
 
2352
2174
class BinaryFile(BzrError):
2353
 
 
 
2175
    
2354
2176
    _fmt = "File is binary but should be text."
2355
2177
 
2356
2178
 
2376
2198
 
2377
2199
 
2378
2200
class NotABundle(BzrError):
2379
 
 
 
2201
    
2380
2202
    _fmt = "Not a bzr revision-bundle: %(text)r"
2381
2203
 
2382
2204
    def __init__(self, text):
2384
2206
        self.text = text
2385
2207
 
2386
2208
 
2387
 
class BadBundle(BzrError):
2388
 
 
 
2209
class BadBundle(BzrError): 
 
2210
    
2389
2211
    _fmt = "Bad bzr revision-bundle: %(text)r"
2390
2212
 
2391
2213
    def __init__(self, text):
2393
2215
        self.text = text
2394
2216
 
2395
2217
 
2396
 
class MalformedHeader(BadBundle):
2397
 
 
 
2218
class MalformedHeader(BadBundle): 
 
2219
    
2398
2220
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2399
2221
 
2400
2222
 
2401
 
class MalformedPatches(BadBundle):
2402
 
 
 
2223
class MalformedPatches(BadBundle): 
 
2224
    
2403
2225
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2404
2226
 
2405
2227
 
2406
 
class MalformedFooter(BadBundle):
2407
 
 
 
2228
class MalformedFooter(BadBundle): 
 
2229
    
2408
2230
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2409
2231
 
2410
2232
 
2411
2233
class UnsupportedEOLMarker(BadBundle):
2412
 
 
2413
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
2234
    
 
2235
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
2414
2236
 
2415
2237
    def __init__(self):
2416
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
2238
        # XXX: BadBundle's constructor assumes there's explanatory text, 
2417
2239
        # but for this there is not
2418
2240
        BzrError.__init__(self)
2419
2241
 
2420
2242
 
2421
2243
class IncompatibleBundleFormat(BzrError):
2422
 
 
 
2244
    
2423
2245
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2424
2246
 
2425
2247
    def __init__(self, bundle_format, other):
2429
2251
 
2430
2252
 
2431
2253
class BadInventoryFormat(BzrError):
2432
 
 
 
2254
    
2433
2255
    _fmt = "Root class for inventory serialization errors"
2434
2256
 
2435
2257
 
2454
2276
        self.transport = transport
2455
2277
 
2456
2278
 
 
2279
class NoSmartServer(NotBranchError):
 
2280
 
 
2281
    _fmt = "No smart server available at %(url)s"
 
2282
 
 
2283
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
 
2284
    def __init__(self, url):
 
2285
        self.url = url
 
2286
 
 
2287
 
2457
2288
class UnknownSSH(BzrError):
2458
2289
 
2459
2290
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2479
2310
        self.revision_id = revision_id
2480
2311
        self.ghost_revision_id = ghost_revision_id
2481
2312
 
2482
 
 
 
2313
        
2483
2314
class GhostRevisionUnusableHere(BzrError):
2484
2315
 
2485
2316
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2577
2408
 
2578
2409
 
2579
2410
class UnsupportedInventoryKind(BzrError):
2580
 
 
 
2411
    
2581
2412
    _fmt = """Unsupported entry kind %(kind)s"""
2582
2413
 
2583
2414
    def __init__(self, kind):
2595
2426
 
2596
2427
 
2597
2428
class SubsumeTargetNeedsUpgrade(BzrError):
2598
 
 
 
2429
    
2599
2430
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2600
2431
 
2601
2432
    def __init__(self, other_tree):
2629
2460
    def __init__(self, branch):
2630
2461
        self.branch = branch
2631
2462
 
2632
 
 
 
2463
        
2633
2464
class TagAlreadyExists(BzrError):
2634
2465
 
2635
2466
    _fmt = "Tag %(tag_name)s already exists."
2640
2471
 
2641
2472
class MalformedBugIdentifier(BzrError):
2642
2473
 
2643
 
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
2644
 
            'See "bzr help bugs" for more information on this feature.')
 
2474
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2645
2475
 
2646
2476
    def __init__(self, bug_id, reason):
2647
2477
        self.bug_id = bug_id
2668
2498
        self.branch = branch
2669
2499
 
2670
2500
 
2671
 
class InvalidLineInBugsProperty(BzrError):
2672
 
 
2673
 
    _fmt = ("Invalid line in bugs property: '%(line)s'")
2674
 
 
2675
 
    def __init__(self, line):
2676
 
        self.line = line
2677
 
 
2678
 
 
2679
 
class InvalidBugStatus(BzrError):
2680
 
 
2681
 
    _fmt = ("Invalid bug status: '%(status)s'")
2682
 
 
2683
 
    def __init__(self, status):
2684
 
        self.status = status
2685
 
 
2686
 
 
2687
2501
class UnexpectedSmartServerResponse(BzrError):
2688
2502
 
2689
2503
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2717
2531
 
2718
2532
    This is distinct from ErrorFromSmartServer so that it is possible to
2719
2533
    distinguish between the following two cases:
2720
 
 
2721
 
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
2722
 
      and so should provoke a traceback to the user.
2723
 
    - ErrorFromSmartServer was caught but its error_tuple could not be
2724
 
      translated.  This is probably because the server sent us garbage, and
2725
 
      should not provoke a traceback.
 
2534
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2535
        and so should provoke a traceback to the user.
 
2536
      - ErrorFromSmartServer was caught but its error_tuple could not be
 
2537
        translated.  This is probably because the server sent us garbage, and
 
2538
        should not provoke a traceback.
2726
2539
    """
2727
2540
 
2728
2541
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2736
2549
        """
2737
2550
        self.error_from_smart_server = error_from_smart_server
2738
2551
        self.error_tuple = error_from_smart_server.error_tuple
2739
 
 
 
2552
        
2740
2553
 
2741
2554
class ContainerError(BzrError):
2742
2555
    """Base class of container errors."""
2745
2558
class UnknownContainerFormatError(ContainerError):
2746
2559
 
2747
2560
    _fmt = "Unrecognised container format: %(container_format)r"
2748
 
 
 
2561
    
2749
2562
    def __init__(self, container_format):
2750
2563
        self.container_format = container_format
2751
2564
 
2815
2628
 
2816
2629
class NoMailAddressSpecified(BzrError):
2817
2630
 
2818
 
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
 
2631
    _fmt = "No mail-to address specified."
2819
2632
 
2820
2633
 
2821
2634
class UnknownMailClient(BzrError):
2854
2667
 
2855
2668
    def __init__(self, bzrdir):
2856
2669
        import bzrlib.urlutils as urlutils
2857
 
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
 
2670
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
2858
2671
                                                    'ascii')
2859
2672
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2860
2673
 
2901
2714
    _fmt = "'%(display_url)s' is already standalone."
2902
2715
 
2903
2716
 
2904
 
class AlreadyWithTrees(BzrDirError):
2905
 
 
2906
 
    _fmt = ("Shared repository '%(display_url)s' already creates "
2907
 
            "working trees.")
2908
 
 
2909
 
 
2910
 
class AlreadyWithNoTrees(BzrDirError):
2911
 
 
2912
 
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
2913
 
            "working trees.")
2914
 
 
2915
 
 
2916
2717
class ReconfigurationNotSupported(BzrDirError):
2917
2718
 
2918
2719
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2925
2726
 
2926
2727
class UncommittedChanges(BzrError):
2927
2728
 
2928
 
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2929
 
            ' (See bzr status).%(more)s')
 
2729
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2930
2730
 
2931
 
    def __init__(self, tree, more=None):
2932
 
        if more is None:
2933
 
            more = ''
2934
 
        else:
2935
 
            more = ' ' + more
 
2731
    def __init__(self, tree):
2936
2732
        import bzrlib.urlutils as urlutils
2937
 
        user_url = getattr(tree, "user_url", None)
2938
 
        if user_url is None:
2939
 
            display_url = str(tree)
2940
 
        else:
2941
 
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2942
 
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2943
 
 
2944
 
 
2945
 
class ShelvedChanges(UncommittedChanges):
2946
 
 
2947
 
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
2948
 
            ' (See bzr shelve --list).%(more)s')
 
2733
        display_url = urlutils.unescape_for_display(
 
2734
            tree.bzrdir.root_transport.base, 'ascii')
 
2735
        BzrError.__init__(self, tree=tree, display_url=display_url)
2949
2736
 
2950
2737
 
2951
2738
class MissingTemplateVariable(BzrError):
2986
2773
 
2987
2774
 
2988
2775
class CommandAvailableInPlugin(StandardError):
2989
 
 
 
2776
    
2990
2777
    internal_error = False
2991
2778
 
2992
2779
    def __init__(self, cmd_name, plugin_metadata, provider):
2993
 
 
 
2780
        
2994
2781
        self.plugin_metadata = plugin_metadata
2995
2782
        self.cmd_name = cmd_name
2996
2783
        self.provider = provider
2997
2784
 
2998
2785
    def __str__(self):
2999
2786
 
3000
 
        _fmt = ('"%s" is not a standard bzr command. \n'
 
2787
        _fmt = ('"%s" is not a standard bzr command. \n' 
3001
2788
                'However, the following official plugin provides this command: %s\n'
3002
2789
                'You can install it by going to: %s'
3003
 
                % (self.cmd_name, self.plugin_metadata['name'],
 
2790
                % (self.cmd_name, self.plugin_metadata['name'], 
3004
2791
                    self.plugin_metadata['url']))
3005
2792
 
3006
2793
        return _fmt
3007
2794
 
3008
2795
 
3009
2796
class NoPluginAvailable(BzrError):
3010
 
    pass
 
2797
    pass    
 
2798
 
 
2799
 
 
2800
class NotATerminal(BzrError):
 
2801
 
 
2802
    _fmt = 'Unable to ask for a password without real terminal.'
3011
2803
 
3012
2804
 
3013
2805
class UnableEncodePath(BzrError):
3022
2814
        self.user_encoding = osutils.get_user_encoding()
3023
2815
 
3024
2816
 
3025
 
class NoSuchConfig(BzrError):
3026
 
 
3027
 
    _fmt = ('The "%(config_id)s" configuration does not exist.')
3028
 
 
3029
 
    def __init__(self, config_id):
3030
 
        BzrError.__init__(self, config_id=config_id)
3031
 
 
3032
 
 
3033
 
class NoSuchConfigOption(BzrError):
3034
 
 
3035
 
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
3036
 
 
3037
 
    def __init__(self, option_name):
3038
 
        BzrError.__init__(self, option_name=option_name)
3039
 
 
3040
 
 
3041
2817
class NoSuchAlias(BzrError):
3042
2818
 
3043
2819
    _fmt = ('The alias "%(alias_name)s" does not exist.')
3073
2849
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
3074
2850
 
3075
2851
    def __init__(self, host, port, orig_error):
3076
 
        # nb: in python2.4 socket.error doesn't have a useful repr
3077
2852
        BzrError.__init__(self, host=host, port=port,
3078
 
            orig_error=repr(orig_error.args))
 
2853
            orig_error=orig_error[1])
3079
2854
 
3080
2855
 
3081
2856
class UnknownRules(BzrError):
3089
2864
class HookFailed(BzrError):
3090
2865
    """Raised when a pre_change_branch_tip hook function fails anything other
3091
2866
    than TipChangeRejected.
3092
 
 
3093
 
    Note that this exception is no longer raised, and the import is only left
3094
 
    to be nice to code which might catch it in a plugin.
3095
2867
    """
3096
2868
 
3097
2869
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
3098
2870
            "%(traceback_text)s%(exc_value)s")
3099
2871
 
3100
 
    def __init__(self, hook_stage, hook_name, exc_info, warn=True):
3101
 
        if warn:
3102
 
            symbol_versioning.warn("BzrError HookFailed has been deprecated "
3103
 
                "as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
 
2872
    def __init__(self, hook_stage, hook_name, exc_info):
3104
2873
        import traceback
3105
2874
        self.hook_stage = hook_stage
3106
2875
        self.hook_name = hook_name
3115
2884
    """A pre_change_branch_tip hook function may raise this to cleanly and
3116
2885
    explicitly abort a change to a branch tip.
3117
2886
    """
3118
 
 
 
2887
    
3119
2888
    _fmt = u"Tip change rejected: %(msg)s"
3120
2889
 
3121
2890
    def __init__(self, msg):
3122
2891
        self.msg = msg
3123
2892
 
3124
 
 
3125
 
class ShelfCorrupt(BzrError):
3126
 
 
3127
 
    _fmt = "Shelf corrupt."
3128
 
 
3129
 
 
3130
 
class DecompressCorruption(BzrError):
3131
 
 
3132
 
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
3133
 
 
3134
 
    def __init__(self, orig_error=None):
3135
 
        if orig_error is not None:
3136
 
            self.orig_error = ", %s" % (orig_error,)
3137
 
        else:
3138
 
            self.orig_error = ""
3139
 
        BzrError.__init__(self)
3140
 
 
3141
 
 
3142
 
class NoSuchShelfId(BzrError):
3143
 
 
3144
 
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
3145
 
 
3146
 
    def __init__(self, shelf_id):
3147
 
        BzrError.__init__(self, shelf_id=shelf_id)
3148
 
 
3149
 
 
3150
 
class InvalidShelfId(BzrError):
3151
 
 
3152
 
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3153
 
 
3154
 
    def __init__(self, invalid_id):
3155
 
        BzrError.__init__(self, invalid_id=invalid_id)
3156
 
 
3157
 
 
3158
 
class JailBreak(BzrError):
3159
 
 
3160
 
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3161
 
 
3162
 
    def __init__(self, url):
3163
 
        BzrError.__init__(self, url=url)
3164
 
 
3165
 
 
3166
 
class UserAbort(BzrError):
3167
 
 
3168
 
    _fmt = 'The user aborted the operation.'
3169
 
 
3170
 
 
3171
 
class MustHaveWorkingTree(BzrError):
3172
 
 
3173
 
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3174
 
 
3175
 
    def __init__(self, format, url):
3176
 
        BzrError.__init__(self, format=format, url=url)
3177
 
 
3178
 
 
3179
 
class NoSuchView(BzrError):
3180
 
    """A view does not exist.
3181
 
    """
3182
 
 
3183
 
    _fmt = u"No such view: %(view_name)s."
3184
 
 
3185
 
    def __init__(self, view_name):
3186
 
        self.view_name = view_name
3187
 
 
3188
 
 
3189
 
class ViewsNotSupported(BzrError):
3190
 
    """Views are not supported by a tree format.
3191
 
    """
3192
 
 
3193
 
    _fmt = ("Views are not supported by %(tree)s;"
3194
 
            " use 'bzr upgrade' to change your tree to a later format.")
3195
 
 
3196
 
    def __init__(self, tree):
3197
 
        self.tree = tree
3198
 
 
3199
 
 
3200
 
class FileOutsideView(BzrError):
3201
 
 
3202
 
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
3203
 
            '%(view_str)s')
3204
 
 
3205
 
    def __init__(self, file_name, view_files):
3206
 
        self.file_name = file_name
3207
 
        self.view_str = ", ".join(view_files)
3208
 
 
3209
 
 
3210
 
class UnresumableWriteGroup(BzrError):
3211
 
 
3212
 
    _fmt = ("Repository %(repository)s cannot resume write group "
3213
 
            "%(write_groups)r: %(reason)s")
3214
 
 
3215
 
    internal_error = True
3216
 
 
3217
 
    def __init__(self, repository, write_groups, reason):
3218
 
        self.repository = repository
3219
 
        self.write_groups = write_groups
3220
 
        self.reason = reason
3221
 
 
3222
 
 
3223
 
class UnsuspendableWriteGroup(BzrError):
3224
 
 
3225
 
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
3226
 
 
3227
 
    internal_error = True
3228
 
 
3229
 
    def __init__(self, repository):
3230
 
        self.repository = repository
3231
 
 
3232
 
 
3233
 
class LossyPushToSameVCS(BzrError):
3234
 
 
3235
 
    _fmt = ("Lossy push not possible between %(source_branch)r and "
3236
 
            "%(target_branch)r that are in the same VCS.")
3237
 
 
3238
 
    internal_error = True
3239
 
 
3240
 
    def __init__(self, source_branch, target_branch):
3241
 
        self.source_branch = source_branch
3242
 
        self.target_branch = target_branch
3243
 
 
3244
 
 
3245
 
class NoRoundtrippingSupport(BzrError):
3246
 
 
3247
 
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
3248
 
            "%(target_branch)r.")
3249
 
 
3250
 
    internal_error = True
3251
 
 
3252
 
    def __init__(self, source_branch, target_branch):
3253
 
        self.source_branch = source_branch
3254
 
        self.target_branch = target_branch
3255
 
 
3256
 
 
3257
 
class FileTimestampUnavailable(BzrError):
3258
 
 
3259
 
    _fmt = "The filestamp for %(path)s is not available."
3260
 
 
3261
 
    internal_error = True
3262
 
 
3263
 
    def __init__(self, path):
3264
 
        self.path = path
3265
 
 
3266
 
 
3267
 
class NoColocatedBranchSupport(BzrError):
3268
 
 
3269
 
    _fmt = ("%(bzrdir)r does not support co-located branches.")
3270
 
 
3271
 
    def __init__(self, bzrdir):
3272
 
        self.bzrdir = bzrdir
3273
 
 
3274
 
 
3275
 
class NoWhoami(BzrError):
3276
 
 
3277
 
    _fmt = ('Unable to determine your name.\n'
3278
 
        "Please, set your name with the 'whoami' command.\n"
3279
 
        'E.g. bzr whoami "Your Name <name@example.com>"')
3280
 
 
3281
 
 
3282
 
class InvalidPattern(BzrError):
3283
 
 
3284
 
    _fmt = ('Invalid pattern(s) found. %(msg)s')
3285
 
 
3286
 
    def __init__(self, msg):
3287
 
        self.msg = msg
3288
 
 
3289
 
 
3290
 
class RecursiveBind(BzrError):
3291
 
 
3292
 
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3293
 
        'Please use `bzr unbind` to fix.')
3294
 
 
3295
 
    def __init__(self, branch_url):
3296
 
        self.branch_url = branch_url
3297
 
 
3298
 
 
3299
 
# FIXME: I would prefer to define the config related exception classes in
3300
 
# config.py but the lazy import mechanism proscribes this -- vila 20101222
3301
 
class OptionExpansionLoop(BzrError):
3302
 
 
3303
 
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3304
 
 
3305
 
    def __init__(self, string, refs):
3306
 
        self.string = string
3307
 
        self.refs = '->'.join(refs)
3308
 
 
3309
 
 
3310
 
class ExpandingUnknownOption(BzrError):
3311
 
 
3312
 
    _fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
3313
 
 
3314
 
    def __init__(self, name, string):
3315
 
        self.name = name
3316
 
        self.string = string
3317
 
 
3318
 
 
3319
 
class NoCompatibleInter(BzrError):
3320
 
 
3321
 
    _fmt = ('No compatible object available for operations from %(source)r '
3322
 
            'to %(target)r.')
3323
 
 
3324
 
    def __init__(self, source, target):
3325
 
        self.source = source
3326
 
        self.target = target