~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Matthew Revell
  • Date: 2008-03-05 14:11:35 UTC
  • mto: This revision was merged to the branch mainline in revision 3263.
  • Revision ID: matthew.revell@canonical.com-20080305141135-96jf8j24b9crru6v
Added an admin-guide directory to doc/en and outlined headings for the admin guide in index.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
 
20
 
20
21
from bzrlib import (
21
22
    osutils,
22
23
    symbol_versioning,
31
32
 
32
33
 
33
34
# TODO: is there any value in providing the .args field used by standard
34
 
# python exceptions?   A list of values with no names seems less useful
 
35
# python exceptions?   A list of values with no names seems less useful 
35
36
# to me.
36
37
 
37
 
# TODO: Perhaps convert the exception to a string at the moment it's
 
38
# TODO: Perhaps convert the exception to a string at the moment it's 
38
39
# constructed to make sure it will succeed.  But that says nothing about
39
40
# exceptions that are never raised.
40
41
 
61
62
    :cvar _fmt: Format string to display the error; this is expanded
62
63
    by the instance's dict.
63
64
    """
64
 
 
 
65
    
65
66
    internal_error = False
66
67
 
67
68
    def __init__(self, msg=None, **kwds):
72
73
        arguments can be given.  The first is for generic "user" errors which
73
74
        are not intended to be caught and so do not need a specific subclass.
74
75
        The second case is for use with subclasses that provide a _fmt format
75
 
        string to print the arguments.
 
76
        string to print the arguments.  
76
77
 
77
 
        Keyword arguments are taken as parameters to the error, which can
78
 
        be inserted into the format string template.  It's recommended
79
 
        that subclasses override the __init__ method to require specific
 
78
        Keyword arguments are taken as parameters to the error, which can 
 
79
        be inserted into the format string template.  It's recommended 
 
80
        that subclasses override the __init__ method to require specific 
80
81
        parameters.
81
82
 
82
83
        :param msg: If given, this is the literal complete text for the error,
83
 
           not subject to expansion. 'msg' is used instead of 'message' because
84
 
           python evolved and, in 2.6, forbids the use of 'message'.
 
84
        not subject to expansion.
85
85
        """
86
86
        StandardError.__init__(self)
87
87
        if msg is not None:
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
 
211
 
class BranchError(BzrError):
212
 
    """Base class for concrete 'errors about a branch'."""
213
 
 
214
 
    def __init__(self, branch):
215
 
        BzrError.__init__(self, branch=branch)
216
 
 
217
 
 
218
188
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
 
189
    
 
190
    _fmt = "Internal check failed: %(message)s"
 
191
 
 
192
    def __init__(self, message):
 
193
        BzrError.__init__(self)
 
194
        self.message = message
235
195
 
236
196
 
237
197
class DisabledMethod(InternalBzrError):
265
225
 
266
226
 
267
227
class InvalidEntryName(InternalBzrError):
268
 
 
 
228
    
269
229
    _fmt = "Invalid entry name: %(name)s"
270
230
 
271
231
    def __init__(self, name):
274
234
 
275
235
 
276
236
class InvalidRevisionNumber(BzrError):
277
 
 
 
237
    
278
238
    _fmt = "Invalid revision number %(revno)s"
279
239
 
280
240
    def __init__(self, revno):
329
289
class NoSuchId(BzrError):
330
290
 
331
291
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
332
 
 
 
292
    
333
293
    def __init__(self, tree, file_id):
334
294
        BzrError.__init__(self)
335
295
        self.file_id = file_id
345
305
        BzrError.__init__(self, repository=repository, file_id=file_id)
346
306
 
347
307
 
348
 
class NotStacked(BranchError):
349
 
 
350
 
    _fmt = "The branch '%(branch)s' is not stacked."
351
 
 
352
 
 
353
308
class InventoryModified(InternalBzrError):
354
309
 
355
310
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
362
317
class NoWorkingTree(BzrError):
363
318
 
364
319
    _fmt = 'No WorkingTree exists for "%(base)s".'
365
 
 
 
320
    
366
321
    def __init__(self, base):
367
322
        BzrError.__init__(self)
368
323
        self.base = base
399
354
    # are not intended to be caught anyway.  UI code need not subclass
400
355
    # BzrCommandError, and non-UI code should not throw a subclass of
401
356
    # BzrCommandError.  ADHB 20051211
 
357
    def __init__(self, msg):
 
358
        # Object.__str__() must return a real string
 
359
        # returning a Unicode string is a python error.
 
360
        if isinstance(msg, unicode):
 
361
            self.msg = msg.encode('utf8')
 
362
        else:
 
363
            self.msg = msg
 
364
 
 
365
    def __str__(self):
 
366
        return self.msg
402
367
 
403
368
 
404
369
class NotWriteLocked(BzrError):
477
442
    def __init__(self, name, value):
478
443
        BzrError.__init__(self, name=name, value=value)
479
444
 
480
 
 
 
445
    
481
446
class StrictCommitFailed(BzrError):
482
447
 
483
448
    _fmt = "Commit refused because there are unknown files in the tree"
486
451
# XXX: Should be unified with TransportError; they seem to represent the
487
452
# same thing
488
453
# 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
 
454
# - this is finer than a TransportError - and more useful as such. It 
490
455
# differentiates between 'transport has failed' and 'operation on a transport
491
456
# has failed.'
492
457
class PathError(BzrError):
493
 
 
 
458
    
494
459
    _fmt = "Generic path error: %(path)r%(extra)s)"
495
460
 
496
461
    def __init__(self, path, extra=None):
550
515
 
551
516
 
552
517
class ReadingCompleted(InternalBzrError):
553
 
 
 
518
    
554
519
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
555
520
            "called upon it - the request has been completed and no more "
556
521
            "data may be read.")
576
541
 
577
542
class InvalidURLJoin(PathError):
578
543
 
579
 
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
580
 
 
581
 
    def __init__(self, reason, base, join_args):
582
 
        self.reason = reason
583
 
        self.base = base
584
 
        self.join_args = join_args
585
 
        PathError.__init__(self, base, reason)
586
 
 
587
 
 
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
 
class UnavailableRepresentation(InternalBzrError):
599
 
 
600
 
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
601
 
        "is encoded as '%(native)s'.")
602
 
 
603
 
    def __init__(self, key, wanted, native):
604
 
        InternalBzrError.__init__(self)
605
 
        self.wanted = wanted
606
 
        self.native = native
607
 
        self.key = key
 
544
    _fmt = 'Invalid URL join request: "%(args)s"%(extra)s'
 
545
 
 
546
    def __init__(self, msg, base, args):
 
547
        PathError.__init__(self, base, msg)
 
548
        self.args = [base] + list(args)
608
549
 
609
550
 
610
551
class UnknownHook(BzrError):
625
566
        PathError.__init__(self, url, extra=extra)
626
567
 
627
568
 
628
 
class UnstackableBranchFormat(BzrError):
629
 
 
630
 
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
631
 
        "You will need to upgrade the branch to permit branch stacking.")
632
 
 
633
 
    def __init__(self, format, url):
634
 
        BzrError.__init__(self)
635
 
        self.format = format
636
 
        self.url = url
637
 
 
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
 
 
649
 
class UnstackableRepositoryFormat(BzrError):
650
 
 
651
 
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
652
 
        "You will need to upgrade the repository to permit branch stacking.")
653
 
 
654
 
    def __init__(self, format, url):
655
 
        BzrError.__init__(self)
656
 
        self.format = format
657
 
        self.url = url
658
 
 
659
 
 
660
569
class ReadError(PathError):
661
 
 
 
570
    
662
571
    _fmt = """Error reading from %(path)r."""
663
572
 
664
573
 
699
608
 
700
609
# TODO: This is given a URL; we try to unescape it but doing that from inside
701
610
# the exception object is a bit undesirable.
702
 
# TODO: Probably this behavior of should be a common superclass
 
611
# TODO: Probably this behavior of should be a common superclass 
703
612
class NotBranchError(PathError):
704
613
 
705
 
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
 
614
    _fmt = 'Not a branch: "%(path)s".'
706
615
 
707
 
    def __init__(self, path, detail=None, bzrdir=None):
 
616
    def __init__(self, path):
708
617
       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)
 
618
       self.path = urlutils.unescape_for_display(path, 'ascii')
731
619
 
732
620
 
733
621
class NoSubmitBranch(PathError):
795
683
 
796
684
 
797
685
class UnknownFormatError(BzrError):
798
 
 
799
 
    _fmt = "Unknown %(kind)s format: %(format)r"
800
 
 
801
 
    def __init__(self, format, kind='branch'):
802
 
        self.kind = kind
803
 
        self.format = format
 
686
    
 
687
    _fmt = "Unknown branch format: %(format)r"
804
688
 
805
689
 
806
690
class IncompatibleFormat(BzrError):
807
 
 
 
691
    
808
692
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
809
693
 
810
694
    def __init__(self, format, bzrdir_format):
814
698
 
815
699
 
816
700
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)
 
701
 
 
702
    _fmt = "Repository %(target)s is not compatible with repository"\
 
703
        " %(source)s"
 
704
 
 
705
    def __init__(self, source, target):
 
706
        BzrError.__init__(self, target=target, source=source)
833
707
 
834
708
 
835
709
class IncompatibleRevision(BzrError):
836
 
 
 
710
    
837
711
    _fmt = "Revision is not compatible with %(repo_format)s"
838
712
 
839
713
    def __init__(self, repo_format):
922
796
        BzrError.__init__(self, filename=filename, kind=kind)
923
797
 
924
798
 
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
799
class ForbiddenControlFileError(BzrError):
937
800
 
938
801
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
991
854
        self.obj = obj
992
855
 
993
856
 
 
857
class ReadOnlyLockError(LockError):
 
858
 
 
859
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
 
860
 
 
861
    @symbol_versioning.deprecated_method(symbol_versioning.zero_ninetytwo)
 
862
    def __init__(self, fname, msg):
 
863
        LockError.__init__(self, '')
 
864
        self.fname = fname
 
865
        self.msg = msg
 
866
 
 
867
 
994
868
class LockFailed(LockError):
995
869
 
996
870
    internal_error = False
1040
914
 
1041
915
class LockContention(LockError):
1042
916
 
1043
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
 
917
    _fmt = 'Could not acquire lock "%(lock)s"'
1044
918
    # TODO: show full url for lock, combining the transport and relative
1045
919
    # bits?
1046
920
 
1047
921
    internal_error = False
1048
922
 
1049
 
    def __init__(self, lock, msg=''):
 
923
    def __init__(self, lock):
1050
924
        self.lock = lock
1051
 
        self.msg = msg
1052
925
 
1053
926
 
1054
927
class LockBroken(LockError):
1153
1026
        BzrError.__init__(self, branch=branch, revision=revision)
1154
1027
 
1155
1028
 
 
1029
# zero_ninetyone: this exception is no longer raised and should be removed
 
1030
class NotLeftParentDescendant(InternalBzrError):
 
1031
 
 
1032
    _fmt = ("Revision %(old_revision)s is not the left parent of"
 
1033
            " %(new_revision)s, but branch %(branch_location)s expects this")
 
1034
 
 
1035
    def __init__(self, branch, old_revision, new_revision):
 
1036
        BzrError.__init__(self, branch_location=branch.base,
 
1037
                          old_revision=old_revision,
 
1038
                          new_revision=new_revision)
 
1039
 
 
1040
 
1156
1041
class RangeInChangeOption(BzrError):
1157
1042
 
1158
1043
    _fmt = "Option --change does not accept revision ranges"
1168
1053
 
1169
1054
class NoSuchRevisionInTree(NoSuchRevision):
1170
1055
    """When using Tree.revision_tree, and the revision is not accessible."""
1171
 
 
 
1056
    
1172
1057
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1173
1058
 
1174
1059
    def __init__(self, tree, revision_id):
1210
1095
class DivergedBranches(BzrError):
1211
1096
 
1212
1097
    _fmt = ("These branches have diverged."
1213
 
            " Use the missing command to see how.\n"
1214
 
            "Use the merge command to reconcile them.")
 
1098
            " Use the merge command to reconcile them.")
1215
1099
 
1216
1100
    def __init__(self, branch1, branch2):
1217
1101
        self.branch1 = branch1
1239
1123
 
1240
1124
 
1241
1125
class NoCommonAncestor(BzrError):
1242
 
 
 
1126
    
1243
1127
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1244
1128
 
1245
1129
    def __init__(self, revision_a, revision_b):
1265
1149
            not_ancestor_id=not_ancestor_id)
1266
1150
 
1267
1151
 
 
1152
class InstallFailed(BzrError):
 
1153
 
 
1154
    def __init__(self, revisions):
 
1155
        revision_str = ", ".join(str(r) for r in revisions)
 
1156
        msg = "Could not install revisions:\n%s" % revision_str
 
1157
        BzrError.__init__(self, msg)
 
1158
        self.revisions = revisions
 
1159
 
 
1160
 
1268
1161
class AmbiguousBase(BzrError):
1269
1162
 
1270
1163
    def __init__(self, bases):
1271
 
        symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
1272
 
            "as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
 
1164
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
1165
                DeprecationWarning)
1273
1166
        msg = ("The correct base is unclear, because %s are all equally close"
1274
1167
                % ", ".join(bases))
1275
1168
        BzrError.__init__(self, msg)
1276
1169
        self.bases = bases
1277
1170
 
1278
1171
 
1279
 
class NoCommits(BranchError):
 
1172
class NoCommits(BzrError):
1280
1173
 
1281
1174
    _fmt = "Branch %(branch)s has no commits."
1282
1175
 
 
1176
    def __init__(self, branch):
 
1177
        BzrError.__init__(self, branch=branch)
 
1178
 
1283
1179
 
1284
1180
class UnlistableStore(BzrError):
1285
1181
 
1304
1200
        self.branch = branch
1305
1201
        self.master = master
1306
1202
 
1307
 
 
 
1203
        
1308
1204
class CommitToDoubleBoundBranch(BzrError):
1309
1205
 
1310
1206
    _fmt = ("Cannot commit to branch %(branch)s."
1340
1236
 
1341
1237
class WeaveError(BzrError):
1342
1238
 
1343
 
    _fmt = "Error in processing weave: %(msg)s"
 
1239
    _fmt = "Error in processing weave: %(message)s"
1344
1240
 
1345
 
    def __init__(self, msg=None):
 
1241
    def __init__(self, message=None):
1346
1242
        BzrError.__init__(self)
1347
 
        self.msg = msg
 
1243
        self.message = message
1348
1244
 
1349
1245
 
1350
1246
class WeaveRevisionAlreadyPresent(WeaveError):
1380
1276
class WeaveParentMismatch(WeaveError):
1381
1277
 
1382
1278
    _fmt = "Parents are mismatched between two revisions. %(message)s"
1383
 
 
 
1279
    
1384
1280
 
1385
1281
class WeaveInvalidChecksum(WeaveError):
1386
1282
 
1412
1308
 
1413
1309
 
1414
1310
class VersionedFileError(BzrError):
1415
 
 
 
1311
    
1416
1312
    _fmt = "Versioned file error"
1417
1313
 
1418
1314
 
1419
1315
class RevisionNotPresent(VersionedFileError):
1420
 
 
 
1316
    
1421
1317
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1422
1318
 
1423
1319
    def __init__(self, revision_id, file_id):
1427
1323
 
1428
1324
 
1429
1325
class RevisionAlreadyPresent(VersionedFileError):
1430
 
 
 
1326
    
1431
1327
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1432
1328
 
1433
1329
    def __init__(self, revision_id, file_id):
1442
1338
 
1443
1339
 
1444
1340
class KnitError(InternalBzrError):
1445
 
 
 
1341
    
1446
1342
    _fmt = "Knit error"
1447
1343
 
1448
1344
 
1456
1352
        self.how = how
1457
1353
 
1458
1354
 
1459
 
class SHA1KnitCorrupt(KnitCorrupt):
1460
 
 
1461
 
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
1462
 
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
1463
 
        "sha %(actual)s")
1464
 
 
1465
 
    def __init__(self, filename, actual, expected, key, content):
1466
 
        KnitError.__init__(self)
1467
 
        self.filename = filename
1468
 
        self.actual = actual
1469
 
        self.expected = expected
1470
 
        self.key = key
1471
 
        self.content = content
1472
 
 
1473
 
 
1474
1355
class KnitDataStreamIncompatible(KnitError):
1475
1356
    # Not raised anymore, as we can convert data streams.  In future we may
1476
1357
    # need it again for more exotic cases, so we're keeping it around for now.
1480
1361
    def __init__(self, stream_format, target_format):
1481
1362
        self.stream_format = stream_format
1482
1363
        self.target_format = target_format
1483
 
 
 
1364
        
1484
1365
 
1485
1366
class KnitDataStreamUnknown(KnitError):
1486
1367
    # Indicates a data stream we don't know how to handle.
1489
1370
 
1490
1371
    def __init__(self, stream_format):
1491
1372
        self.stream_format = stream_format
1492
 
 
 
1373
        
1493
1374
 
1494
1375
class KnitHeaderError(KnitError):
1495
1376
 
1505
1386
 
1506
1387
    Currently only 'fulltext' and 'line-delta' are supported.
1507
1388
    """
1508
 
 
 
1389
    
1509
1390
    _fmt = ("Knit index %(filename)s does not have a known method"
1510
1391
            " in options: %(options)r")
1511
1392
 
1515
1396
        self.options = options
1516
1397
 
1517
1398
 
1518
 
class RetryWithNewPacks(BzrError):
1519
 
    """Raised when we realize that the packs on disk have changed.
1520
 
 
1521
 
    This is meant as more of a signaling exception, to trap between where a
1522
 
    local error occurred and the code that can actually handle the error and
1523
 
    code that can retry appropriately.
1524
 
    """
1525
 
 
1526
 
    internal_error = True
1527
 
 
1528
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1529
 
            " %(orig_error)s")
1530
 
 
1531
 
    def __init__(self, context, reload_occurred, exc_info):
1532
 
        """create a new RetryWithNewPacks error.
1533
 
 
1534
 
        :param reload_occurred: Set to True if we know that the packs have
1535
 
            already been reloaded, and we are failing because of an in-memory
1536
 
            cache miss. If set to True then we will ignore if a reload says
1537
 
            nothing has changed, because we assume it has already reloaded. If
1538
 
            False, then a reload with nothing changed will force an error.
1539
 
        :param exc_info: The original exception traceback, so if there is a
1540
 
            problem we can raise the original error (value from sys.exc_info())
1541
 
        """
1542
 
        BzrError.__init__(self)
1543
 
        self.reload_occurred = reload_occurred
1544
 
        self.exc_info = exc_info
1545
 
        self.orig_error = exc_info[1]
1546
 
        # TODO: The global error handler should probably treat this by
1547
 
        #       raising/printing the original exception with a bit about
1548
 
        #       RetryWithNewPacks also not being caught
1549
 
 
1550
 
 
1551
 
class RetryAutopack(RetryWithNewPacks):
1552
 
    """Raised when we are autopacking and we find a missing file.
1553
 
 
1554
 
    Meant as a signaling exception, to tell the autopack code it should try
1555
 
    again.
1556
 
    """
1557
 
 
1558
 
    internal_error = True
1559
 
 
1560
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1561
 
            " context: %(context)s %(orig_error)s")
1562
 
 
1563
 
 
1564
1399
class NoSuchExportFormat(BzrError):
1565
 
 
 
1400
    
1566
1401
    _fmt = "Export format %(format)r not supported"
1567
1402
 
1568
1403
    def __init__(self, format):
1571
1406
 
1572
1407
 
1573
1408
class TransportError(BzrError):
1574
 
 
 
1409
    
1575
1410
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1576
1411
 
1577
1412
    def __init__(self, msg=None, orig_error=None):
1604
1439
        self.details = details
1605
1440
 
1606
1441
 
1607
 
class UnexpectedProtocolVersionMarker(TransportError):
1608
 
 
1609
 
    _fmt = "Received bad protocol version marker: %(marker)r"
1610
 
 
1611
 
    def __init__(self, marker):
1612
 
        self.marker = marker
1613
 
 
1614
 
 
1615
 
class UnknownSmartMethod(InternalBzrError):
1616
 
 
1617
 
    _fmt = "The server does not recognise the '%(verb)s' request."
1618
 
 
1619
 
    def __init__(self, verb):
1620
 
        self.verb = verb
1621
 
 
1622
 
 
1623
 
class SmartMessageHandlerError(InternalBzrError):
1624
 
 
1625
 
    _fmt = ("The message handler raised an exception:\n"
1626
 
            "%(traceback_text)s")
1627
 
 
1628
 
    def __init__(self, exc_info):
1629
 
        import traceback
1630
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1631
 
        self.exc_info = exc_info
1632
 
        traceback_strings = traceback.format_exception(
1633
 
                self.exc_type, self.exc_value, self.exc_tb)
1634
 
        self.traceback_text = ''.join(traceback_strings)
1635
 
 
1636
 
 
1637
1442
# A set of semi-meaningful errors which can be thrown
1638
1443
class TransportNotPossible(TransportError):
1639
1444
 
1664
1469
            self.port = ':%s' % port
1665
1470
 
1666
1471
 
1667
 
# XXX: This is also used for unexpected end of file, which is different at the
1668
 
# TCP level from "connection reset".
1669
1472
class ConnectionReset(TransportError):
1670
1473
 
1671
1474
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1712
1515
 
1713
1516
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1714
1517
 
1715
 
    def __init__(self, source, target, is_permanent=False):
 
1518
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
1716
1519
        self.source = source
1717
1520
        self.target = target
1718
1521
        if is_permanent:
1719
1522
            self.permanently = ' permanently'
1720
1523
        else:
1721
1524
            self.permanently = ''
 
1525
        self._qualified_proto = qual_proto
1722
1526
        TransportError.__init__(self)
1723
1527
 
 
1528
    def _requalify_url(self, url):
 
1529
        """Restore the qualified proto in front of the url"""
 
1530
        # When this exception is raised, source and target are in
 
1531
        # user readable format. But some transports may use a
 
1532
        # different proto (http+urllib:// will present http:// to
 
1533
        # the user. If a qualified proto is specified, the code
 
1534
        # trapping the exception can get the qualified urls to
 
1535
        # properly handle the redirection themself (creating a
 
1536
        # new transport object from the target url for example).
 
1537
        # But checking that the scheme of the original and
 
1538
        # redirected urls are the same can be tricky. (see the
 
1539
        # FIXME in BzrDir.open_from_transport for the unique use
 
1540
        # case so far).
 
1541
        if self._qualified_proto is None:
 
1542
            return url
 
1543
 
 
1544
        # The TODO related to NotBranchError mention that doing
 
1545
        # that kind of manipulation on the urls may not be the
 
1546
        # exception object job. On the other hand, this object is
 
1547
        # the interface between the code and the user so
 
1548
        # presenting the urls in different ways is indeed its
 
1549
        # job...
 
1550
        import urlparse
 
1551
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1552
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1553
                                   query, fragment))
 
1554
 
 
1555
    def get_source_url(self):
 
1556
        return self._requalify_url(self.source)
 
1557
 
 
1558
    def get_target_url(self):
 
1559
        return self._requalify_url(self.target)
 
1560
 
1724
1561
 
1725
1562
class TooManyRedirections(TransportError):
1726
1563
 
1738
1575
        if filename is None:
1739
1576
            filename = ""
1740
1577
        message = "Error(s) parsing config file %s:\n%s" % \
1741
 
            (filename, ('\n'.join(e.msg for e in errors)))
 
1578
            (filename, ('\n'.join(e.message for e in errors)))
1742
1579
        BzrError.__init__(self, message)
1743
1580
 
1744
1581
 
1761
1598
 
1762
1599
class WorkingTreeNotRevision(BzrError):
1763
1600
 
1764
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1601
    _fmt = ("The working tree for %(basedir)s has changed since" 
1765
1602
            " the last commit, but weave merge requires that it be"
1766
1603
            " unchanged")
1767
1604
 
1929
1766
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1930
1767
 
1931
1768
    def __init__(self, from_path='', to_path='', extra=None):
1932
 
        from bzrlib.osutils import splitpath
1933
1769
        BzrError.__init__(self)
1934
1770
        if extra:
1935
1771
            self.extra = ': ' + str(extra)
1939
1775
        has_from = len(from_path) > 0
1940
1776
        has_to = len(to_path) > 0
1941
1777
        if has_from:
1942
 
            self.from_path = splitpath(from_path)[-1]
 
1778
            self.from_path = osutils.splitpath(from_path)[-1]
1943
1779
        else:
1944
1780
            self.from_path = ''
1945
1781
 
1946
1782
        if has_to:
1947
 
            self.to_path = splitpath(to_path)[-1]
 
1783
            self.to_path = osutils.splitpath(to_path)[-1]
1948
1784
        else:
1949
1785
            self.to_path = ''
1950
1786
 
2033
1869
 
2034
1870
class BadConversionTarget(BzrError):
2035
1871
 
2036
 
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
2037
 
            "    %(problem)s"
 
1872
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
2038
1873
 
2039
 
    def __init__(self, problem, format, from_format=None):
 
1874
    def __init__(self, problem, format):
2040
1875
        BzrError.__init__(self)
2041
1876
        self.problem = problem
2042
1877
        self.format = format
2043
 
        self.from_format = from_format or '(unspecified)'
2044
1878
 
2045
1879
 
2046
1880
class NoDiffFound(BzrError):
2083
1917
    _fmt = """This tree contains left-over files from a failed operation.
2084
1918
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2085
1919
    keep, and delete it when you are done."""
2086
 
 
 
1920
    
2087
1921
    def __init__(self, limbo_dir):
2088
1922
       BzrError.__init__(self)
2089
1923
       self.limbo_dir = limbo_dir
2122
1956
 
2123
1957
class OutOfDateTree(BzrError):
2124
1958
 
2125
 
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
 
1959
    _fmt = "Working tree is out of date, please run 'bzr update'."
2126
1960
 
2127
 
    def __init__(self, tree, more=None):
2128
 
        if more is None:
2129
 
            more = ''
2130
 
        else:
2131
 
            more = ' ' + more
 
1961
    def __init__(self, tree):
2132
1962
        BzrError.__init__(self)
2133
1963
        self.tree = tree
2134
 
        self.more = more
2135
1964
 
2136
1965
 
2137
1966
class PublicBranchOutOfDate(BzrError):
2191
2020
        self.reason = reason
2192
2021
 
2193
2022
 
2194
 
class InconsistentDeltaDelta(InconsistentDelta):
2195
 
    """Used when we get a delta that is not valid."""
2196
 
 
2197
 
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
2198
 
            "\nreason: %(reason)s")
2199
 
 
2200
 
    def __init__(self, delta, reason):
2201
 
        BzrError.__init__(self)
2202
 
        self.delta = delta
2203
 
        self.reason = reason
2204
 
 
2205
 
 
2206
2023
class UpgradeRequired(BzrError):
2207
2024
 
2208
2025
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2212
2029
        self.path = path
2213
2030
 
2214
2031
 
2215
 
class RepositoryUpgradeRequired(UpgradeRequired):
2216
 
 
2217
 
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2218
 
 
2219
 
 
2220
 
class RichRootUpgradeRequired(UpgradeRequired):
2221
 
 
2222
 
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
2223
 
           " a format which supports rich roots.")
2224
 
 
2225
 
 
2226
2032
class LocalRequiresBoundBranch(BzrError):
2227
2033
 
2228
2034
    _fmt = "Cannot perform local-only commits on unbound branches."
2229
2035
 
2230
2036
 
 
2037
class MissingProgressBarFinish(BzrError):
 
2038
 
 
2039
    _fmt = "A nested progress bar was not 'finished' correctly."
 
2040
 
 
2041
 
 
2042
class InvalidProgressBarType(BzrError):
 
2043
 
 
2044
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
 
2045
            " is not a supported type Select one of: %(valid_types)s")
 
2046
 
 
2047
    def __init__(self, bar_type, valid_types):
 
2048
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
2049
 
 
2050
 
2231
2051
class UnsupportedOperation(BzrError):
2232
2052
 
2233
2053
    _fmt = ("The method %(mname)s is not supported on"
2250
2070
 
2251
2071
 
2252
2072
class BinaryFile(BzrError):
2253
 
 
 
2073
    
2254
2074
    _fmt = "File is binary but should be text."
2255
2075
 
2256
2076
 
2276
2096
 
2277
2097
 
2278
2098
class NotABundle(BzrError):
2279
 
 
 
2099
    
2280
2100
    _fmt = "Not a bzr revision-bundle: %(text)r"
2281
2101
 
2282
2102
    def __init__(self, text):
2284
2104
        self.text = text
2285
2105
 
2286
2106
 
2287
 
class BadBundle(BzrError):
2288
 
 
 
2107
class BadBundle(BzrError): 
 
2108
    
2289
2109
    _fmt = "Bad bzr revision-bundle: %(text)r"
2290
2110
 
2291
2111
    def __init__(self, text):
2293
2113
        self.text = text
2294
2114
 
2295
2115
 
2296
 
class MalformedHeader(BadBundle):
2297
 
 
 
2116
class MalformedHeader(BadBundle): 
 
2117
    
2298
2118
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2299
2119
 
2300
2120
 
2301
 
class MalformedPatches(BadBundle):
2302
 
 
 
2121
class MalformedPatches(BadBundle): 
 
2122
    
2303
2123
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2304
2124
 
2305
2125
 
2306
 
class MalformedFooter(BadBundle):
2307
 
 
 
2126
class MalformedFooter(BadBundle): 
 
2127
    
2308
2128
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2309
2129
 
2310
2130
 
2311
2131
class UnsupportedEOLMarker(BadBundle):
2312
 
 
2313
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
2132
    
 
2133
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
2314
2134
 
2315
2135
    def __init__(self):
2316
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
2136
        # XXX: BadBundle's constructor assumes there's explanatory text, 
2317
2137
        # but for this there is not
2318
2138
        BzrError.__init__(self)
2319
2139
 
2320
2140
 
2321
2141
class IncompatibleBundleFormat(BzrError):
2322
 
 
 
2142
    
2323
2143
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2324
2144
 
2325
2145
    def __init__(self, bundle_format, other):
2329
2149
 
2330
2150
 
2331
2151
class BadInventoryFormat(BzrError):
2332
 
 
 
2152
    
2333
2153
    _fmt = "Root class for inventory serialization errors"
2334
2154
 
2335
2155
 
2354
2174
        self.transport = transport
2355
2175
 
2356
2176
 
 
2177
class NoSmartServer(NotBranchError):
 
2178
 
 
2179
    _fmt = "No smart server available at %(url)s"
 
2180
 
 
2181
    def __init__(self, url):
 
2182
        self.url = url
 
2183
 
 
2184
 
2357
2185
class UnknownSSH(BzrError):
2358
2186
 
2359
2187
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2369
2197
            " Please set BZR_SSH environment variable.")
2370
2198
 
2371
2199
 
2372
 
class GhostRevisionsHaveNoRevno(BzrError):
2373
 
    """When searching for revnos, if we encounter a ghost, we are stuck"""
2374
 
 
2375
 
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
2376
 
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
2377
 
 
2378
 
    def __init__(self, revision_id, ghost_revision_id):
2379
 
        self.revision_id = revision_id
2380
 
        self.ghost_revision_id = ghost_revision_id
2381
 
 
2382
 
 
2383
2200
class GhostRevisionUnusableHere(BzrError):
2384
2201
 
2385
2202
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2463
2280
        self.patch_type = patch_type
2464
2281
 
2465
2282
 
2466
 
class TargetNotBranch(BzrError):
2467
 
    """A merge directive's target branch is required, but isn't a branch"""
2468
 
 
2469
 
    _fmt = ("Your branch does not have all of the revisions required in "
2470
 
            "order to merge this merge directive and the target "
2471
 
            "location specified in the merge directive is not a branch: "
2472
 
            "%(location)s.")
2473
 
 
2474
 
    def __init__(self, location):
2475
 
        BzrError.__init__(self)
2476
 
        self.location = location
2477
 
 
2478
 
 
2479
2283
class UnsupportedInventoryKind(BzrError):
2480
 
 
 
2284
    
2481
2285
    _fmt = """Unsupported entry kind %(kind)s"""
2482
2286
 
2483
2287
    def __init__(self, kind):
2495
2299
 
2496
2300
 
2497
2301
class SubsumeTargetNeedsUpgrade(BzrError):
2498
 
 
 
2302
    
2499
2303
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2500
2304
 
2501
2305
    def __init__(self, other_tree):
2524
2328
class TagsNotSupported(BzrError):
2525
2329
 
2526
2330
    _fmt = ("Tags not supported by %(branch)s;"
2527
 
            " you may be able to use bzr upgrade.")
 
2331
            " you may be able to use bzr upgrade --dirstate-tags.")
2528
2332
 
2529
2333
    def __init__(self, branch):
2530
2334
        self.branch = branch
2531
2335
 
2532
 
 
 
2336
        
2533
2337
class TagAlreadyExists(BzrError):
2534
2338
 
2535
2339
    _fmt = "Tag %(tag_name)s already exists."
2540
2344
 
2541
2345
class MalformedBugIdentifier(BzrError):
2542
2346
 
2543
 
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
2544
 
            'See "bzr help bugs" for more information on this feature.')
 
2347
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2545
2348
 
2546
2349
    def __init__(self, bug_id, reason):
2547
2350
        self.bug_id = bug_id
2568
2371
        self.branch = branch
2569
2372
 
2570
2373
 
2571
 
class InvalidLineInBugsProperty(BzrError):
2572
 
 
2573
 
    _fmt = ("Invalid line in bugs property: '%(line)s'")
2574
 
 
2575
 
    def __init__(self, line):
2576
 
        self.line = line
2577
 
 
2578
 
 
2579
 
class InvalidBugStatus(BzrError):
2580
 
 
2581
 
    _fmt = ("Invalid bug status: '%(status)s'")
2582
 
 
2583
 
    def __init__(self, status):
2584
 
        self.status = status
2585
 
 
2586
 
 
2587
2374
class UnexpectedSmartServerResponse(BzrError):
2588
2375
 
2589
2376
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2592
2379
        self.response_tuple = response_tuple
2593
2380
 
2594
2381
 
2595
 
class ErrorFromSmartServer(BzrError):
2596
 
    """An error was received from a smart server.
2597
 
 
2598
 
    :seealso: UnknownErrorFromSmartServer
2599
 
    """
2600
 
 
2601
 
    _fmt = "Error received from smart server: %(error_tuple)r"
2602
 
 
2603
 
    internal_error = True
2604
 
 
2605
 
    def __init__(self, error_tuple):
2606
 
        self.error_tuple = error_tuple
2607
 
        try:
2608
 
            self.error_verb = error_tuple[0]
2609
 
        except IndexError:
2610
 
            self.error_verb = None
2611
 
        self.error_args = error_tuple[1:]
2612
 
 
2613
 
 
2614
 
class UnknownErrorFromSmartServer(BzrError):
2615
 
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
2616
 
    error.
2617
 
 
2618
 
    This is distinct from ErrorFromSmartServer so that it is possible to
2619
 
    distinguish between the following two cases:
2620
 
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
2621
 
        and so should provoke a traceback to the user.
2622
 
      - ErrorFromSmartServer was caught but its error_tuple could not be
2623
 
        translated.  This is probably because the server sent us garbage, and
2624
 
        should not provoke a traceback.
2625
 
    """
2626
 
 
2627
 
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2628
 
 
2629
 
    internal_error = False
2630
 
 
2631
 
    def __init__(self, error_from_smart_server):
2632
 
        """Constructor.
2633
 
 
2634
 
        :param error_from_smart_server: An ErrorFromSmartServer instance.
2635
 
        """
2636
 
        self.error_from_smart_server = error_from_smart_server
2637
 
        self.error_tuple = error_from_smart_server.error_tuple
2638
 
 
2639
 
 
2640
2382
class ContainerError(BzrError):
2641
2383
    """Base class of container errors."""
2642
2384
 
2644
2386
class UnknownContainerFormatError(ContainerError):
2645
2387
 
2646
2388
    _fmt = "Unrecognised container format: %(container_format)r"
2647
 
 
 
2389
    
2648
2390
    def __init__(self, container_format):
2649
2391
        self.container_format = container_format
2650
2392
 
2714
2456
 
2715
2457
class NoMailAddressSpecified(BzrError):
2716
2458
 
2717
 
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
 
2459
    _fmt = "No mail-to address specified."
2718
2460
 
2719
2461
 
2720
2462
class UnknownMailClient(BzrError):
2758
2500
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2759
2501
 
2760
2502
 
2761
 
class UnsyncedBranches(BzrDirError):
2762
 
 
2763
 
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
2764
 
            " bzr help sync-for-reconfigure.")
2765
 
 
2766
 
    def __init__(self, bzrdir, target_branch):
2767
 
        BzrDirError.__init__(self, bzrdir)
2768
 
        import bzrlib.urlutils as urlutils
2769
 
        self.target_url = urlutils.unescape_for_display(target_branch.base,
2770
 
                                                        'ascii')
2771
 
 
2772
 
 
2773
2503
class AlreadyBranch(BzrDirError):
2774
2504
 
2775
2505
    _fmt = "'%(display_url)s' is already a branch."
2790
2520
    _fmt = "'%(display_url)s' is already a lightweight checkout."
2791
2521
 
2792
2522
 
2793
 
class AlreadyUsingShared(BzrDirError):
2794
 
 
2795
 
    _fmt = "'%(display_url)s' is already using a shared repository."
2796
 
 
2797
 
 
2798
 
class AlreadyStandalone(BzrDirError):
2799
 
 
2800
 
    _fmt = "'%(display_url)s' is already standalone."
2801
 
 
2802
 
 
2803
 
class AlreadyWithTrees(BzrDirError):
2804
 
 
2805
 
    _fmt = ("Shared repository '%(display_url)s' already creates "
2806
 
            "working trees.")
2807
 
 
2808
 
 
2809
 
class AlreadyWithNoTrees(BzrDirError):
2810
 
 
2811
 
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
2812
 
            "working trees.")
2813
 
 
2814
 
 
2815
2523
class ReconfigurationNotSupported(BzrDirError):
2816
2524
 
2817
2525
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2824
2532
 
2825
2533
class UncommittedChanges(BzrError):
2826
2534
 
2827
 
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2828
 
            ' (See bzr status).%(more)s')
 
2535
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2829
2536
 
2830
 
    def __init__(self, tree, more=None):
2831
 
        if more is None:
2832
 
            more = ''
2833
 
        else:
2834
 
            more = ' ' + more
 
2537
    def __init__(self, tree):
2835
2538
        import bzrlib.urlutils as urlutils
2836
2539
        display_url = urlutils.unescape_for_display(
2837
2540
            tree.bzrdir.root_transport.base, 'ascii')
2838
 
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
 
2541
        BzrError.__init__(self, tree=tree, display_url=display_url)
2839
2542
 
2840
2543
 
2841
2544
class MissingTemplateVariable(BzrError):
2873
2576
 
2874
2577
    def __init__(self, timezone):
2875
2578
        self.timezone = timezone
2876
 
 
2877
 
 
2878
 
class CommandAvailableInPlugin(StandardError):
2879
 
 
2880
 
    internal_error = False
2881
 
 
2882
 
    def __init__(self, cmd_name, plugin_metadata, provider):
2883
 
 
2884
 
        self.plugin_metadata = plugin_metadata
2885
 
        self.cmd_name = cmd_name
2886
 
        self.provider = provider
2887
 
 
2888
 
    def __str__(self):
2889
 
 
2890
 
        _fmt = ('"%s" is not a standard bzr command. \n'
2891
 
                'However, the following official plugin provides this command: %s\n'
2892
 
                'You can install it by going to: %s'
2893
 
                % (self.cmd_name, self.plugin_metadata['name'],
2894
 
                    self.plugin_metadata['url']))
2895
 
 
2896
 
        return _fmt
2897
 
 
2898
 
 
2899
 
class NoPluginAvailable(BzrError):
2900
 
    pass
2901
 
 
2902
 
 
2903
 
class UnableEncodePath(BzrError):
2904
 
 
2905
 
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2906
 
            'user encoding %(user_encoding)s')
2907
 
 
2908
 
    def __init__(self, path, kind):
2909
 
        from bzrlib.osutils import get_user_encoding
2910
 
        self.path = path
2911
 
        self.kind = kind
2912
 
        self.user_encoding = osutils.get_user_encoding()
2913
 
 
2914
 
 
2915
 
class NoSuchAlias(BzrError):
2916
 
 
2917
 
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2918
 
 
2919
 
    def __init__(self, alias_name):
2920
 
        BzrError.__init__(self, alias_name=alias_name)
2921
 
 
2922
 
 
2923
 
class DirectoryLookupFailure(BzrError):
2924
 
    """Base type for lookup errors."""
2925
 
 
2926
 
    pass
2927
 
 
2928
 
 
2929
 
class InvalidLocationAlias(DirectoryLookupFailure):
2930
 
 
2931
 
    _fmt = '"%(alias_name)s" is not a valid location alias.'
2932
 
 
2933
 
    def __init__(self, alias_name):
2934
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2935
 
 
2936
 
 
2937
 
class UnsetLocationAlias(DirectoryLookupFailure):
2938
 
 
2939
 
    _fmt = 'No %(alias_name)s location assigned.'
2940
 
 
2941
 
    def __init__(self, alias_name):
2942
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2943
 
 
2944
 
 
2945
 
class CannotBindAddress(BzrError):
2946
 
 
2947
 
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2948
 
 
2949
 
    def __init__(self, host, port, orig_error):
2950
 
        # nb: in python2.4 socket.error doesn't have a useful repr
2951
 
        BzrError.__init__(self, host=host, port=port,
2952
 
            orig_error=repr(orig_error.args))
2953
 
 
2954
 
 
2955
 
class UnknownRules(BzrError):
2956
 
 
2957
 
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
2958
 
 
2959
 
    def __init__(self, unknowns):
2960
 
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2961
 
 
2962
 
 
2963
 
class HookFailed(BzrError):
2964
 
    """Raised when a pre_change_branch_tip hook function fails anything other
2965
 
    than TipChangeRejected.
2966
 
 
2967
 
    Note that this exception is no longer raised, and the import is only left
2968
 
    to be nice to code which might catch it in a plugin.
2969
 
    """
2970
 
 
2971
 
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2972
 
            "%(traceback_text)s%(exc_value)s")
2973
 
 
2974
 
    def __init__(self, hook_stage, hook_name, exc_info, warn=True):
2975
 
        if warn:
2976
 
            symbol_versioning.warn("BzrError HookFailed has been deprecated "
2977
 
                "as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
2978
 
        import traceback
2979
 
        self.hook_stage = hook_stage
2980
 
        self.hook_name = hook_name
2981
 
        self.exc_info = exc_info
2982
 
        self.exc_type = exc_info[0]
2983
 
        self.exc_value = exc_info[1]
2984
 
        self.exc_tb = exc_info[2]
2985
 
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2986
 
 
2987
 
 
2988
 
class TipChangeRejected(BzrError):
2989
 
    """A pre_change_branch_tip hook function may raise this to cleanly and
2990
 
    explicitly abort a change to a branch tip.
2991
 
    """
2992
 
 
2993
 
    _fmt = u"Tip change rejected: %(msg)s"
2994
 
 
2995
 
    def __init__(self, msg):
2996
 
        self.msg = msg
2997
 
 
2998
 
 
2999
 
class ShelfCorrupt(BzrError):
3000
 
 
3001
 
    _fmt = "Shelf corrupt."
3002
 
 
3003
 
 
3004
 
class NoSuchShelfId(BzrError):
3005
 
 
3006
 
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
3007
 
 
3008
 
    def __init__(self, shelf_id):
3009
 
        BzrError.__init__(self, shelf_id=shelf_id)
3010
 
 
3011
 
 
3012
 
class InvalidShelfId(BzrError):
3013
 
 
3014
 
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3015
 
 
3016
 
    def __init__(self, invalid_id):
3017
 
        BzrError.__init__(self, invalid_id=invalid_id)
3018
 
 
3019
 
 
3020
 
class JailBreak(BzrError):
3021
 
 
3022
 
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3023
 
 
3024
 
    def __init__(self, url):
3025
 
        BzrError.__init__(self, url=url)
3026
 
 
3027
 
 
3028
 
class UserAbort(BzrError):
3029
 
 
3030
 
    _fmt = 'The user aborted the operation.'
3031
 
 
3032
 
 
3033
 
class MustHaveWorkingTree(BzrError):
3034
 
 
3035
 
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3036
 
 
3037
 
    def __init__(self, format, url):
3038
 
        BzrError.__init__(self, format=format, url=url)
3039
 
 
3040
 
 
3041
 
class NoSuchView(BzrError):
3042
 
    """A view does not exist.
3043
 
    """
3044
 
 
3045
 
    _fmt = u"No such view: %(view_name)s."
3046
 
 
3047
 
    def __init__(self, view_name):
3048
 
        self.view_name = view_name
3049
 
 
3050
 
 
3051
 
class ViewsNotSupported(BzrError):
3052
 
    """Views are not supported by a tree format.
3053
 
    """
3054
 
 
3055
 
    _fmt = ("Views are not supported by %(tree)s;"
3056
 
            " use 'bzr upgrade' to change your tree to a later format.")
3057
 
 
3058
 
    def __init__(self, tree):
3059
 
        self.tree = tree
3060
 
 
3061
 
 
3062
 
class FileOutsideView(BzrError):
3063
 
 
3064
 
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
3065
 
            '%(view_str)s')
3066
 
 
3067
 
    def __init__(self, file_name, view_files):
3068
 
        self.file_name = file_name
3069
 
        self.view_str = ", ".join(view_files)
3070
 
 
3071
 
 
3072
 
class UnresumableWriteGroup(BzrError):
3073
 
 
3074
 
    _fmt = ("Repository %(repository)s cannot resume write group "
3075
 
            "%(write_groups)r: %(reason)s")
3076
 
 
3077
 
    internal_error = True
3078
 
 
3079
 
    def __init__(self, repository, write_groups, reason):
3080
 
        self.repository = repository
3081
 
        self.write_groups = write_groups
3082
 
        self.reason = reason
3083
 
 
3084
 
 
3085
 
class UnsuspendableWriteGroup(BzrError):
3086
 
 
3087
 
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
3088
 
 
3089
 
    internal_error = True
3090
 
 
3091
 
    def __init__(self, repository):
3092
 
        self.repository = repository
3093
 
 
3094
 
 
3095
 
class LossyPushToSameVCS(BzrError):
3096
 
 
3097
 
    _fmt = ("Lossy push not possible between %(source_branch)r and "
3098
 
            "%(target_branch)r that are in the same VCS.")
3099
 
 
3100
 
    internal_error = True
3101
 
 
3102
 
    def __init__(self, source_branch, target_branch):
3103
 
        self.source_branch = source_branch
3104
 
        self.target_branch = target_branch
3105
 
 
3106
 
 
3107
 
class NoRoundtrippingSupport(BzrError):
3108
 
 
3109
 
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
3110
 
            "%(target_branch)r.")
3111
 
 
3112
 
    internal_error = True
3113
 
 
3114
 
    def __init__(self, source_branch, target_branch):
3115
 
        self.source_branch = source_branch
3116
 
        self.target_branch = target_branch
3117
 
 
3118
 
 
3119
 
class FileTimestampUnavailable(BzrError):
3120
 
 
3121
 
    _fmt = "The filestamp for %(path)s is not available."
3122
 
 
3123
 
    internal_error = True
3124
 
 
3125
 
    def __init__(self, path):
3126
 
        self.path = path