~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Florian Dorn
  • Date: 2012-04-03 14:49:22 UTC
  • mto: This revision was merged to the branch mainline in revision 6546.
  • Revision ID: florian.dorn@boku.ac.at-20120403144922-b8y59csy8l1rzs5u
updated developer docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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., 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
 
55
54
    Base class for errors raised by bzrlib.
56
55
 
57
56
    :cvar internal_error: if True this was probably caused by a bzr bug and
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.)
 
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.)
61
60
 
62
61
    :cvar _fmt: Format string to display the error; this is expanded
63
 
    by the instance's dict.
 
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):
304
304
class RootMissing(InternalBzrError):
305
305
 
306
306
    _fmt = ("The root entry of a tree must be the first entry supplied to "
307
 
        "record_entry_contents.")
 
307
        "the commit builder.")
308
308
 
309
309
 
310
310
class NoPublicBranch(BzrError):
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
 
670
680
 
671
681
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
672
682
 
673
 
    internal_error = True
 
683
    internal_error = False
674
684
 
675
685
    def __init__(self, path, base, extra=None):
676
686
        BzrError.__init__(self)
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
 
    _fmt = 'Not a branch: "%(path)s".'
 
705
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
696
706
 
697
 
    def __init__(self, path):
 
707
    def __init__(self, path, detail=None, bzrdir=None):
698
708
       import bzrlib.urlutils as urlutils
699
 
       self.path = urlutils.unescape_for_display(path, 'ascii')
 
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)
700
743
 
701
744
 
702
745
class NoSubmitBranch(PathError):
751
794
 
752
795
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
753
796
 
 
797
    # use PathNotChild instead
 
798
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 3, 0)))
754
799
    def __init__(self, branch, path):
755
800
        BzrError.__init__(self)
756
801
        self.branch = branch
764
809
 
765
810
 
766
811
class UnknownFormatError(BzrError):
767
 
    
 
812
 
768
813
    _fmt = "Unknown %(kind)s format: %(format)r"
769
814
 
770
815
    def __init__(self, format, kind='branch'):
773
818
 
774
819
 
775
820
class IncompatibleFormat(BzrError):
776
 
    
 
821
 
777
822
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
778
823
 
779
824
    def __init__(self, format, bzrdir_format):
783
828
 
784
829
 
785
830
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
    """
786
837
 
787
838
    _fmt = "%(target)s\n" \
788
839
            "is not compatible with\n" \
796
847
 
797
848
 
798
849
class IncompatibleRevision(BzrError):
799
 
    
 
850
 
800
851
    _fmt = "Revision is not compatible with %(repo_format)s"
801
852
 
802
853
    def __init__(self, repo_format):
813
864
        """Construct a new AlreadyVersionedError.
814
865
 
815
866
        :param path: This is the path which is versioned,
816
 
        which should be in a user friendly form.
 
867
            which should be in a user friendly form.
817
868
        :param context_info: If given, this is information about the context,
818
 
        which could explain why this is expected to not be versioned.
 
869
            which could explain why this is expected to not be versioned.
819
870
        """
820
871
        BzrError.__init__(self)
821
872
        self.path = path
834
885
        """Construct a new NotVersionedError.
835
886
 
836
887
        :param path: This is the path which is not versioned,
837
 
        which should be in a user friendly form.
 
888
            which should be in a user friendly form.
838
889
        :param context_info: If given, this is information about the context,
839
 
        which could explain why this is expected to be versioned.
 
890
            which could explain why this is expected to be versioned.
840
891
        """
841
892
        BzrError.__init__(self)
842
893
        self.path = path
910
961
    # original exception is available as e.original_error
911
962
    #
912
963
    # New code should prefer to raise specific subclasses
913
 
    def __init__(self, message):
914
 
        # Python 2.5 uses a slot for StandardError.message,
915
 
        # so use a different variable name.  We now work around this in
916
 
        # BzrError.__str__, but this member name is kept for compatability.
917
 
        self.msg = message
 
964
    def __init__(self, msg):
 
965
        self.msg = msg
918
966
 
919
967
 
920
968
class LockActive(LockError):
1003
1051
 
1004
1052
class LockContention(LockError):
1005
1053
 
1006
 
    _fmt = 'Could not acquire lock "%(lock)s"'
1007
 
    # TODO: show full url for lock, combining the transport and relative
1008
 
    # bits?
 
1054
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
1009
1055
 
1010
1056
    internal_error = False
1011
1057
 
1012
 
    def __init__(self, lock):
 
1058
    def __init__(self, lock, msg=''):
1013
1059
        self.lock = lock
 
1060
        self.msg = msg
1014
1061
 
1015
1062
 
1016
1063
class LockBroken(LockError):
1037
1084
        self.target = target
1038
1085
 
1039
1086
 
 
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
 
1040
1099
class LockNotHeld(LockError):
1041
1100
 
1042
1101
    _fmt = "Lock not held: %(lock)s"
1081
1140
        BzrError.__init__(self, files=files, files_str=files_str)
1082
1141
 
1083
1142
 
 
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
 
1084
1152
class BadCommitMessageEncoding(BzrError):
1085
1153
 
1086
1154
    _fmt = 'The specified commit message contains characters unsupported by '\
1130
1198
 
1131
1199
class NoSuchRevisionInTree(NoSuchRevision):
1132
1200
    """When using Tree.revision_tree, and the revision is not accessible."""
1133
 
    
 
1201
 
1134
1202
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1135
1203
 
1136
1204
    def __init__(self, tree, revision_id):
1141
1209
 
1142
1210
class InvalidRevisionSpec(BzrError):
1143
1211
 
1144
 
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
1145
 
            " %(branch)s%(extra)s")
 
1212
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
 
1213
            " %(branch_url)s%(extra)s")
1146
1214
 
1147
1215
    def __init__(self, spec, branch, extra=None):
1148
1216
        BzrError.__init__(self, branch=branch, spec=spec)
 
1217
        self.branch_url = getattr(branch, 'user_url', str(branch))
1149
1218
        if extra:
1150
1219
            self.extra = '\n' + str(extra)
1151
1220
        else:
1172
1241
class DivergedBranches(BzrError):
1173
1242
 
1174
1243
    _fmt = ("These branches have diverged."
1175
 
            " Use the merge command to reconcile them.")
 
1244
            " Use the missing command to see how.\n"
 
1245
            "Use the merge command to reconcile them.")
1176
1246
 
1177
1247
    def __init__(self, branch1, branch2):
1178
1248
        self.branch1 = branch1
1200
1270
 
1201
1271
 
1202
1272
class NoCommonAncestor(BzrError):
1203
 
    
 
1273
 
1204
1274
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1205
1275
 
1206
1276
    def __init__(self, revision_a, revision_b):
1226
1296
            not_ancestor_id=not_ancestor_id)
1227
1297
 
1228
1298
 
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
1299
class AmbiguousBase(BzrError):
1239
1300
 
1240
1301
    def __init__(self, bases):
1241
 
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
1242
 
                DeprecationWarning)
 
1302
        symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
 
1303
            "as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
1243
1304
        msg = ("The correct base is unclear, because %s are all equally close"
1244
1305
                % ", ".join(bases))
1245
1306
        BzrError.__init__(self, msg)
1267
1328
class BoundBranchOutOfDate(BzrError):
1268
1329
 
1269
1330
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1270
 
            " %(master)s.")
 
1331
            " %(master)s.%(extra_help)s")
1271
1332
 
1272
1333
    def __init__(self, branch, master):
1273
1334
        BzrError.__init__(self)
1274
1335
        self.branch = branch
1275
1336
        self.master = master
1276
 
 
1277
 
        
 
1337
        self.extra_help = ''
 
1338
 
 
1339
 
1278
1340
class CommitToDoubleBoundBranch(BzrError):
1279
1341
 
1280
1342
    _fmt = ("Cannot commit to branch %(branch)s."
1310
1372
 
1311
1373
class WeaveError(BzrError):
1312
1374
 
1313
 
    _fmt = "Error in processing weave: %(message)s"
 
1375
    _fmt = "Error in processing weave: %(msg)s"
1314
1376
 
1315
 
    def __init__(self, message=None):
 
1377
    def __init__(self, msg=None):
1316
1378
        BzrError.__init__(self)
1317
 
        self.message = message
 
1379
        self.msg = msg
1318
1380
 
1319
1381
 
1320
1382
class WeaveRevisionAlreadyPresent(WeaveError):
1349
1411
 
1350
1412
class WeaveParentMismatch(WeaveError):
1351
1413
 
1352
 
    _fmt = "Parents are mismatched between two revisions. %(message)s"
1353
 
    
 
1414
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
 
1415
 
1354
1416
 
1355
1417
class WeaveInvalidChecksum(WeaveError):
1356
1418
 
1357
 
    _fmt = "Text did not match it's checksum: %(message)s"
 
1419
    _fmt = "Text did not match its checksum: %(msg)s"
1358
1420
 
1359
1421
 
1360
1422
class WeaveTextDiffers(WeaveError):
1382
1444
 
1383
1445
 
1384
1446
class VersionedFileError(BzrError):
1385
 
    
 
1447
 
1386
1448
    _fmt = "Versioned file error"
1387
1449
 
1388
1450
 
1389
1451
class RevisionNotPresent(VersionedFileError):
1390
 
    
 
1452
 
1391
1453
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1392
1454
 
1393
1455
    def __init__(self, revision_id, file_id):
1397
1459
 
1398
1460
 
1399
1461
class RevisionAlreadyPresent(VersionedFileError):
1400
 
    
 
1462
 
1401
1463
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1402
1464
 
1403
1465
    def __init__(self, revision_id, file_id):
1408
1470
 
1409
1471
class VersionedFileInvalidChecksum(VersionedFileError):
1410
1472
 
1411
 
    _fmt = "Text did not match its checksum: %(message)s"
 
1473
    _fmt = "Text did not match its checksum: %(msg)s"
1412
1474
 
1413
1475
 
1414
1476
class KnitError(InternalBzrError):
1415
 
    
 
1477
 
1416
1478
    _fmt = "Knit error"
1417
1479
 
1418
1480
 
1426
1488
        self.how = how
1427
1489
 
1428
1490
 
 
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
 
1429
1506
class KnitDataStreamIncompatible(KnitError):
1430
1507
    # Not raised anymore, as we can convert data streams.  In future we may
1431
1508
    # need it again for more exotic cases, so we're keeping it around for now.
1435
1512
    def __init__(self, stream_format, target_format):
1436
1513
        self.stream_format = stream_format
1437
1514
        self.target_format = target_format
1438
 
        
 
1515
 
1439
1516
 
1440
1517
class KnitDataStreamUnknown(KnitError):
1441
1518
    # Indicates a data stream we don't know how to handle.
1444
1521
 
1445
1522
    def __init__(self, stream_format):
1446
1523
        self.stream_format = stream_format
1447
 
        
 
1524
 
1448
1525
 
1449
1526
class KnitHeaderError(KnitError):
1450
1527
 
1460
1537
 
1461
1538
    Currently only 'fulltext' and 'line-delta' are supported.
1462
1539
    """
1463
 
    
 
1540
 
1464
1541
    _fmt = ("Knit index %(filename)s does not have a known method"
1465
1542
            " in options: %(options)r")
1466
1543
 
1470
1547
        self.options = options
1471
1548
 
1472
1549
 
 
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
 
1473
1596
class NoSuchExportFormat(BzrError):
1474
 
    
 
1597
 
1475
1598
    _fmt = "Export format %(format)r not supported"
1476
1599
 
1477
1600
    def __init__(self, format):
1480
1603
 
1481
1604
 
1482
1605
class TransportError(BzrError):
1483
 
    
 
1606
 
1484
1607
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1485
1608
 
1486
1609
    def __init__(self, msg=None, orig_error=None):
1531
1654
 
1532
1655
class SmartMessageHandlerError(InternalBzrError):
1533
1656
 
1534
 
    _fmt = "The message handler raised an exception: %(exc_value)s."
 
1657
    _fmt = ("The message handler raised an exception:\n"
 
1658
            "%(traceback_text)s")
1535
1659
 
1536
1660
    def __init__(self, exc_info):
1537
 
        self.exc_type, self.exc_value, self.tb = exc_info
1538
 
        
 
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
 
1539
1668
 
1540
1669
# A set of semi-meaningful errors which can be thrown
1541
1670
class TransportNotPossible(TransportError):
1567
1696
            self.port = ':%s' % port
1568
1697
 
1569
1698
 
 
1699
# XXX: This is also used for unexpected end of file, which is different at the
 
1700
# TCP level from "connection reset".
1570
1701
class ConnectionReset(TransportError):
1571
1702
 
1572
1703
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1613
1744
 
1614
1745
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1615
1746
 
1616
 
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
 
1747
    def __init__(self, source, target, is_permanent=False):
1617
1748
        self.source = source
1618
1749
        self.target = target
1619
1750
        if is_permanent:
1620
1751
            self.permanently = ' permanently'
1621
1752
        else:
1622
1753
            self.permanently = ''
1623
 
        self._qualified_proto = qual_proto
1624
1754
        TransportError.__init__(self)
1625
1755
 
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
1756
 
1660
1757
class TooManyRedirections(TransportError):
1661
1758
 
1669
1766
 
1670
1767
class ParseConfigError(BzrError):
1671
1768
 
 
1769
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
 
1770
 
1672
1771
    def __init__(self, errors, filename):
1673
 
        if filename is None:
1674
 
            filename = ""
1675
 
        message = "Error(s) parsing config file %s:\n%s" % \
1676
 
            (filename, ('\n'.join(e.message for e in errors)))
1677
 
        BzrError.__init__(self, message)
 
1772
        BzrError.__init__(self)
 
1773
        self.filename = filename
 
1774
        self.errors = '\n'.join(e.msg for e in errors)
1678
1775
 
1679
1776
 
1680
1777
class NoEmailInUsername(BzrError):
1696
1793
 
1697
1794
class WorkingTreeNotRevision(BzrError):
1698
1795
 
1699
 
    _fmt = ("The working tree for %(basedir)s has changed since" 
 
1796
    _fmt = ("The working tree for %(basedir)s has changed since"
1700
1797
            " the last commit, but weave merge requires that it be"
1701
1798
            " unchanged")
1702
1799
 
1859
1956
    _fmt = "Moving the root directory is not supported at this time"
1860
1957
 
1861
1958
 
 
1959
class TransformRenameFailed(BzrError):
 
1960
 
 
1961
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
 
1962
 
 
1963
    def __init__(self, from_path, to_path, why, errno):
 
1964
        self.from_path = from_path
 
1965
        self.to_path = to_path
 
1966
        self.why = why
 
1967
        self.errno = errno
 
1968
 
 
1969
 
1862
1970
class BzrMoveFailedError(BzrError):
1863
1971
 
1864
 
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1972
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
 
1973
        "%(_has_extra)s%(extra)s")
1865
1974
 
1866
1975
    def __init__(self, from_path='', to_path='', extra=None):
 
1976
        from bzrlib.osutils import splitpath
1867
1977
        BzrError.__init__(self)
1868
1978
        if extra:
1869
 
            self.extra = ': ' + str(extra)
 
1979
            self.extra, self._has_extra = extra, ': '
1870
1980
        else:
1871
 
            self.extra = ''
 
1981
            self.extra = self._has_extra = ''
1872
1982
 
1873
1983
        has_from = len(from_path) > 0
1874
1984
        has_to = len(to_path) > 0
1875
1985
        if has_from:
1876
 
            self.from_path = osutils.splitpath(from_path)[-1]
 
1986
            self.from_path = splitpath(from_path)[-1]
1877
1987
        else:
1878
1988
            self.from_path = ''
1879
1989
 
1880
1990
        if has_to:
1881
 
            self.to_path = osutils.splitpath(to_path)[-1]
 
1991
            self.to_path = splitpath(to_path)[-1]
1882
1992
        else:
1883
1993
            self.to_path = ''
1884
1994
 
1895
2005
 
1896
2006
class BzrRenameFailedError(BzrMoveFailedError):
1897
2007
 
1898
 
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
2008
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
 
2009
        "%(_has_extra)s%(extra)s")
1899
2010
 
1900
2011
    def __init__(self, from_path, to_path, extra=None):
1901
2012
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1902
2013
 
 
2014
 
1903
2015
class BzrRemoveChangedFilesError(BzrError):
1904
2016
    """Used when user is trying to remove changed files."""
1905
2017
 
1908
2020
        "Use --keep to not delete them, or --force to delete them regardless.")
1909
2021
 
1910
2022
    def __init__(self, tree_delta):
 
2023
        symbol_versioning.warn(symbol_versioning.deprecated_in((2, 3, 0)) %
 
2024
            "BzrRemoveChangedFilesError", DeprecationWarning, stacklevel=2)
1911
2025
        BzrError.__init__(self)
1912
2026
        self.changes_as_text = tree_delta.get_changes_as_text()
1913
2027
        #self.paths_as_string = '\n'.join(changed_files)
1921
2035
 
1922
2036
class BzrBadParameterMissing(BzrBadParameter):
1923
2037
 
1924
 
    _fmt = "Parameter $(param)s is required but not present."
 
2038
    _fmt = "Parameter %(param)s is required but not present."
1925
2039
 
1926
2040
 
1927
2041
class BzrBadParameterUnicode(BzrBadParameter):
1967
2081
 
1968
2082
class BadConversionTarget(BzrError):
1969
2083
 
1970
 
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
 
2084
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
 
2085
            "    %(problem)s"
1971
2086
 
1972
 
    def __init__(self, problem, format):
 
2087
    def __init__(self, problem, format, from_format=None):
1973
2088
        BzrError.__init__(self)
1974
2089
        self.problem = problem
1975
2090
        self.format = format
 
2091
        self.from_format = from_format or '(unspecified)'
1976
2092
 
1977
2093
 
1978
2094
class NoDiffFound(BzrError):
2015
2131
    _fmt = """This tree contains left-over files from a failed operation.
2016
2132
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2017
2133
    keep, and delete it when you are done."""
2018
 
    
 
2134
 
2019
2135
    def __init__(self, limbo_dir):
2020
2136
       BzrError.__init__(self)
2021
2137
       self.limbo_dir = limbo_dir
2054
2170
 
2055
2171
class OutOfDateTree(BzrError):
2056
2172
 
2057
 
    _fmt = "Working tree is out of date, please run 'bzr update'."
 
2173
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
2058
2174
 
2059
 
    def __init__(self, tree):
 
2175
    def __init__(self, tree, more=None):
 
2176
        if more is None:
 
2177
            more = ''
 
2178
        else:
 
2179
            more = ' ' + more
2060
2180
        BzrError.__init__(self)
2061
2181
        self.tree = tree
 
2182
        self.more = more
2062
2183
 
2063
2184
 
2064
2185
class PublicBranchOutOfDate(BzrError):
2102
2223
 
2103
2224
    def __init__(self, repo):
2104
2225
        BzrError.__init__(self)
2105
 
        self.repo_path = repo.bzrdir.root_transport.base
 
2226
        self.repo_path = repo.user_url
2106
2227
 
2107
2228
 
2108
2229
class InconsistentDelta(BzrError):
2118
2239
        self.reason = reason
2119
2240
 
2120
2241
 
 
2242
class InconsistentDeltaDelta(InconsistentDelta):
 
2243
    """Used when we get a delta that is not valid."""
 
2244
 
 
2245
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
 
2246
            "\nreason: %(reason)s")
 
2247
 
 
2248
    def __init__(self, delta, reason):
 
2249
        BzrError.__init__(self)
 
2250
        self.delta = delta
 
2251
        self.reason = reason
 
2252
 
 
2253
 
2121
2254
class UpgradeRequired(BzrError):
2122
2255
 
2123
2256
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2132
2265
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2133
2266
 
2134
2267
 
 
2268
class RichRootUpgradeRequired(UpgradeRequired):
 
2269
 
 
2270
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
 
2271
           " a format which supports rich roots.")
 
2272
 
 
2273
 
2135
2274
class LocalRequiresBoundBranch(BzrError):
2136
2275
 
2137
2276
    _fmt = "Cannot perform local-only commits on unbound branches."
2138
2277
 
2139
2278
 
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
2279
class UnsupportedOperation(BzrError):
2155
2280
 
2156
2281
    _fmt = ("The method %(mname)s is not supported on"
2173
2298
 
2174
2299
 
2175
2300
class BinaryFile(BzrError):
2176
 
    
 
2301
 
2177
2302
    _fmt = "File is binary but should be text."
2178
2303
 
2179
2304
 
2199
2324
 
2200
2325
 
2201
2326
class NotABundle(BzrError):
2202
 
    
 
2327
 
2203
2328
    _fmt = "Not a bzr revision-bundle: %(text)r"
2204
2329
 
2205
2330
    def __init__(self, text):
2207
2332
        self.text = text
2208
2333
 
2209
2334
 
2210
 
class BadBundle(BzrError): 
2211
 
    
 
2335
class BadBundle(BzrError):
 
2336
 
2212
2337
    _fmt = "Bad bzr revision-bundle: %(text)r"
2213
2338
 
2214
2339
    def __init__(self, text):
2216
2341
        self.text = text
2217
2342
 
2218
2343
 
2219
 
class MalformedHeader(BadBundle): 
2220
 
    
 
2344
class MalformedHeader(BadBundle):
 
2345
 
2221
2346
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2222
2347
 
2223
2348
 
2224
 
class MalformedPatches(BadBundle): 
2225
 
    
 
2349
class MalformedPatches(BadBundle):
 
2350
 
2226
2351
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2227
2352
 
2228
2353
 
2229
 
class MalformedFooter(BadBundle): 
2230
 
    
 
2354
class MalformedFooter(BadBundle):
 
2355
 
2231
2356
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2232
2357
 
2233
2358
 
2234
2359
class UnsupportedEOLMarker(BadBundle):
2235
 
    
2236
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
 
2360
 
 
2361
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
2237
2362
 
2238
2363
    def __init__(self):
2239
 
        # XXX: BadBundle's constructor assumes there's explanatory text, 
 
2364
        # XXX: BadBundle's constructor assumes there's explanatory text,
2240
2365
        # but for this there is not
2241
2366
        BzrError.__init__(self)
2242
2367
 
2243
2368
 
2244
2369
class IncompatibleBundleFormat(BzrError):
2245
 
    
 
2370
 
2246
2371
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2247
2372
 
2248
2373
    def __init__(self, bundle_format, other):
2252
2377
 
2253
2378
 
2254
2379
class BadInventoryFormat(BzrError):
2255
 
    
 
2380
 
2256
2381
    _fmt = "Root class for inventory serialization errors"
2257
2382
 
2258
2383
 
2277
2402
        self.transport = transport
2278
2403
 
2279
2404
 
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
2405
class UnknownSSH(BzrError):
2290
2406
 
2291
2407
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2311
2427
        self.revision_id = revision_id
2312
2428
        self.ghost_revision_id = ghost_revision_id
2313
2429
 
2314
 
        
 
2430
 
2315
2431
class GhostRevisionUnusableHere(BzrError):
2316
2432
 
2317
2433
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2409
2525
 
2410
2526
 
2411
2527
class UnsupportedInventoryKind(BzrError):
2412
 
    
 
2528
 
2413
2529
    _fmt = """Unsupported entry kind %(kind)s"""
2414
2530
 
2415
2531
    def __init__(self, kind):
2427
2543
 
2428
2544
 
2429
2545
class SubsumeTargetNeedsUpgrade(BzrError):
2430
 
    
 
2546
 
2431
2547
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2432
2548
 
2433
2549
    def __init__(self, other_tree):
2461
2577
    def __init__(self, branch):
2462
2578
        self.branch = branch
2463
2579
 
2464
 
        
 
2580
 
2465
2581
class TagAlreadyExists(BzrError):
2466
2582
 
2467
2583
    _fmt = "Tag %(tag_name)s already exists."
2472
2588
 
2473
2589
class MalformedBugIdentifier(BzrError):
2474
2590
 
2475
 
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2591
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
2592
            'See "bzr help bugs" for more information on this feature.')
2476
2593
 
2477
2594
    def __init__(self, bug_id, reason):
2478
2595
        self.bug_id = bug_id
2499
2616
        self.branch = branch
2500
2617
 
2501
2618
 
 
2619
class InvalidLineInBugsProperty(BzrError):
 
2620
 
 
2621
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
2622
 
 
2623
    def __init__(self, line):
 
2624
        self.line = line
 
2625
 
 
2626
 
 
2627
class InvalidBugStatus(BzrError):
 
2628
 
 
2629
    _fmt = ("Invalid bug status: '%(status)s'")
 
2630
 
 
2631
    def __init__(self, status):
 
2632
        self.status = status
 
2633
 
 
2634
 
2502
2635
class UnexpectedSmartServerResponse(BzrError):
2503
2636
 
2504
2637
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2508
2641
 
2509
2642
 
2510
2643
class ErrorFromSmartServer(BzrError):
 
2644
    """An error was received from a smart server.
 
2645
 
 
2646
    :seealso: UnknownErrorFromSmartServer
 
2647
    """
2511
2648
 
2512
2649
    _fmt = "Error received from smart server: %(error_tuple)r"
2513
2650
 
2522
2659
        self.error_args = error_tuple[1:]
2523
2660
 
2524
2661
 
 
2662
class UnknownErrorFromSmartServer(BzrError):
 
2663
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
 
2664
    error.
 
2665
 
 
2666
    This is distinct from ErrorFromSmartServer so that it is possible to
 
2667
    distinguish between the following two cases:
 
2668
 
 
2669
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2670
      and so should provoke a traceback to the user.
 
2671
    - ErrorFromSmartServer was caught but its error_tuple could not be
 
2672
      translated.  This is probably because the server sent us garbage, and
 
2673
      should not provoke a traceback.
 
2674
    """
 
2675
 
 
2676
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
 
2677
 
 
2678
    internal_error = False
 
2679
 
 
2680
    def __init__(self, error_from_smart_server):
 
2681
        """Constructor.
 
2682
 
 
2683
        :param error_from_smart_server: An ErrorFromSmartServer instance.
 
2684
        """
 
2685
        self.error_from_smart_server = error_from_smart_server
 
2686
        self.error_tuple = error_from_smart_server.error_tuple
 
2687
 
 
2688
 
2525
2689
class ContainerError(BzrError):
2526
2690
    """Base class of container errors."""
2527
2691
 
2529
2693
class UnknownContainerFormatError(ContainerError):
2530
2694
 
2531
2695
    _fmt = "Unrecognised container format: %(container_format)r"
2532
 
    
 
2696
 
2533
2697
    def __init__(self, container_format):
2534
2698
        self.container_format = container_format
2535
2699
 
2599
2763
 
2600
2764
class NoMailAddressSpecified(BzrError):
2601
2765
 
2602
 
    _fmt = "No mail-to address specified."
 
2766
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
2603
2767
 
2604
2768
 
2605
2769
class UnknownMailClient(BzrError):
2638
2802
 
2639
2803
    def __init__(self, bzrdir):
2640
2804
        import bzrlib.urlutils as urlutils
2641
 
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2805
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
2642
2806
                                                    'ascii')
2643
2807
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2644
2808
 
2685
2849
    _fmt = "'%(display_url)s' is already standalone."
2686
2850
 
2687
2851
 
 
2852
class AlreadyWithTrees(BzrDirError):
 
2853
 
 
2854
    _fmt = ("Shared repository '%(display_url)s' already creates "
 
2855
            "working trees.")
 
2856
 
 
2857
 
 
2858
class AlreadyWithNoTrees(BzrDirError):
 
2859
 
 
2860
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
 
2861
            "working trees.")
 
2862
 
 
2863
 
2688
2864
class ReconfigurationNotSupported(BzrDirError):
2689
2865
 
2690
2866
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2697
2873
 
2698
2874
class UncommittedChanges(BzrError):
2699
2875
 
2700
 
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
 
2876
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
 
2877
            ' (See bzr status).%(more)s')
2701
2878
 
2702
 
    def __init__(self, tree):
 
2879
    def __init__(self, tree, more=None):
 
2880
        if more is None:
 
2881
            more = ''
 
2882
        else:
 
2883
            more = ' ' + more
2703
2884
        import bzrlib.urlutils as urlutils
2704
 
        display_url = urlutils.unescape_for_display(
2705
 
            tree.bzrdir.root_transport.base, 'ascii')
2706
 
        BzrError.__init__(self, tree=tree, display_url=display_url)
 
2885
        user_url = getattr(tree, "user_url", None)
 
2886
        if user_url is None:
 
2887
            display_url = str(tree)
 
2888
        else:
 
2889
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
 
2890
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
 
2891
 
 
2892
 
 
2893
class ShelvedChanges(UncommittedChanges):
 
2894
 
 
2895
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
 
2896
            ' (See bzr shelve --list).%(more)s')
2707
2897
 
2708
2898
 
2709
2899
class MissingTemplateVariable(BzrError):
2744
2934
 
2745
2935
 
2746
2936
class CommandAvailableInPlugin(StandardError):
2747
 
    
 
2937
 
2748
2938
    internal_error = False
2749
2939
 
2750
2940
    def __init__(self, cmd_name, plugin_metadata, provider):
2751
 
        
 
2941
 
2752
2942
        self.plugin_metadata = plugin_metadata
2753
2943
        self.cmd_name = cmd_name
2754
2944
        self.provider = provider
2755
2945
 
2756
2946
    def __str__(self):
2757
2947
 
2758
 
        _fmt = ('"%s" is not a standard bzr command. \n' 
 
2948
        _fmt = ('"%s" is not a standard bzr command. \n'
2759
2949
                'However, the following official plugin provides this command: %s\n'
2760
2950
                'You can install it by going to: %s'
2761
 
                % (self.cmd_name, self.plugin_metadata['name'], 
 
2951
                % (self.cmd_name, self.plugin_metadata['name'],
2762
2952
                    self.plugin_metadata['url']))
2763
2953
 
2764
2954
        return _fmt
2765
2955
 
2766
2956
 
2767
2957
class NoPluginAvailable(BzrError):
2768
 
    pass    
2769
 
 
2770
 
 
2771
 
class NotATerminal(BzrError):
2772
 
 
2773
 
    _fmt = 'Unable to ask for a password without real terminal.'
 
2958
    pass
2774
2959
 
2775
2960
 
2776
2961
class UnableEncodePath(BzrError):
2779
2964
            'user encoding %(user_encoding)s')
2780
2965
 
2781
2966
    def __init__(self, path, kind):
 
2967
        from bzrlib.osutils import get_user_encoding
2782
2968
        self.path = path
2783
2969
        self.kind = kind
2784
2970
        self.user_encoding = osutils.get_user_encoding()
2785
2971
 
2786
2972
 
 
2973
class NoSuchConfig(BzrError):
 
2974
 
 
2975
    _fmt = ('The "%(config_id)s" configuration does not exist.')
 
2976
 
 
2977
    def __init__(self, config_id):
 
2978
        BzrError.__init__(self, config_id=config_id)
 
2979
 
 
2980
 
 
2981
class NoSuchConfigOption(BzrError):
 
2982
 
 
2983
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
 
2984
 
 
2985
    def __init__(self, option_name):
 
2986
        BzrError.__init__(self, option_name=option_name)
 
2987
 
 
2988
 
2787
2989
class NoSuchAlias(BzrError):
2788
2990
 
2789
2991
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2819
3021
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2820
3022
 
2821
3023
    def __init__(self, host, port, orig_error):
 
3024
        # nb: in python2.4 socket.error doesn't have a useful repr
2822
3025
        BzrError.__init__(self, host=host, port=port,
2823
 
            orig_error=orig_error[1])
 
3026
            orig_error=repr(orig_error.args))
2824
3027
 
2825
3028
 
2826
3029
class UnknownRules(BzrError):
2834
3037
class HookFailed(BzrError):
2835
3038
    """Raised when a pre_change_branch_tip hook function fails anything other
2836
3039
    than TipChangeRejected.
 
3040
 
 
3041
    Note that this exception is no longer raised, and the import is only left
 
3042
    to be nice to code which might catch it in a plugin.
2837
3043
    """
2838
3044
 
2839
3045
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2840
3046
            "%(traceback_text)s%(exc_value)s")
2841
3047
 
2842
 
    def __init__(self, hook_stage, hook_name, exc_info):
 
3048
    def __init__(self, hook_stage, hook_name, exc_info, warn=True):
 
3049
        if warn:
 
3050
            symbol_versioning.warn("BzrError HookFailed has been deprecated "
 
3051
                "as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
2843
3052
        import traceback
2844
3053
        self.hook_stage = hook_stage
2845
3054
        self.hook_name = hook_name
2854
3063
    """A pre_change_branch_tip hook function may raise this to cleanly and
2855
3064
    explicitly abort a change to a branch tip.
2856
3065
    """
2857
 
    
 
3066
 
2858
3067
    _fmt = u"Tip change rejected: %(msg)s"
2859
3068
 
2860
3069
    def __init__(self, msg):
2861
3070
        self.msg = msg
2862
3071
 
 
3072
 
 
3073
class ShelfCorrupt(BzrError):
 
3074
 
 
3075
    _fmt = "Shelf corrupt."
 
3076
 
 
3077
 
 
3078
class NoSuchShelfId(BzrError):
 
3079
 
 
3080
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
 
3081
 
 
3082
    def __init__(self, shelf_id):
 
3083
        BzrError.__init__(self, shelf_id=shelf_id)
 
3084
 
 
3085
 
 
3086
class InvalidShelfId(BzrError):
 
3087
 
 
3088
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
 
3089
 
 
3090
    def __init__(self, invalid_id):
 
3091
        BzrError.__init__(self, invalid_id=invalid_id)
 
3092
 
 
3093
 
 
3094
class JailBreak(BzrError):
 
3095
 
 
3096
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
 
3097
 
 
3098
    def __init__(self, url):
 
3099
        BzrError.__init__(self, url=url)
 
3100
 
 
3101
 
 
3102
class UserAbort(BzrError):
 
3103
 
 
3104
    _fmt = 'The user aborted the operation.'
 
3105
 
 
3106
 
 
3107
class MustHaveWorkingTree(BzrError):
 
3108
 
 
3109
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
 
3110
 
 
3111
    def __init__(self, format, url):
 
3112
        BzrError.__init__(self, format=format, url=url)
 
3113
 
 
3114
 
 
3115
class NoSuchView(BzrError):
 
3116
    """A view does not exist.
 
3117
    """
 
3118
 
 
3119
    _fmt = u"No such view: %(view_name)s."
 
3120
 
 
3121
    def __init__(self, view_name):
 
3122
        self.view_name = view_name
 
3123
 
 
3124
 
 
3125
class ViewsNotSupported(BzrError):
 
3126
    """Views are not supported by a tree format.
 
3127
    """
 
3128
 
 
3129
    _fmt = ("Views are not supported by %(tree)s;"
 
3130
            " use 'bzr upgrade' to change your tree to a later format.")
 
3131
 
 
3132
    def __init__(self, tree):
 
3133
        self.tree = tree
 
3134
 
 
3135
 
 
3136
class FileOutsideView(BzrError):
 
3137
 
 
3138
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
3139
            '%(view_str)s')
 
3140
 
 
3141
    def __init__(self, file_name, view_files):
 
3142
        self.file_name = file_name
 
3143
        self.view_str = ", ".join(view_files)
 
3144
 
 
3145
 
 
3146
class UnresumableWriteGroup(BzrError):
 
3147
 
 
3148
    _fmt = ("Repository %(repository)s cannot resume write group "
 
3149
            "%(write_groups)r: %(reason)s")
 
3150
 
 
3151
    internal_error = True
 
3152
 
 
3153
    def __init__(self, repository, write_groups, reason):
 
3154
        self.repository = repository
 
3155
        self.write_groups = write_groups
 
3156
        self.reason = reason
 
3157
 
 
3158
 
 
3159
class UnsuspendableWriteGroup(BzrError):
 
3160
 
 
3161
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
 
3162
 
 
3163
    internal_error = True
 
3164
 
 
3165
    def __init__(self, repository):
 
3166
        self.repository = repository
 
3167
 
 
3168
 
 
3169
class LossyPushToSameVCS(BzrError):
 
3170
 
 
3171
    _fmt = ("Lossy push not possible between %(source_branch)r and "
 
3172
            "%(target_branch)r that are in the same VCS.")
 
3173
 
 
3174
    internal_error = True
 
3175
 
 
3176
    def __init__(self, source_branch, target_branch):
 
3177
        self.source_branch = source_branch
 
3178
        self.target_branch = target_branch
 
3179
 
 
3180
 
 
3181
class NoRoundtrippingSupport(BzrError):
 
3182
 
 
3183
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
 
3184
            "%(target_branch)r.")
 
3185
 
 
3186
    internal_error = True
 
3187
 
 
3188
    def __init__(self, source_branch, target_branch):
 
3189
        self.source_branch = source_branch
 
3190
        self.target_branch = target_branch
 
3191
 
 
3192
 
 
3193
class FileTimestampUnavailable(BzrError):
 
3194
 
 
3195
    _fmt = "The filestamp for %(path)s is not available."
 
3196
 
 
3197
    internal_error = True
 
3198
 
 
3199
    def __init__(self, path):
 
3200
        self.path = path
 
3201
 
 
3202
 
 
3203
class NoColocatedBranchSupport(BzrError):
 
3204
 
 
3205
    _fmt = ("%(bzrdir)r does not support co-located branches.")
 
3206
 
 
3207
    def __init__(self, bzrdir):
 
3208
        self.bzrdir = bzrdir
 
3209
 
 
3210
 
 
3211
class NoWhoami(BzrError):
 
3212
 
 
3213
    _fmt = ('Unable to determine your name.\n'
 
3214
        "Please, set your name with the 'whoami' command.\n"
 
3215
        'E.g. bzr whoami "Your Name <name@example.com>"')
 
3216
 
 
3217
 
 
3218
class InvalidPattern(BzrError):
 
3219
 
 
3220
    _fmt = ('Invalid pattern(s) found. %(msg)s')
 
3221
 
 
3222
    def __init__(self, msg):
 
3223
        self.msg = msg
 
3224
 
 
3225
 
 
3226
class RecursiveBind(BzrError):
 
3227
 
 
3228
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
 
3229
        'Please use `bzr unbind` to fix.')
 
3230
 
 
3231
    def __init__(self, branch_url):
 
3232
        self.branch_url = branch_url
 
3233
 
 
3234
 
 
3235
# FIXME: I would prefer to define the config related exception classes in
 
3236
# config.py but the lazy import mechanism proscribes this -- vila 20101222
 
3237
class OptionExpansionLoop(BzrError):
 
3238
 
 
3239
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
 
3240
 
 
3241
    def __init__(self, string, refs):
 
3242
        self.string = string
 
3243
        self.refs = '->'.join(refs)
 
3244
 
 
3245
 
 
3246
class ExpandingUnknownOption(BzrError):
 
3247
 
 
3248
    _fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
 
3249
 
 
3250
    def __init__(self, name, string):
 
3251
        self.name = name
 
3252
        self.string = string
 
3253
 
 
3254
 
 
3255
class NoCompatibleInter(BzrError):
 
3256
 
 
3257
    _fmt = ('No compatible object available for operations from %(source)r '
 
3258
            'to %(target)r.')
 
3259
 
 
3260
    def __init__(self, source, target):
 
3261
        self.source = source
 
3262
        self.target = target