/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: John Arbash Meinel
  • Date: 2008-05-16 21:00:25 UTC
  • mfrom: (3418.6.5 1.5)
  • mto: This revision was merged to the branch mainline in revision 3430.
  • Revision ID: john@arbash-meinel.com-20080516210025-42cfvhivu30yq32k
Merge in bzr-1.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 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
 
61
62
    :cvar _fmt: Format string to display the error; this is expanded
62
63
    by the instance's dict.
63
64
    """
64
 
 
 
65
    
65
66
    internal_error = False
66
67
 
67
68
    def __init__(self, msg=None, **kwds):
72
73
        arguments can be given.  The first is for generic "user" errors which
73
74
        are not intended to be caught and so do not need a specific subclass.
74
75
        The second case is for use with subclasses that provide a _fmt format
75
 
        string to print the arguments.
 
76
        string to print the arguments.  
76
77
 
77
 
        Keyword arguments are taken as parameters to the error, which can
78
 
        be inserted into the format string template.  It's recommended
79
 
        that subclasses override the __init__ method to require specific
 
78
        Keyword arguments are taken as parameters to the error, which can 
 
79
        be inserted into the format string template.  It's recommended 
 
80
        that subclasses override the __init__ method to require specific 
80
81
        parameters.
81
82
 
82
83
        :param msg: If given, this is the literal complete text for the error,
83
 
           not subject to expansion. 'msg' is used instead of 'message' because
84
 
           python evolved and, in 2.6, forbids the use of 'message'.
 
84
        not subject to expansion.
85
85
        """
86
86
        StandardError.__init__(self)
87
87
        if msg is not None:
93
93
            for key, value in kwds.items():
94
94
                setattr(self, key, value)
95
95
 
96
 
    def _format(self):
 
96
    def __str__(self):
97
97
        s = getattr(self, '_preformatted_string', None)
98
98
        if s is not None:
99
 
            # contains a preformatted message
100
 
            return s
 
99
            # contains a preformatted message; must be cast to plain str
 
100
            return str(s)
101
101
        try:
102
102
            fmt = self._get_format_string()
103
103
            if fmt:
104
104
                d = dict(self.__dict__)
 
105
                # special case: python2.5 puts the 'message' attribute in a
 
106
                # slot, so it isn't seen in __dict__
 
107
                d['message'] = getattr(self, 'message', 'no message')
105
108
                s = fmt % d
106
109
                # __str__() should always return a 'str' object
107
110
                # never a 'unicode' object.
 
111
                if isinstance(s, unicode):
 
112
                    return s.encode('utf8')
108
113
                return s
109
114
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
110
115
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
113
118
                   getattr(self, '_fmt', None),
114
119
                   e)
115
120
 
116
 
    def __unicode__(self):
117
 
        u = self._format()
118
 
        if isinstance(u, str):
119
 
            # Try decoding the str using the default encoding.
120
 
            u = unicode(u)
121
 
        elif not isinstance(u, unicode):
122
 
            # Try to make a unicode object from it, because __unicode__ must
123
 
            # return a unicode object.
124
 
            u = unicode(u)
125
 
        return u
126
 
 
127
 
    def __str__(self):
128
 
        s = self._format()
129
 
        if isinstance(s, unicode):
130
 
            s = s.encode('utf8')
131
 
        else:
132
 
            # __str__ must return a str.
133
 
            s = str(s)
134
 
        return s
135
 
 
136
 
    def __repr__(self):
137
 
        return '%s(%s)' % (self.__class__.__name__, str(self))
138
 
 
139
121
    def _get_format_string(self):
140
122
        """Return format string for this exception or None"""
141
123
        fmt = getattr(self, '_fmt', None)
153
135
               getattr(self, '_fmt', None),
154
136
               )
155
137
 
156
 
    def __eq__(self, other):
157
 
        if self.__class__ is not other.__class__:
158
 
            return NotImplemented
159
 
        return self.__dict__ == other.__dict__
160
 
 
161
138
 
162
139
class InternalBzrError(BzrError):
163
140
    """Base class for errors that are internal in nature.
204
181
 
205
182
 
206
183
class AlreadyBuilding(BzrError):
207
 
 
 
184
    
208
185
    _fmt = "The tree builder is already building a tree."
209
186
 
210
187
 
216
193
 
217
194
 
218
195
class BzrCheckError(InternalBzrError):
219
 
 
220
 
    _fmt = "Internal check failed: %(msg)s"
221
 
 
222
 
    def __init__(self, msg):
223
 
        BzrError.__init__(self)
224
 
        self.msg = msg
225
 
 
226
 
 
227
 
class DirstateCorrupt(BzrError):
228
 
 
229
 
    _fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
230
 
 
231
 
    def __init__(self, state, msg):
232
 
        BzrError.__init__(self)
233
 
        self.state = state
234
 
        self.msg = msg
 
196
    
 
197
    _fmt = "Internal check failed: %(message)s"
 
198
 
 
199
    def __init__(self, message):
 
200
        BzrError.__init__(self)
 
201
        self.message = message
235
202
 
236
203
 
237
204
class DisabledMethod(InternalBzrError):
265
232
 
266
233
 
267
234
class InvalidEntryName(InternalBzrError):
268
 
 
 
235
    
269
236
    _fmt = "Invalid entry name: %(name)s"
270
237
 
271
238
    def __init__(self, name):
274
241
 
275
242
 
276
243
class InvalidRevisionNumber(BzrError):
277
 
 
 
244
    
278
245
    _fmt = "Invalid revision number %(revno)s"
279
246
 
280
247
    def __init__(self, revno):
329
296
class NoSuchId(BzrError):
330
297
 
331
298
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
332
 
 
 
299
    
333
300
    def __init__(self, tree, file_id):
334
301
        BzrError.__init__(self)
335
302
        self.file_id = file_id
362
329
class NoWorkingTree(BzrError):
363
330
 
364
331
    _fmt = 'No WorkingTree exists for "%(base)s".'
365
 
 
 
332
    
366
333
    def __init__(self, base):
367
334
        BzrError.__init__(self)
368
335
        self.base = base
399
366
    # are not intended to be caught anyway.  UI code need not subclass
400
367
    # BzrCommandError, and non-UI code should not throw a subclass of
401
368
    # BzrCommandError.  ADHB 20051211
 
369
    def __init__(self, msg):
 
370
        # Object.__str__() must return a real string
 
371
        # returning a Unicode string is a python error.
 
372
        if isinstance(msg, unicode):
 
373
            self.msg = msg.encode('utf8')
 
374
        else:
 
375
            self.msg = msg
 
376
 
 
377
    def __str__(self):
 
378
        return self.msg
402
379
 
403
380
 
404
381
class NotWriteLocked(BzrError):
477
454
    def __init__(self, name, value):
478
455
        BzrError.__init__(self, name=name, value=value)
479
456
 
480
 
 
 
457
    
481
458
class StrictCommitFailed(BzrError):
482
459
 
483
460
    _fmt = "Commit refused because there are unknown files in the tree"
486
463
# XXX: Should be unified with TransportError; they seem to represent the
487
464
# same thing
488
465
# 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
 
466
# - this is finer than a TransportError - and more useful as such. It 
490
467
# differentiates between 'transport has failed' and 'operation on a transport
491
468
# has failed.'
492
469
class PathError(BzrError):
493
 
 
 
470
    
494
471
    _fmt = "Generic path error: %(path)r%(extra)s)"
495
472
 
496
473
    def __init__(self, path, extra=None):
550
527
 
551
528
 
552
529
class ReadingCompleted(InternalBzrError):
553
 
 
 
530
    
554
531
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
555
532
            "called upon it - the request has been completed and no more "
556
533
            "data may be read.")
585
562
        PathError.__init__(self, base, reason)
586
563
 
587
564
 
588
 
class InvalidRebaseURLs(PathError):
589
 
 
590
 
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
591
 
 
592
 
    def __init__(self, from_, to):
593
 
        self.from_ = from_
594
 
        self.to = to
595
 
        PathError.__init__(self, from_, 'URLs differ by more than path.')
596
 
 
597
 
 
598
565
class UnavailableRepresentation(InternalBzrError):
599
566
 
600
567
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
636
603
        self.url = url
637
604
 
638
605
 
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
606
class UnstackableRepositoryFormat(BzrError):
650
607
 
651
608
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
658
615
 
659
616
 
660
617
class ReadError(PathError):
661
 
 
 
618
    
662
619
    _fmt = """Error reading from %(path)r."""
663
620
 
664
621
 
699
656
 
700
657
# TODO: This is given a URL; we try to unescape it but doing that from inside
701
658
# the exception object is a bit undesirable.
702
 
# TODO: Probably this behavior of should be a common superclass
 
659
# TODO: Probably this behavior of should be a common superclass 
703
660
class NotBranchError(PathError):
704
661
 
705
 
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
 
662
    _fmt = 'Not a branch: "%(path)s".'
706
663
 
707
 
    def __init__(self, path, detail=None, bzrdir=None):
 
664
    def __init__(self, path):
708
665
       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 _format(self):
717
 
        # XXX: Ideally self.detail would be a property, but Exceptions in
718
 
        # Python 2.4 have to be old-style classes so properties don't work.
719
 
        # Instead we override _format.
720
 
        if self.detail is None:
721
 
            if self.bzrdir is not None:
722
 
                try:
723
 
                    self.bzrdir.open_repository()
724
 
                except NoRepositoryPresent:
725
 
                    self.detail = ''
726
 
                else:
727
 
                    self.detail = ': location is a repository'
728
 
            else:
729
 
                self.detail = ''
730
 
        return PathError._format(self)
 
666
       self.path = urlutils.unescape_for_display(path, 'ascii')
731
667
 
732
668
 
733
669
class NoSubmitBranch(PathError):
795
731
 
796
732
 
797
733
class UnknownFormatError(BzrError):
798
 
 
 
734
    
799
735
    _fmt = "Unknown %(kind)s format: %(format)r"
800
736
 
801
737
    def __init__(self, format, kind='branch'):
804
740
 
805
741
 
806
742
class IncompatibleFormat(BzrError):
807
 
 
 
743
    
808
744
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
809
745
 
810
746
    def __init__(self, format, bzrdir_format):
814
750
 
815
751
 
816
752
class IncompatibleRepositories(BzrError):
817
 
    """Report an error that two repositories are not compatible.
818
 
 
819
 
    Note that the source and target repositories are permitted to be strings:
820
 
    this exception is thrown from the smart server and may refer to a
821
 
    repository the client hasn't opened.
822
 
    """
823
 
 
824
 
    _fmt = "%(target)s\n" \
825
 
            "is not compatible with\n" \
826
 
            "%(source)s\n" \
827
 
            "%(details)s"
828
 
 
829
 
    def __init__(self, source, target, details=None):
830
 
        if details is None:
831
 
            details = "(no details)"
832
 
        BzrError.__init__(self, target=target, source=source, details=details)
 
753
 
 
754
    _fmt = "Repository %(target)s is not compatible with repository"\
 
755
        " %(source)s"
 
756
 
 
757
    def __init__(self, source, target):
 
758
        BzrError.__init__(self, target=target, source=source)
833
759
 
834
760
 
835
761
class IncompatibleRevision(BzrError):
836
 
 
 
762
    
837
763
    _fmt = "Revision is not compatible with %(repo_format)s"
838
764
 
839
765
    def __init__(self, repo_format):
922
848
        BzrError.__init__(self, filename=filename, kind=kind)
923
849
 
924
850
 
925
 
class BadFilenameEncoding(BzrError):
926
 
 
927
 
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
928
 
            ' encoding %(fs_encoding)s')
929
 
 
930
 
    def __init__(self, filename, fs_encoding):
931
 
        BzrError.__init__(self)
932
 
        self.filename = filename
933
 
        self.fs_encoding = fs_encoding
934
 
 
935
 
 
936
851
class ForbiddenControlFileError(BzrError):
937
852
 
938
853
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
947
862
    # original exception is available as e.original_error
948
863
    #
949
864
    # New code should prefer to raise specific subclasses
950
 
    def __init__(self, msg):
951
 
        self.msg = msg
 
865
    def __init__(self, message):
 
866
        # Python 2.5 uses a slot for StandardError.message,
 
867
        # so use a different variable name.  We now work around this in
 
868
        # BzrError.__str__, but this member name is kept for compatability.
 
869
        self.msg = message
952
870
 
953
871
 
954
872
class LockActive(LockError):
1037
955
 
1038
956
class LockContention(LockError):
1039
957
 
1040
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
 
958
    _fmt = 'Could not acquire lock "%(lock)s"'
 
959
    # TODO: show full url for lock, combining the transport and relative
 
960
    # bits?
1041
961
 
1042
962
    internal_error = False
1043
963
 
1044
 
    def __init__(self, lock, msg=''):
 
964
    def __init__(self, lock):
1045
965
        self.lock = lock
1046
 
        self.msg = msg
1047
966
 
1048
967
 
1049
968
class LockBroken(LockError):
1163
1082
 
1164
1083
class NoSuchRevisionInTree(NoSuchRevision):
1165
1084
    """When using Tree.revision_tree, and the revision is not accessible."""
1166
 
 
 
1085
    
1167
1086
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1168
1087
 
1169
1088
    def __init__(self, tree, revision_id):
1174
1093
 
1175
1094
class InvalidRevisionSpec(BzrError):
1176
1095
 
1177
 
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
 
1096
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
1178
1097
            " %(branch)s%(extra)s")
1179
1098
 
1180
1099
    def __init__(self, spec, branch, extra=None):
1205
1124
class DivergedBranches(BzrError):
1206
1125
 
1207
1126
    _fmt = ("These branches have diverged."
1208
 
            " Use the missing command to see how.\n"
1209
 
            "Use the merge command to reconcile them.")
 
1127
            " Use the merge command to reconcile them.")
1210
1128
 
1211
1129
    def __init__(self, branch1, branch2):
1212
1130
        self.branch1 = branch1
1234
1152
 
1235
1153
 
1236
1154
class NoCommonAncestor(BzrError):
1237
 
 
 
1155
    
1238
1156
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1239
1157
 
1240
1158
    def __init__(self, revision_a, revision_b):
1260
1178
            not_ancestor_id=not_ancestor_id)
1261
1179
 
1262
1180
 
 
1181
class InstallFailed(BzrError):
 
1182
 
 
1183
    def __init__(self, revisions):
 
1184
        revision_str = ", ".join(str(r) for r in revisions)
 
1185
        msg = "Could not install revisions:\n%s" % revision_str
 
1186
        BzrError.__init__(self, msg)
 
1187
        self.revisions = revisions
 
1188
 
 
1189
 
1263
1190
class AmbiguousBase(BzrError):
1264
1191
 
1265
1192
    def __init__(self, bases):
1266
 
        symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
1267
 
            "as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
 
1193
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
1194
                DeprecationWarning)
1268
1195
        msg = ("The correct base is unclear, because %s are all equally close"
1269
1196
                % ", ".join(bases))
1270
1197
        BzrError.__init__(self, msg)
1292
1219
class BoundBranchOutOfDate(BzrError):
1293
1220
 
1294
1221
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1295
 
            " %(master)s.%(extra_help)s")
 
1222
            " %(master)s.")
1296
1223
 
1297
1224
    def __init__(self, branch, master):
1298
1225
        BzrError.__init__(self)
1299
1226
        self.branch = branch
1300
1227
        self.master = master
1301
 
        self.extra_help = ''
1302
 
 
1303
 
 
 
1228
 
 
1229
        
1304
1230
class CommitToDoubleBoundBranch(BzrError):
1305
1231
 
1306
1232
    _fmt = ("Cannot commit to branch %(branch)s."
1336
1262
 
1337
1263
class WeaveError(BzrError):
1338
1264
 
1339
 
    _fmt = "Error in processing weave: %(msg)s"
 
1265
    _fmt = "Error in processing weave: %(message)s"
1340
1266
 
1341
 
    def __init__(self, msg=None):
 
1267
    def __init__(self, message=None):
1342
1268
        BzrError.__init__(self)
1343
 
        self.msg = msg
 
1269
        self.message = message
1344
1270
 
1345
1271
 
1346
1272
class WeaveRevisionAlreadyPresent(WeaveError):
1375
1301
 
1376
1302
class WeaveParentMismatch(WeaveError):
1377
1303
 
1378
 
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
1379
 
 
 
1304
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
1305
    
1380
1306
 
1381
1307
class WeaveInvalidChecksum(WeaveError):
1382
1308
 
1383
 
    _fmt = "Text did not match it's checksum: %(msg)s"
 
1309
    _fmt = "Text did not match it's checksum: %(message)s"
1384
1310
 
1385
1311
 
1386
1312
class WeaveTextDiffers(WeaveError):
1408
1334
 
1409
1335
 
1410
1336
class VersionedFileError(BzrError):
1411
 
 
 
1337
    
1412
1338
    _fmt = "Versioned file error"
1413
1339
 
1414
1340
 
1415
1341
class RevisionNotPresent(VersionedFileError):
1416
 
 
 
1342
    
1417
1343
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1418
1344
 
1419
1345
    def __init__(self, revision_id, file_id):
1423
1349
 
1424
1350
 
1425
1351
class RevisionAlreadyPresent(VersionedFileError):
1426
 
 
 
1352
    
1427
1353
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1428
1354
 
1429
1355
    def __init__(self, revision_id, file_id):
1434
1360
 
1435
1361
class VersionedFileInvalidChecksum(VersionedFileError):
1436
1362
 
1437
 
    _fmt = "Text did not match its checksum: %(msg)s"
 
1363
    _fmt = "Text did not match its checksum: %(message)s"
1438
1364
 
1439
1365
 
1440
1366
class KnitError(InternalBzrError):
1441
 
 
 
1367
    
1442
1368
    _fmt = "Knit error"
1443
1369
 
1444
1370
 
1452
1378
        self.how = how
1453
1379
 
1454
1380
 
1455
 
class SHA1KnitCorrupt(KnitCorrupt):
1456
 
 
1457
 
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
1458
 
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
1459
 
        "sha %(actual)s")
1460
 
 
1461
 
    def __init__(self, filename, actual, expected, key, content):
1462
 
        KnitError.__init__(self)
1463
 
        self.filename = filename
1464
 
        self.actual = actual
1465
 
        self.expected = expected
1466
 
        self.key = key
1467
 
        self.content = content
1468
 
 
1469
 
 
1470
1381
class KnitDataStreamIncompatible(KnitError):
1471
1382
    # Not raised anymore, as we can convert data streams.  In future we may
1472
1383
    # need it again for more exotic cases, so we're keeping it around for now.
1476
1387
    def __init__(self, stream_format, target_format):
1477
1388
        self.stream_format = stream_format
1478
1389
        self.target_format = target_format
1479
 
 
 
1390
        
1480
1391
 
1481
1392
class KnitDataStreamUnknown(KnitError):
1482
1393
    # Indicates a data stream we don't know how to handle.
1485
1396
 
1486
1397
    def __init__(self, stream_format):
1487
1398
        self.stream_format = stream_format
1488
 
 
 
1399
        
1489
1400
 
1490
1401
class KnitHeaderError(KnitError):
1491
1402
 
1501
1412
 
1502
1413
    Currently only 'fulltext' and 'line-delta' are supported.
1503
1414
    """
1504
 
 
 
1415
    
1505
1416
    _fmt = ("Knit index %(filename)s does not have a known method"
1506
1417
            " in options: %(options)r")
1507
1418
 
1511
1422
        self.options = options
1512
1423
 
1513
1424
 
1514
 
class RetryWithNewPacks(BzrError):
1515
 
    """Raised when we realize that the packs on disk have changed.
1516
 
 
1517
 
    This is meant as more of a signaling exception, to trap between where a
1518
 
    local error occurred and the code that can actually handle the error and
1519
 
    code that can retry appropriately.
1520
 
    """
1521
 
 
1522
 
    internal_error = True
1523
 
 
1524
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1525
 
            " %(orig_error)s")
1526
 
 
1527
 
    def __init__(self, context, reload_occurred, exc_info):
1528
 
        """create a new RetryWithNewPacks error.
1529
 
 
1530
 
        :param reload_occurred: Set to True if we know that the packs have
1531
 
            already been reloaded, and we are failing because of an in-memory
1532
 
            cache miss. If set to True then we will ignore if a reload says
1533
 
            nothing has changed, because we assume it has already reloaded. If
1534
 
            False, then a reload with nothing changed will force an error.
1535
 
        :param exc_info: The original exception traceback, so if there is a
1536
 
            problem we can raise the original error (value from sys.exc_info())
1537
 
        """
1538
 
        BzrError.__init__(self)
1539
 
        self.reload_occurred = reload_occurred
1540
 
        self.exc_info = exc_info
1541
 
        self.orig_error = exc_info[1]
1542
 
        # TODO: The global error handler should probably treat this by
1543
 
        #       raising/printing the original exception with a bit about
1544
 
        #       RetryWithNewPacks also not being caught
1545
 
 
1546
 
 
1547
 
class RetryAutopack(RetryWithNewPacks):
1548
 
    """Raised when we are autopacking and we find a missing file.
1549
 
 
1550
 
    Meant as a signaling exception, to tell the autopack code it should try
1551
 
    again.
1552
 
    """
1553
 
 
1554
 
    internal_error = True
1555
 
 
1556
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1557
 
            " context: %(context)s %(orig_error)s")
1558
 
 
1559
 
 
1560
1425
class NoSuchExportFormat(BzrError):
1561
 
 
 
1426
    
1562
1427
    _fmt = "Export format %(format)r not supported"
1563
1428
 
1564
1429
    def __init__(self, format):
1567
1432
 
1568
1433
 
1569
1434
class TransportError(BzrError):
1570
 
 
 
1435
    
1571
1436
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1572
1437
 
1573
1438
    def __init__(self, msg=None, orig_error=None):
1600
1465
        self.details = details
1601
1466
 
1602
1467
 
1603
 
class UnexpectedProtocolVersionMarker(TransportError):
1604
 
 
1605
 
    _fmt = "Received bad protocol version marker: %(marker)r"
1606
 
 
1607
 
    def __init__(self, marker):
1608
 
        self.marker = marker
1609
 
 
1610
 
 
1611
1468
class UnknownSmartMethod(InternalBzrError):
1612
1469
 
1613
1470
    _fmt = "The server does not recognise the '%(verb)s' request."
1616
1473
        self.verb = verb
1617
1474
 
1618
1475
 
1619
 
class SmartMessageHandlerError(InternalBzrError):
1620
 
 
1621
 
    _fmt = ("The message handler raised an exception:\n"
1622
 
            "%(traceback_text)s")
1623
 
 
1624
 
    def __init__(self, exc_info):
1625
 
        import traceback
1626
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1627
 
        self.exc_info = exc_info
1628
 
        traceback_strings = traceback.format_exception(
1629
 
                self.exc_type, self.exc_value, self.exc_tb)
1630
 
        self.traceback_text = ''.join(traceback_strings)
1631
 
 
1632
 
 
1633
1476
# A set of semi-meaningful errors which can be thrown
1634
1477
class TransportNotPossible(TransportError):
1635
1478
 
1660
1503
            self.port = ':%s' % port
1661
1504
 
1662
1505
 
1663
 
# XXX: This is also used for unexpected end of file, which is different at the
1664
 
# TCP level from "connection reset".
1665
1506
class ConnectionReset(TransportError):
1666
1507
 
1667
1508
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1708
1549
 
1709
1550
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1710
1551
 
1711
 
    def __init__(self, source, target, is_permanent=False):
 
1552
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
1712
1553
        self.source = source
1713
1554
        self.target = target
1714
1555
        if is_permanent:
1715
1556
            self.permanently = ' permanently'
1716
1557
        else:
1717
1558
            self.permanently = ''
 
1559
        self._qualified_proto = qual_proto
1718
1560
        TransportError.__init__(self)
1719
1561
 
 
1562
    def _requalify_url(self, url):
 
1563
        """Restore the qualified proto in front of the url"""
 
1564
        # When this exception is raised, source and target are in
 
1565
        # user readable format. But some transports may use a
 
1566
        # different proto (http+urllib:// will present http:// to
 
1567
        # the user. If a qualified proto is specified, the code
 
1568
        # trapping the exception can get the qualified urls to
 
1569
        # properly handle the redirection themself (creating a
 
1570
        # new transport object from the target url for example).
 
1571
        # But checking that the scheme of the original and
 
1572
        # redirected urls are the same can be tricky. (see the
 
1573
        # FIXME in BzrDir.open_from_transport for the unique use
 
1574
        # case so far).
 
1575
        if self._qualified_proto is None:
 
1576
            return url
 
1577
 
 
1578
        # The TODO related to NotBranchError mention that doing
 
1579
        # that kind of manipulation on the urls may not be the
 
1580
        # exception object job. On the other hand, this object is
 
1581
        # the interface between the code and the user so
 
1582
        # presenting the urls in different ways is indeed its
 
1583
        # job...
 
1584
        import urlparse
 
1585
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1586
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1587
                                   query, fragment))
 
1588
 
 
1589
    def get_source_url(self):
 
1590
        return self._requalify_url(self.source)
 
1591
 
 
1592
    def get_target_url(self):
 
1593
        return self._requalify_url(self.target)
 
1594
 
1720
1595
 
1721
1596
class TooManyRedirections(TransportError):
1722
1597
 
1734
1609
        if filename is None:
1735
1610
            filename = ""
1736
1611
        message = "Error(s) parsing config file %s:\n%s" % \
1737
 
            (filename, ('\n'.join(e.msg for e in errors)))
 
1612
            (filename, ('\n'.join(e.message for e in errors)))
1738
1613
        BzrError.__init__(self, message)
1739
1614
 
1740
1615
 
1757
1632
 
1758
1633
class WorkingTreeNotRevision(BzrError):
1759
1634
 
1760
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1635
    _fmt = ("The working tree for %(basedir)s has changed since" 
1761
1636
            " the last commit, but weave merge requires that it be"
1762
1637
            " unchanged")
1763
1638
 
1920
1795
    _fmt = "Moving the root directory is not supported at this time"
1921
1796
 
1922
1797
 
1923
 
class TransformRenameFailed(BzrError):
1924
 
 
1925
 
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
1926
 
 
1927
 
    def __init__(self, from_path, to_path, why, errno):
1928
 
        self.from_path = from_path
1929
 
        self.to_path = to_path
1930
 
        self.why = why
1931
 
        self.errno = errno
1932
 
 
1933
 
 
1934
1798
class BzrMoveFailedError(BzrError):
1935
1799
 
1936
1800
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1937
1801
 
1938
1802
    def __init__(self, from_path='', to_path='', extra=None):
1939
 
        from bzrlib.osutils import splitpath
1940
1803
        BzrError.__init__(self)
1941
1804
        if extra:
1942
1805
            self.extra = ': ' + str(extra)
1946
1809
        has_from = len(from_path) > 0
1947
1810
        has_to = len(to_path) > 0
1948
1811
        if has_from:
1949
 
            self.from_path = splitpath(from_path)[-1]
 
1812
            self.from_path = osutils.splitpath(from_path)[-1]
1950
1813
        else:
1951
1814
            self.from_path = ''
1952
1815
 
1953
1816
        if has_to:
1954
 
            self.to_path = splitpath(to_path)[-1]
 
1817
            self.to_path = osutils.splitpath(to_path)[-1]
1955
1818
        else:
1956
1819
            self.to_path = ''
1957
1820
 
2040
1903
 
2041
1904
class BadConversionTarget(BzrError):
2042
1905
 
2043
 
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
2044
 
            "    %(problem)s"
 
1906
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
2045
1907
 
2046
 
    def __init__(self, problem, format, from_format=None):
 
1908
    def __init__(self, problem, format):
2047
1909
        BzrError.__init__(self)
2048
1910
        self.problem = problem
2049
1911
        self.format = format
2050
 
        self.from_format = from_format or '(unspecified)'
2051
1912
 
2052
1913
 
2053
1914
class NoDiffFound(BzrError):
2090
1951
    _fmt = """This tree contains left-over files from a failed operation.
2091
1952
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2092
1953
    keep, and delete it when you are done."""
2093
 
 
 
1954
    
2094
1955
    def __init__(self, limbo_dir):
2095
1956
       BzrError.__init__(self)
2096
1957
       self.limbo_dir = limbo_dir
2129
1990
 
2130
1991
class OutOfDateTree(BzrError):
2131
1992
 
2132
 
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
 
1993
    _fmt = "Working tree is out of date, please run 'bzr update'."
2133
1994
 
2134
 
    def __init__(self, tree, more=None):
2135
 
        if more is None:
2136
 
            more = ''
2137
 
        else:
2138
 
            more = ' ' + more
 
1995
    def __init__(self, tree):
2139
1996
        BzrError.__init__(self)
2140
1997
        self.tree = tree
2141
 
        self.more = more
2142
1998
 
2143
1999
 
2144
2000
class PublicBranchOutOfDate(BzrError):
2182
2038
 
2183
2039
    def __init__(self, repo):
2184
2040
        BzrError.__init__(self)
2185
 
        self.repo_path = repo.user_url
 
2041
        self.repo_path = repo.bzrdir.root_transport.base
2186
2042
 
2187
2043
 
2188
2044
class InconsistentDelta(BzrError):
2198
2054
        self.reason = reason
2199
2055
 
2200
2056
 
2201
 
class InconsistentDeltaDelta(InconsistentDelta):
2202
 
    """Used when we get a delta that is not valid."""
2203
 
 
2204
 
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
2205
 
            "\nreason: %(reason)s")
2206
 
 
2207
 
    def __init__(self, delta, reason):
2208
 
        BzrError.__init__(self)
2209
 
        self.delta = delta
2210
 
        self.reason = reason
2211
 
 
2212
 
 
2213
2057
class UpgradeRequired(BzrError):
2214
2058
 
2215
2059
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2224
2068
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2225
2069
 
2226
2070
 
2227
 
class RichRootUpgradeRequired(UpgradeRequired):
2228
 
 
2229
 
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
2230
 
           " a format which supports rich roots.")
2231
 
 
2232
 
 
2233
2071
class LocalRequiresBoundBranch(BzrError):
2234
2072
 
2235
2073
    _fmt = "Cannot perform local-only commits on unbound branches."
2236
2074
 
2237
2075
 
 
2076
class MissingProgressBarFinish(BzrError):
 
2077
 
 
2078
    _fmt = "A nested progress bar was not 'finished' correctly."
 
2079
 
 
2080
 
 
2081
class InvalidProgressBarType(BzrError):
 
2082
 
 
2083
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
 
2084
            " is not a supported type Select one of: %(valid_types)s")
 
2085
 
 
2086
    def __init__(self, bar_type, valid_types):
 
2087
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
2088
 
 
2089
 
2238
2090
class UnsupportedOperation(BzrError):
2239
2091
 
2240
2092
    _fmt = ("The method %(mname)s is not supported on"
2257
2109
 
2258
2110
 
2259
2111
class BinaryFile(BzrError):
2260
 
 
 
2112
    
2261
2113
    _fmt = "File is binary but should be text."
2262
2114
 
2263
2115
 
2283
2135
 
2284
2136
 
2285
2137
class NotABundle(BzrError):
2286
 
 
 
2138
    
2287
2139
    _fmt = "Not a bzr revision-bundle: %(text)r"
2288
2140
 
2289
2141
    def __init__(self, text):
2291
2143
        self.text = text
2292
2144
 
2293
2145
 
2294
 
class BadBundle(BzrError):
2295
 
 
 
2146
class BadBundle(BzrError): 
 
2147
    
2296
2148
    _fmt = "Bad bzr revision-bundle: %(text)r"
2297
2149
 
2298
2150
    def __init__(self, text):
2300
2152
        self.text = text
2301
2153
 
2302
2154
 
2303
 
class MalformedHeader(BadBundle):
2304
 
 
 
2155
class MalformedHeader(BadBundle): 
 
2156
    
2305
2157
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2306
2158
 
2307
2159
 
2308
 
class MalformedPatches(BadBundle):
2309
 
 
 
2160
class MalformedPatches(BadBundle): 
 
2161
    
2310
2162
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2311
2163
 
2312
2164
 
2313
 
class MalformedFooter(BadBundle):
2314
 
 
 
2165
class MalformedFooter(BadBundle): 
 
2166
    
2315
2167
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2316
2168
 
2317
2169
 
2318
2170
class UnsupportedEOLMarker(BadBundle):
2319
 
 
2320
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
2171
    
 
2172
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
2321
2173
 
2322
2174
    def __init__(self):
2323
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
2175
        # XXX: BadBundle's constructor assumes there's explanatory text, 
2324
2176
        # but for this there is not
2325
2177
        BzrError.__init__(self)
2326
2178
 
2327
2179
 
2328
2180
class IncompatibleBundleFormat(BzrError):
2329
 
 
 
2181
    
2330
2182
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2331
2183
 
2332
2184
    def __init__(self, bundle_format, other):
2336
2188
 
2337
2189
 
2338
2190
class BadInventoryFormat(BzrError):
2339
 
 
 
2191
    
2340
2192
    _fmt = "Root class for inventory serialization errors"
2341
2193
 
2342
2194
 
2361
2213
        self.transport = transport
2362
2214
 
2363
2215
 
 
2216
class NoSmartServer(NotBranchError):
 
2217
 
 
2218
    _fmt = "No smart server available at %(url)s"
 
2219
 
 
2220
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
 
2221
    def __init__(self, url):
 
2222
        self.url = url
 
2223
 
 
2224
 
2364
2225
class UnknownSSH(BzrError):
2365
2226
 
2366
2227
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2376
2237
            " Please set BZR_SSH environment variable.")
2377
2238
 
2378
2239
 
2379
 
class GhostRevisionsHaveNoRevno(BzrError):
2380
 
    """When searching for revnos, if we encounter a ghost, we are stuck"""
2381
 
 
2382
 
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
2383
 
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
2384
 
 
2385
 
    def __init__(self, revision_id, ghost_revision_id):
2386
 
        self.revision_id = revision_id
2387
 
        self.ghost_revision_id = ghost_revision_id
2388
 
 
2389
 
 
2390
2240
class GhostRevisionUnusableHere(BzrError):
2391
2241
 
2392
2242
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2470
2320
        self.patch_type = patch_type
2471
2321
 
2472
2322
 
2473
 
class TargetNotBranch(BzrError):
2474
 
    """A merge directive's target branch is required, but isn't a branch"""
2475
 
 
2476
 
    _fmt = ("Your branch does not have all of the revisions required in "
2477
 
            "order to merge this merge directive and the target "
2478
 
            "location specified in the merge directive is not a branch: "
2479
 
            "%(location)s.")
2480
 
 
2481
 
    def __init__(self, location):
2482
 
        BzrError.__init__(self)
2483
 
        self.location = location
2484
 
 
2485
 
 
2486
2323
class UnsupportedInventoryKind(BzrError):
2487
 
 
 
2324
    
2488
2325
    _fmt = """Unsupported entry kind %(kind)s"""
2489
2326
 
2490
2327
    def __init__(self, kind):
2502
2339
 
2503
2340
 
2504
2341
class SubsumeTargetNeedsUpgrade(BzrError):
2505
 
 
 
2342
    
2506
2343
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2507
2344
 
2508
2345
    def __init__(self, other_tree):
2531
2368
class TagsNotSupported(BzrError):
2532
2369
 
2533
2370
    _fmt = ("Tags not supported by %(branch)s;"
2534
 
            " you may be able to use bzr upgrade.")
 
2371
            " you may be able to use bzr upgrade --dirstate-tags.")
2535
2372
 
2536
2373
    def __init__(self, branch):
2537
2374
        self.branch = branch
2538
2375
 
2539
 
 
 
2376
        
2540
2377
class TagAlreadyExists(BzrError):
2541
2378
 
2542
2379
    _fmt = "Tag %(tag_name)s already exists."
2547
2384
 
2548
2385
class MalformedBugIdentifier(BzrError):
2549
2386
 
2550
 
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
2551
 
            'See "bzr help bugs" for more information on this feature.')
 
2387
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2552
2388
 
2553
2389
    def __init__(self, bug_id, reason):
2554
2390
        self.bug_id = bug_id
2575
2411
        self.branch = branch
2576
2412
 
2577
2413
 
2578
 
class InvalidLineInBugsProperty(BzrError):
2579
 
 
2580
 
    _fmt = ("Invalid line in bugs property: '%(line)s'")
2581
 
 
2582
 
    def __init__(self, line):
2583
 
        self.line = line
2584
 
 
2585
 
 
2586
 
class InvalidBugStatus(BzrError):
2587
 
 
2588
 
    _fmt = ("Invalid bug status: '%(status)s'")
2589
 
 
2590
 
    def __init__(self, status):
2591
 
        self.status = status
2592
 
 
2593
 
 
2594
2414
class UnexpectedSmartServerResponse(BzrError):
2595
2415
 
2596
2416
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2599
2419
        self.response_tuple = response_tuple
2600
2420
 
2601
2421
 
2602
 
class ErrorFromSmartServer(BzrError):
2603
 
    """An error was received from a smart server.
2604
 
 
2605
 
    :seealso: UnknownErrorFromSmartServer
2606
 
    """
2607
 
 
2608
 
    _fmt = "Error received from smart server: %(error_tuple)r"
2609
 
 
2610
 
    internal_error = True
2611
 
 
2612
 
    def __init__(self, error_tuple):
2613
 
        self.error_tuple = error_tuple
2614
 
        try:
2615
 
            self.error_verb = error_tuple[0]
2616
 
        except IndexError:
2617
 
            self.error_verb = None
2618
 
        self.error_args = error_tuple[1:]
2619
 
 
2620
 
 
2621
 
class UnknownErrorFromSmartServer(BzrError):
2622
 
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
2623
 
    error.
2624
 
 
2625
 
    This is distinct from ErrorFromSmartServer so that it is possible to
2626
 
    distinguish between the following two cases:
2627
 
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
2628
 
        and so should provoke a traceback to the user.
2629
 
      - ErrorFromSmartServer was caught but its error_tuple could not be
2630
 
        translated.  This is probably because the server sent us garbage, and
2631
 
        should not provoke a traceback.
2632
 
    """
2633
 
 
2634
 
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2635
 
 
2636
 
    internal_error = False
2637
 
 
2638
 
    def __init__(self, error_from_smart_server):
2639
 
        """Constructor.
2640
 
 
2641
 
        :param error_from_smart_server: An ErrorFromSmartServer instance.
2642
 
        """
2643
 
        self.error_from_smart_server = error_from_smart_server
2644
 
        self.error_tuple = error_from_smart_server.error_tuple
2645
 
 
2646
 
 
2647
2422
class ContainerError(BzrError):
2648
2423
    """Base class of container errors."""
2649
2424
 
2651
2426
class UnknownContainerFormatError(ContainerError):
2652
2427
 
2653
2428
    _fmt = "Unrecognised container format: %(container_format)r"
2654
 
 
 
2429
    
2655
2430
    def __init__(self, container_format):
2656
2431
        self.container_format = container_format
2657
2432
 
2721
2496
 
2722
2497
class NoMailAddressSpecified(BzrError):
2723
2498
 
2724
 
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
 
2499
    _fmt = "No mail-to address specified."
2725
2500
 
2726
2501
 
2727
2502
class UnknownMailClient(BzrError):
2760
2535
 
2761
2536
    def __init__(self, bzrdir):
2762
2537
        import bzrlib.urlutils as urlutils
2763
 
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
 
2538
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
2764
2539
                                                    'ascii')
2765
2540
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2766
2541
 
2807
2582
    _fmt = "'%(display_url)s' is already standalone."
2808
2583
 
2809
2584
 
2810
 
class AlreadyWithTrees(BzrDirError):
2811
 
 
2812
 
    _fmt = ("Shared repository '%(display_url)s' already creates "
2813
 
            "working trees.")
2814
 
 
2815
 
 
2816
 
class AlreadyWithNoTrees(BzrDirError):
2817
 
 
2818
 
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
2819
 
            "working trees.")
2820
 
 
2821
 
 
2822
2585
class ReconfigurationNotSupported(BzrDirError):
2823
2586
 
2824
2587
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2831
2594
 
2832
2595
class UncommittedChanges(BzrError):
2833
2596
 
2834
 
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2835
 
            ' (See bzr status).%(more)s')
 
2597
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2836
2598
 
2837
 
    def __init__(self, tree, more=None):
2838
 
        if more is None:
2839
 
            more = ''
2840
 
        else:
2841
 
            more = ' ' + more
 
2599
    def __init__(self, tree):
2842
2600
        import bzrlib.urlutils as urlutils
2843
2601
        display_url = urlutils.unescape_for_display(
2844
 
            tree.user_url, 'ascii')
2845
 
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2846
 
 
2847
 
 
2848
 
class ShelvedChanges(UncommittedChanges):
2849
 
 
2850
 
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
2851
 
            ' (See bzr shelve --list).%(more)s')
 
2602
            tree.bzrdir.root_transport.base, 'ascii')
 
2603
        BzrError.__init__(self, tree=tree, display_url=display_url)
2852
2604
 
2853
2605
 
2854
2606
class MissingTemplateVariable(BzrError):
2889
2641
 
2890
2642
 
2891
2643
class CommandAvailableInPlugin(StandardError):
2892
 
 
 
2644
    
2893
2645
    internal_error = False
2894
2646
 
2895
2647
    def __init__(self, cmd_name, plugin_metadata, provider):
2896
 
 
 
2648
        
2897
2649
        self.plugin_metadata = plugin_metadata
2898
2650
        self.cmd_name = cmd_name
2899
2651
        self.provider = provider
2900
2652
 
2901
2653
    def __str__(self):
2902
2654
 
2903
 
        _fmt = ('"%s" is not a standard bzr command. \n'
 
2655
        _fmt = ('"%s" is not a standard bzr command. \n' 
2904
2656
                'However, the following official plugin provides this command: %s\n'
2905
2657
                'You can install it by going to: %s'
2906
 
                % (self.cmd_name, self.plugin_metadata['name'],
 
2658
                % (self.cmd_name, self.plugin_metadata['name'], 
2907
2659
                    self.plugin_metadata['url']))
2908
2660
 
2909
2661
        return _fmt
2910
2662
 
2911
2663
 
2912
2664
class NoPluginAvailable(BzrError):
2913
 
    pass
 
2665
    pass    
 
2666
 
 
2667
 
 
2668
class NotATerminal(BzrError):
 
2669
 
 
2670
    _fmt = 'Unable to ask for a password without real terminal.'
2914
2671
 
2915
2672
 
2916
2673
class UnableEncodePath(BzrError):
2919
2676
            'user encoding %(user_encoding)s')
2920
2677
 
2921
2678
    def __init__(self, path, kind):
2922
 
        from bzrlib.osutils import get_user_encoding
2923
2679
        self.path = path
2924
2680
        self.kind = kind
2925
2681
        self.user_encoding = osutils.get_user_encoding()
2926
2682
 
2927
2683
 
2928
 
class NoSuchAlias(BzrError):
2929
 
 
2930
 
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2931
 
 
2932
 
    def __init__(self, alias_name):
2933
 
        BzrError.__init__(self, alias_name=alias_name)
2934
 
 
2935
 
 
2936
 
class DirectoryLookupFailure(BzrError):
2937
 
    """Base type for lookup errors."""
2938
 
 
2939
 
    pass
2940
 
 
2941
 
 
2942
 
class InvalidLocationAlias(DirectoryLookupFailure):
2943
 
 
2944
 
    _fmt = '"%(alias_name)s" is not a valid location alias.'
2945
 
 
2946
 
    def __init__(self, alias_name):
2947
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2948
 
 
2949
 
 
2950
 
class UnsetLocationAlias(DirectoryLookupFailure):
2951
 
 
2952
 
    _fmt = 'No %(alias_name)s location assigned.'
2953
 
 
2954
 
    def __init__(self, alias_name):
2955
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2956
 
 
2957
 
 
2958
2684
class CannotBindAddress(BzrError):
2959
2685
 
2960
2686
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2961
2687
 
2962
2688
    def __init__(self, host, port, orig_error):
2963
 
        # nb: in python2.4 socket.error doesn't have a useful repr
2964
2689
        BzrError.__init__(self, host=host, port=port,
2965
 
            orig_error=repr(orig_error.args))
2966
 
 
2967
 
 
2968
 
class UnknownRules(BzrError):
2969
 
 
2970
 
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
2971
 
 
2972
 
    def __init__(self, unknowns):
2973
 
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2974
 
 
2975
 
 
2976
 
class HookFailed(BzrError):
2977
 
    """Raised when a pre_change_branch_tip hook function fails anything other
2978
 
    than TipChangeRejected.
2979
 
 
2980
 
    Note that this exception is no longer raised, and the import is only left
2981
 
    to be nice to code which might catch it in a plugin.
2982
 
    """
2983
 
 
2984
 
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2985
 
            "%(traceback_text)s%(exc_value)s")
2986
 
 
2987
 
    def __init__(self, hook_stage, hook_name, exc_info, warn=True):
2988
 
        if warn:
2989
 
            symbol_versioning.warn("BzrError HookFailed has been deprecated "
2990
 
                "as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
2991
 
        import traceback
2992
 
        self.hook_stage = hook_stage
2993
 
        self.hook_name = hook_name
2994
 
        self.exc_info = exc_info
2995
 
        self.exc_type = exc_info[0]
2996
 
        self.exc_value = exc_info[1]
2997
 
        self.exc_tb = exc_info[2]
2998
 
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2999
 
 
3000
 
 
3001
 
class TipChangeRejected(BzrError):
3002
 
    """A pre_change_branch_tip hook function may raise this to cleanly and
3003
 
    explicitly abort a change to a branch tip.
3004
 
    """
3005
 
 
3006
 
    _fmt = u"Tip change rejected: %(msg)s"
3007
 
 
3008
 
    def __init__(self, msg):
3009
 
        self.msg = msg
3010
 
 
3011
 
 
3012
 
class ShelfCorrupt(BzrError):
3013
 
 
3014
 
    _fmt = "Shelf corrupt."
3015
 
 
3016
 
 
3017
 
class NoSuchShelfId(BzrError):
3018
 
 
3019
 
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
3020
 
 
3021
 
    def __init__(self, shelf_id):
3022
 
        BzrError.__init__(self, shelf_id=shelf_id)
3023
 
 
3024
 
 
3025
 
class InvalidShelfId(BzrError):
3026
 
 
3027
 
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3028
 
 
3029
 
    def __init__(self, invalid_id):
3030
 
        BzrError.__init__(self, invalid_id=invalid_id)
3031
 
 
3032
 
 
3033
 
class JailBreak(BzrError):
3034
 
 
3035
 
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3036
 
 
3037
 
    def __init__(self, url):
3038
 
        BzrError.__init__(self, url=url)
3039
 
 
3040
 
 
3041
 
class UserAbort(BzrError):
3042
 
 
3043
 
    _fmt = 'The user aborted the operation.'
3044
 
 
3045
 
 
3046
 
class MustHaveWorkingTree(BzrError):
3047
 
 
3048
 
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3049
 
 
3050
 
    def __init__(self, format, url):
3051
 
        BzrError.__init__(self, format=format, url=url)
3052
 
 
3053
 
 
3054
 
class NoSuchView(BzrError):
3055
 
    """A view does not exist.
3056
 
    """
3057
 
 
3058
 
    _fmt = u"No such view: %(view_name)s."
3059
 
 
3060
 
    def __init__(self, view_name):
3061
 
        self.view_name = view_name
3062
 
 
3063
 
 
3064
 
class ViewsNotSupported(BzrError):
3065
 
    """Views are not supported by a tree format.
3066
 
    """
3067
 
 
3068
 
    _fmt = ("Views are not supported by %(tree)s;"
3069
 
            " use 'bzr upgrade' to change your tree to a later format.")
3070
 
 
3071
 
    def __init__(self, tree):
3072
 
        self.tree = tree
3073
 
 
3074
 
 
3075
 
class FileOutsideView(BzrError):
3076
 
 
3077
 
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
3078
 
            '%(view_str)s')
3079
 
 
3080
 
    def __init__(self, file_name, view_files):
3081
 
        self.file_name = file_name
3082
 
        self.view_str = ", ".join(view_files)
3083
 
 
3084
 
 
3085
 
class UnresumableWriteGroup(BzrError):
3086
 
 
3087
 
    _fmt = ("Repository %(repository)s cannot resume write group "
3088
 
            "%(write_groups)r: %(reason)s")
3089
 
 
3090
 
    internal_error = True
3091
 
 
3092
 
    def __init__(self, repository, write_groups, reason):
3093
 
        self.repository = repository
3094
 
        self.write_groups = write_groups
3095
 
        self.reason = reason
3096
 
 
3097
 
 
3098
 
class UnsuspendableWriteGroup(BzrError):
3099
 
 
3100
 
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
3101
 
 
3102
 
    internal_error = True
3103
 
 
3104
 
    def __init__(self, repository):
3105
 
        self.repository = repository
3106
 
 
3107
 
 
3108
 
class LossyPushToSameVCS(BzrError):
3109
 
 
3110
 
    _fmt = ("Lossy push not possible between %(source_branch)r and "
3111
 
            "%(target_branch)r that are in the same VCS.")
3112
 
 
3113
 
    internal_error = True
3114
 
 
3115
 
    def __init__(self, source_branch, target_branch):
3116
 
        self.source_branch = source_branch
3117
 
        self.target_branch = target_branch
3118
 
 
3119
 
 
3120
 
class NoRoundtrippingSupport(BzrError):
3121
 
 
3122
 
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
3123
 
            "%(target_branch)r.")
3124
 
 
3125
 
    internal_error = True
3126
 
 
3127
 
    def __init__(self, source_branch, target_branch):
3128
 
        self.source_branch = source_branch
3129
 
        self.target_branch = target_branch
3130
 
 
3131
 
 
3132
 
class FileTimestampUnavailable(BzrError):
3133
 
 
3134
 
    _fmt = "The filestamp for %(path)s is not available."
3135
 
 
3136
 
    internal_error = True
3137
 
 
3138
 
    def __init__(self, path):
3139
 
        self.path = path
3140
 
 
3141
 
 
3142
 
class NoColocatedBranchSupport(BzrError):
3143
 
 
3144
 
    _fmt = ("%(bzrdir)r does not support co-located branches.")
3145
 
 
3146
 
    def __init__(self, bzrdir):
3147
 
        self.bzrdir = bzrdir
3148
 
 
3149
 
 
3150
 
class NoWhoami(BzrError):
3151
 
 
3152
 
    _fmt = ('Unable to determine your name.\n'
3153
 
        "Please, set your name with the 'whoami' command.\n"
3154
 
        'E.g. bzr whoami "Your Name <name@example.com>"')
3155
 
 
3156
 
 
3157
 
class InvalidPattern(BzrError):
3158
 
 
3159
 
    _fmt = ('Invalid pattern(s) found. %(msg)s')
3160
 
 
3161
 
    def __init__(self, msg):
3162
 
        self.msg = msg
3163
 
 
3164
 
 
3165
 
class RecursiveBind(BzrError):
3166
 
 
3167
 
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3168
 
        'Please use `bzr unbind` to fix.')
3169
 
 
3170
 
    def __init__(self, branch_url):
3171
 
        self.branch_url = branch_url
3172
 
 
 
2690
            orig_error=orig_error[1])