~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

Merge bzr.dev and tree-file-ids-as-tuples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
20
 
 
21
 
from bzrlib import (
22
 
    osutils,
23
 
    symbol_versioning,
24
 
    )
25
 
from bzrlib.patches import (
26
 
    MalformedHunkHeader,
27
 
    MalformedLine,
28
 
    MalformedPatchHeader,
29
 
    PatchConflict,
30
 
    PatchSyntax,
31
 
    )
32
 
 
 
20
from __future__ import absolute_import
33
21
 
34
22
# TODO: is there any value in providing the .args field used by standard
35
 
# python exceptions?   A list of values with no names seems less useful 
 
23
# python exceptions?   A list of values with no names seems less useful
36
24
# to me.
37
25
 
38
 
# TODO: Perhaps convert the exception to a string at the moment it's 
 
26
# TODO: Perhaps convert the exception to a string at the moment it's
39
27
# constructed to make sure it will succeed.  But that says nothing about
40
28
# exceptions that are never raised.
41
29
 
55
43
    Base class for errors raised by bzrlib.
56
44
 
57
45
    :cvar internal_error: if True this was probably caused by a bzr bug and
58
 
    should be displayed with a traceback; if False (or absent) this was
59
 
    probably a user or environment error and they don't need the gory details.
60
 
    (That can be overridden by -Derror on the command line.)
 
46
        should be displayed with a traceback; if False (or absent) this was
 
47
        probably a user or environment error and they don't need the gory
 
48
        details.  (That can be overridden by -Derror on the command line.)
61
49
 
62
50
    :cvar _fmt: Format string to display the error; this is expanded
63
 
    by the instance's dict.
 
51
        by the instance's dict.
64
52
    """
65
 
    
 
53
 
66
54
    internal_error = False
67
55
 
68
56
    def __init__(self, msg=None, **kwds):
73
61
        arguments can be given.  The first is for generic "user" errors which
74
62
        are not intended to be caught and so do not need a specific subclass.
75
63
        The second case is for use with subclasses that provide a _fmt format
76
 
        string to print the arguments.  
 
64
        string to print the arguments.
77
65
 
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 
 
66
        Keyword arguments are taken as parameters to the error, which can
 
67
        be inserted into the format string template.  It's recommended
 
68
        that subclasses override the __init__ method to require specific
81
69
        parameters.
82
70
 
83
71
        :param msg: If given, this is the literal complete text for the error,
107
95
                # __str__() should always return a 'str' object
108
96
                # never a 'unicode' object.
109
97
                return s
110
 
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
111
 
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
112
 
                % (self.__class__.__name__,
113
 
                   self.__dict__,
114
 
                   getattr(self, '_fmt', None),
115
 
                   e)
 
98
        except Exception, e:
 
99
            pass # just bind to 'e' for formatting below
 
100
        else:
 
101
            e = None
 
102
        return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
103
            % (self.__class__.__name__,
 
104
               self.__dict__,
 
105
               getattr(self, '_fmt', None),
 
106
               e)
116
107
 
117
108
    def __unicode__(self):
118
109
        u = self._format()
134
125
            s = str(s)
135
126
        return s
136
127
 
 
128
    def __repr__(self):
 
129
        return '%s(%s)' % (self.__class__.__name__, str(self))
 
130
 
137
131
    def _get_format_string(self):
138
132
        """Return format string for this exception or None"""
139
133
        fmt = getattr(self, '_fmt', None)
140
134
        if fmt is not None:
141
 
            return fmt
142
 
        fmt = getattr(self, '__doc__', None)
143
 
        if fmt is not None:
144
 
            symbol_versioning.warn("%s uses its docstring as a format, "
145
 
                    "it should use _fmt instead" % self.__class__.__name__,
146
 
                    DeprecationWarning)
147
 
            return fmt
148
 
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
149
 
            % (self.__class__.__name__,
150
 
               self.__dict__,
151
 
               getattr(self, '_fmt', None),
152
 
               )
 
135
            from bzrlib.i18n import gettext
 
136
            return gettext(unicode(fmt)) # _fmt strings should be ascii
153
137
 
154
138
    def __eq__(self, other):
155
 
        if self.__class__ != other.__class__:
 
139
        if self.__class__ is not other.__class__:
156
140
            return NotImplemented
157
141
        return self.__dict__ == other.__dict__
158
142
 
168
152
    internal_error = True
169
153
 
170
154
 
171
 
class BzrNewError(BzrError):
172
 
    """Deprecated error base class."""
173
 
    # base classes should override the docstring with their human-
174
 
    # readable explanation
175
 
 
176
 
    def __init__(self, *args, **kwds):
177
 
        # XXX: Use the underlying BzrError to always generate the args
178
 
        # attribute if it doesn't exist.  We can't use super here, because
179
 
        # exceptions are old-style classes in python2.4 (but new in 2.5).
180
 
        # --bmc, 20060426
181
 
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
182
 
             'please convert %s to use BzrError instead'
183
 
             % self.__class__.__name__,
184
 
             DeprecationWarning,
185
 
             stacklevel=2)
186
 
        BzrError.__init__(self, *args)
187
 
        for key, value in kwds.items():
188
 
            setattr(self, key, value)
189
 
 
190
 
    def __str__(self):
191
 
        try:
192
 
            # __str__() should always return a 'str' object
193
 
            # never a 'unicode' object.
194
 
            s = self.__doc__ % self.__dict__
195
 
            if isinstance(s, unicode):
196
 
                return s.encode('utf8')
197
 
            return s
198
 
        except (TypeError, NameError, ValueError, KeyError), e:
199
 
            return 'Unprintable exception %s(%r): %r' \
200
 
                % (self.__class__.__name__,
201
 
                   self.__dict__, e)
202
 
 
203
 
 
204
155
class AlreadyBuilding(BzrError):
205
156
 
206
157
    _fmt = "The tree builder is already building a tree."
263
214
 
264
215
 
265
216
class InvalidEntryName(InternalBzrError):
266
 
    
 
217
 
267
218
    _fmt = "Invalid entry name: %(name)s"
268
219
 
269
220
    def __init__(self, name):
272
223
 
273
224
 
274
225
class InvalidRevisionNumber(BzrError):
275
 
    
 
226
 
276
227
    _fmt = "Invalid revision number %(revno)s"
277
228
 
278
229
    def __init__(self, revno):
302
253
class RootMissing(InternalBzrError):
303
254
 
304
255
    _fmt = ("The root entry of a tree must be the first entry supplied to "
305
 
        "record_entry_contents.")
 
256
        "the commit builder.")
306
257
 
307
258
 
308
259
class NoPublicBranch(BzrError):
327
278
class NoSuchId(BzrError):
328
279
 
329
280
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
330
 
    
 
281
 
331
282
    def __init__(self, tree, file_id):
332
283
        BzrError.__init__(self)
333
284
        self.file_id = file_id
360
311
class NoWorkingTree(BzrError):
361
312
 
362
313
    _fmt = 'No WorkingTree exists for "%(base)s".'
363
 
    
 
314
 
364
315
    def __init__(self, base):
365
316
        BzrError.__init__(self)
366
317
        self.base = base
475
426
    def __init__(self, name, value):
476
427
        BzrError.__init__(self, name=name, value=value)
477
428
 
478
 
    
 
429
 
479
430
class StrictCommitFailed(BzrError):
480
431
 
481
432
    _fmt = "Commit refused because there are unknown files in the tree"
484
435
# XXX: Should be unified with TransportError; they seem to represent the
485
436
# same thing
486
437
# RBC 20060929: I think that unifiying with TransportError would be a mistake
487
 
# - this is finer than a TransportError - and more useful as such. It 
 
438
# - this is finer than a TransportError - and more useful as such. It
488
439
# differentiates between 'transport has failed' and 'operation on a transport
489
440
# has failed.'
490
441
class PathError(BzrError):
491
 
    
 
442
 
492
443
    _fmt = "Generic path error: %(path)r%(extra)s)"
493
444
 
494
445
    def __init__(self, path, extra=None):
548
499
 
549
500
 
550
501
class ReadingCompleted(InternalBzrError):
551
 
    
 
502
 
552
503
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
553
504
            "called upon it - the request has been completed and no more "
554
505
            "data may be read.")
619
570
 
620
571
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
621
572
 
622
 
    def __init__(self, url, extra):
 
573
    def __init__(self, url, extra=""):
623
574
        PathError.__init__(self, url, extra=extra)
624
575
 
625
576
 
634
585
        self.url = url
635
586
 
636
587
 
 
588
class UnstackableLocationError(BzrError):
 
589
 
 
590
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
 
591
 
 
592
    def __init__(self, branch_url, target_url):
 
593
        BzrError.__init__(self)
 
594
        self.branch_url = branch_url
 
595
        self.target_url = target_url
 
596
 
 
597
 
637
598
class UnstackableRepositoryFormat(BzrError):
638
599
 
639
600
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
646
607
 
647
608
 
648
609
class ReadError(PathError):
649
 
    
 
610
 
650
611
    _fmt = """Error reading from %(path)r."""
651
612
 
652
613
 
668
629
 
669
630
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
670
631
 
671
 
    internal_error = True
 
632
    internal_error = False
672
633
 
673
634
    def __init__(self, path, base, extra=None):
674
635
        BzrError.__init__(self)
687
648
 
688
649
# TODO: This is given a URL; we try to unescape it but doing that from inside
689
650
# the exception object is a bit undesirable.
690
 
# TODO: Probably this behavior of should be a common superclass 
 
651
# TODO: Probably this behavior of should be a common superclass
691
652
class NotBranchError(PathError):
692
653
 
693
 
    _fmt = 'Not a branch: "%(path)s".'
 
654
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
694
655
 
695
 
    def __init__(self, path):
 
656
    def __init__(self, path, detail=None, bzrdir=None):
696
657
       import bzrlib.urlutils as urlutils
697
 
       self.path = urlutils.unescape_for_display(path, 'ascii')
 
658
       path = urlutils.unescape_for_display(path, 'ascii')
 
659
       if detail is not None:
 
660
           detail = ': ' + detail
 
661
       self.detail = detail
 
662
       self.bzrdir = bzrdir
 
663
       PathError.__init__(self, path=path)
 
664
 
 
665
    def __repr__(self):
 
666
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
 
667
 
 
668
    def _format(self):
 
669
        # XXX: Ideally self.detail would be a property, but Exceptions in
 
670
        # Python 2.4 have to be old-style classes so properties don't work.
 
671
        # Instead we override _format.
 
672
        if self.detail is None:
 
673
            if self.bzrdir is not None:
 
674
                try:
 
675
                    self.bzrdir.open_repository()
 
676
                except NoRepositoryPresent:
 
677
                    self.detail = ''
 
678
                except Exception:
 
679
                    # Just ignore unexpected errors.  Raising arbitrary errors
 
680
                    # during str(err) can provoke strange bugs.  Concretely
 
681
                    # Launchpad's codehosting managed to raise NotBranchError
 
682
                    # here, and then get stuck in an infinite loop/recursion
 
683
                    # trying to str() that error.  All this error really cares
 
684
                    # about that there's no working repository there, and if
 
685
                    # open_repository() fails, there probably isn't.
 
686
                    self.detail = ''
 
687
                else:
 
688
                    self.detail = ': location is a repository'
 
689
            else:
 
690
                self.detail = ''
 
691
        return PathError._format(self)
698
692
 
699
693
 
700
694
class NoSubmitBranch(PathError):
706
700
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
707
701
 
708
702
 
 
703
class AlreadyControlDirError(PathError):
 
704
 
 
705
    _fmt = 'A control directory already exists: "%(path)s".'
 
706
 
 
707
 
709
708
class AlreadyBranchError(PathError):
710
709
 
711
710
    _fmt = 'Already a branch: "%(path)s".'
745
744
        self.path = bzrdir.transport.clone('..').base
746
745
 
747
746
 
748
 
class FileInWrongBranch(BzrError):
749
 
 
750
 
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
751
 
 
752
 
    def __init__(self, branch, path):
753
 
        BzrError.__init__(self)
754
 
        self.branch = branch
755
 
        self.branch_base = branch.base
756
 
        self.path = path
757
 
 
758
 
 
759
747
class UnsupportedFormatError(BzrError):
760
748
 
761
749
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
762
750
 
763
751
 
764
752
class UnknownFormatError(BzrError):
765
 
    
 
753
 
766
754
    _fmt = "Unknown %(kind)s format: %(format)r"
767
755
 
768
756
    def __init__(self, format, kind='branch'):
771
759
 
772
760
 
773
761
class IncompatibleFormat(BzrError):
774
 
    
 
762
 
775
763
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
776
764
 
777
765
    def __init__(self, format, bzrdir_format):
780
768
        self.bzrdir = bzrdir_format
781
769
 
782
770
 
 
771
class ParseFormatError(BzrError):
 
772
 
 
773
    _fmt = "Parse error on line %(lineno)d of %(format)s format: %(line)s"
 
774
 
 
775
    def __init__(self, format, lineno, line, text):
 
776
        BzrError.__init__(self)
 
777
        self.format = format
 
778
        self.lineno = lineno
 
779
        self.line = line
 
780
        self.text = text
 
781
 
 
782
 
783
783
class IncompatibleRepositories(BzrError):
 
784
    """Report an error that two repositories are not compatible.
 
785
 
 
786
    Note that the source and target repositories are permitted to be strings:
 
787
    this exception is thrown from the smart server and may refer to a
 
788
    repository the client hasn't opened.
 
789
    """
784
790
 
785
791
    _fmt = "%(target)s\n" \
786
792
            "is not compatible with\n" \
794
800
 
795
801
 
796
802
class IncompatibleRevision(BzrError):
797
 
    
 
803
 
798
804
    _fmt = "Revision is not compatible with %(repo_format)s"
799
805
 
800
806
    def __init__(self, repo_format):
811
817
        """Construct a new AlreadyVersionedError.
812
818
 
813
819
        :param path: This is the path which is versioned,
814
 
        which should be in a user friendly form.
 
820
            which should be in a user friendly form.
815
821
        :param context_info: If given, this is information about the context,
816
 
        which could explain why this is expected to not be versioned.
 
822
            which could explain why this is expected to not be versioned.
817
823
        """
818
824
        BzrError.__init__(self)
819
825
        self.path = path
832
838
        """Construct a new NotVersionedError.
833
839
 
834
840
        :param path: This is the path which is not versioned,
835
 
        which should be in a user friendly form.
 
841
            which should be in a user friendly form.
836
842
        :param context_info: If given, this is information about the context,
837
 
        which could explain why this is expected to be versioned.
 
843
            which could explain why this is expected to be versioned.
838
844
        """
839
845
        BzrError.__init__(self)
840
846
        self.path = path
908
914
    # original exception is available as e.original_error
909
915
    #
910
916
    # New code should prefer to raise specific subclasses
911
 
    def __init__(self, message):
912
 
        # Python 2.5 uses a slot for StandardError.message,
913
 
        # so use a different variable name.  We now work around this in
914
 
        # BzrError.__str__, but this member name is kept for compatability.
915
 
        self.msg = message
 
917
    def __init__(self, msg):
 
918
        self.msg = msg
916
919
 
917
920
 
918
921
class LockActive(LockError):
1001
1004
 
1002
1005
class LockContention(LockError):
1003
1006
 
1004
 
    _fmt = 'Could not acquire lock "%(lock)s"'
1005
 
    # TODO: show full url for lock, combining the transport and relative
1006
 
    # bits?
 
1007
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
1007
1008
 
1008
1009
    internal_error = False
1009
1010
 
1010
 
    def __init__(self, lock):
 
1011
    def __init__(self, lock, msg=''):
1011
1012
        self.lock = lock
 
1013
        self.msg = msg
1012
1014
 
1013
1015
 
1014
1016
class LockBroken(LockError):
1035
1037
        self.target = target
1036
1038
 
1037
1039
 
 
1040
class LockCorrupt(LockError):
 
1041
 
 
1042
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
 
1043
            "Use 'bzr break-lock' to clear it")
 
1044
 
 
1045
    internal_error = False
 
1046
 
 
1047
    def __init__(self, corruption_info, file_data=None):
 
1048
        self.corruption_info = corruption_info
 
1049
        self.file_data = file_data
 
1050
 
 
1051
 
1038
1052
class LockNotHeld(LockError):
1039
1053
 
1040
1054
    _fmt = "Lock not held: %(lock)s"
1079
1093
        BzrError.__init__(self, files=files, files_str=files_str)
1080
1094
 
1081
1095
 
 
1096
class ExcludesUnsupported(BzrError):
 
1097
 
 
1098
    _fmt = ('Excluding paths during commit is not supported by '
 
1099
            'repository at %(repository)r.')
 
1100
 
 
1101
    def __init__(self, repository):
 
1102
        BzrError.__init__(self, repository=repository)
 
1103
 
 
1104
 
1082
1105
class BadCommitMessageEncoding(BzrError):
1083
1106
 
1084
1107
    _fmt = 'The specified commit message contains characters unsupported by '\
1128
1151
 
1129
1152
class NoSuchRevisionInTree(NoSuchRevision):
1130
1153
    """When using Tree.revision_tree, and the revision is not accessible."""
1131
 
    
 
1154
 
1132
1155
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1133
1156
 
1134
1157
    def __init__(self, tree, revision_id):
1139
1162
 
1140
1163
class InvalidRevisionSpec(BzrError):
1141
1164
 
1142
 
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
1143
 
            " %(branch)s%(extra)s")
 
1165
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
 
1166
            " %(branch_url)s%(extra)s")
1144
1167
 
1145
1168
    def __init__(self, spec, branch, extra=None):
1146
1169
        BzrError.__init__(self, branch=branch, spec=spec)
 
1170
        self.branch_url = getattr(branch, 'user_url', str(branch))
1147
1171
        if extra:
1148
1172
            self.extra = '\n' + str(extra)
1149
1173
        else:
1150
1174
            self.extra = ''
1151
1175
 
1152
1176
 
1153
 
class HistoryMissing(BzrError):
1154
 
 
1155
 
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
1156
 
 
1157
 
 
1158
1177
class AppendRevisionsOnlyViolation(BzrError):
1159
1178
 
1160
1179
    _fmt = ('Operation denied because it would change the main history,'
1170
1189
class DivergedBranches(BzrError):
1171
1190
 
1172
1191
    _fmt = ("These branches have diverged."
1173
 
            " Use the merge command to reconcile them.")
 
1192
            " Use the missing command to see how.\n"
 
1193
            "Use the merge command to reconcile them.")
1174
1194
 
1175
1195
    def __init__(self, branch1, branch2):
1176
1196
        self.branch1 = branch1
1198
1218
 
1199
1219
 
1200
1220
class NoCommonAncestor(BzrError):
1201
 
    
 
1221
 
1202
1222
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1203
1223
 
1204
1224
    def __init__(self, revision_a, revision_b):
1224
1244
            not_ancestor_id=not_ancestor_id)
1225
1245
 
1226
1246
 
1227
 
class InstallFailed(BzrError):
1228
 
 
1229
 
    def __init__(self, revisions):
1230
 
        revision_str = ", ".join(str(r) for r in revisions)
1231
 
        msg = "Could not install revisions:\n%s" % revision_str
1232
 
        BzrError.__init__(self, msg)
1233
 
        self.revisions = revisions
1234
 
 
1235
 
 
1236
 
class AmbiguousBase(BzrError):
1237
 
 
1238
 
    def __init__(self, bases):
1239
 
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
1240
 
                DeprecationWarning)
1241
 
        msg = ("The correct base is unclear, because %s are all equally close"
1242
 
                % ", ".join(bases))
1243
 
        BzrError.__init__(self, msg)
1244
 
        self.bases = bases
1245
 
 
1246
 
 
1247
1247
class NoCommits(BranchError):
1248
1248
 
1249
1249
    _fmt = "Branch %(branch)s has no commits."
1265
1265
class BoundBranchOutOfDate(BzrError):
1266
1266
 
1267
1267
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1268
 
            " %(master)s.")
 
1268
            " %(master)s.%(extra_help)s")
1269
1269
 
1270
1270
    def __init__(self, branch, master):
1271
1271
        BzrError.__init__(self)
1272
1272
        self.branch = branch
1273
1273
        self.master = master
1274
 
 
1275
 
        
 
1274
        self.extra_help = ''
 
1275
 
 
1276
 
1276
1277
class CommitToDoubleBoundBranch(BzrError):
1277
1278
 
1278
1279
    _fmt = ("Cannot commit to branch %(branch)s."
1347
1348
 
1348
1349
class WeaveParentMismatch(WeaveError):
1349
1350
 
1350
 
    _fmt = "Parents are mismatched between two revisions. %(message)s"
1351
 
    
 
1351
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
 
1352
 
1352
1353
 
1353
1354
class WeaveInvalidChecksum(WeaveError):
1354
1355
 
1355
 
    _fmt = "Text did not match it's checksum: %(message)s"
 
1356
    _fmt = "Text did not match its checksum: %(msg)s"
1356
1357
 
1357
1358
 
1358
1359
class WeaveTextDiffers(WeaveError):
1380
1381
 
1381
1382
 
1382
1383
class VersionedFileError(BzrError):
1383
 
    
 
1384
 
1384
1385
    _fmt = "Versioned file error"
1385
1386
 
1386
1387
 
1387
1388
class RevisionNotPresent(VersionedFileError):
1388
 
    
 
1389
 
1389
1390
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1390
1391
 
1391
1392
    def __init__(self, revision_id, file_id):
1395
1396
 
1396
1397
 
1397
1398
class RevisionAlreadyPresent(VersionedFileError):
1398
 
    
 
1399
 
1399
1400
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1400
1401
 
1401
1402
    def __init__(self, revision_id, file_id):
1406
1407
 
1407
1408
class VersionedFileInvalidChecksum(VersionedFileError):
1408
1409
 
1409
 
    _fmt = "Text did not match its checksum: %(message)s"
 
1410
    _fmt = "Text did not match its checksum: %(msg)s"
1410
1411
 
1411
1412
 
1412
1413
class KnitError(InternalBzrError):
1413
 
    
 
1414
 
1414
1415
    _fmt = "Knit error"
1415
1416
 
1416
1417
 
1424
1425
        self.how = how
1425
1426
 
1426
1427
 
 
1428
class SHA1KnitCorrupt(KnitCorrupt):
 
1429
 
 
1430
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
 
1431
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
 
1432
        "sha %(actual)s")
 
1433
 
 
1434
    def __init__(self, filename, actual, expected, key, content):
 
1435
        KnitError.__init__(self)
 
1436
        self.filename = filename
 
1437
        self.actual = actual
 
1438
        self.expected = expected
 
1439
        self.key = key
 
1440
        self.content = content
 
1441
 
 
1442
 
1427
1443
class KnitDataStreamIncompatible(KnitError):
1428
1444
    # Not raised anymore, as we can convert data streams.  In future we may
1429
1445
    # need it again for more exotic cases, so we're keeping it around for now.
1433
1449
    def __init__(self, stream_format, target_format):
1434
1450
        self.stream_format = stream_format
1435
1451
        self.target_format = target_format
1436
 
        
 
1452
 
1437
1453
 
1438
1454
class KnitDataStreamUnknown(KnitError):
1439
1455
    # Indicates a data stream we don't know how to handle.
1442
1458
 
1443
1459
    def __init__(self, stream_format):
1444
1460
        self.stream_format = stream_format
1445
 
        
 
1461
 
1446
1462
 
1447
1463
class KnitHeaderError(KnitError):
1448
1464
 
1458
1474
 
1459
1475
    Currently only 'fulltext' and 'line-delta' are supported.
1460
1476
    """
1461
 
    
 
1477
 
1462
1478
    _fmt = ("Knit index %(filename)s does not have a known method"
1463
1479
            " in options: %(options)r")
1464
1480
 
1468
1484
        self.options = options
1469
1485
 
1470
1486
 
 
1487
class RetryWithNewPacks(BzrError):
 
1488
    """Raised when we realize that the packs on disk have changed.
 
1489
 
 
1490
    This is meant as more of a signaling exception, to trap between where a
 
1491
    local error occurred and the code that can actually handle the error and
 
1492
    code that can retry appropriately.
 
1493
    """
 
1494
 
 
1495
    internal_error = True
 
1496
 
 
1497
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
 
1498
            " %(orig_error)s")
 
1499
 
 
1500
    def __init__(self, context, reload_occurred, exc_info):
 
1501
        """create a new RetryWithNewPacks error.
 
1502
 
 
1503
        :param reload_occurred: Set to True if we know that the packs have
 
1504
            already been reloaded, and we are failing because of an in-memory
 
1505
            cache miss. If set to True then we will ignore if a reload says
 
1506
            nothing has changed, because we assume it has already reloaded. If
 
1507
            False, then a reload with nothing changed will force an error.
 
1508
        :param exc_info: The original exception traceback, so if there is a
 
1509
            problem we can raise the original error (value from sys.exc_info())
 
1510
        """
 
1511
        BzrError.__init__(self)
 
1512
        self.context = context
 
1513
        self.reload_occurred = reload_occurred
 
1514
        self.exc_info = exc_info
 
1515
        self.orig_error = exc_info[1]
 
1516
        # TODO: The global error handler should probably treat this by
 
1517
        #       raising/printing the original exception with a bit about
 
1518
        #       RetryWithNewPacks also not being caught
 
1519
 
 
1520
 
 
1521
class RetryAutopack(RetryWithNewPacks):
 
1522
    """Raised when we are autopacking and we find a missing file.
 
1523
 
 
1524
    Meant as a signaling exception, to tell the autopack code it should try
 
1525
    again.
 
1526
    """
 
1527
 
 
1528
    internal_error = True
 
1529
 
 
1530
    _fmt = ("Pack files have changed, reload and try autopack again."
 
1531
            " context: %(context)s %(orig_error)s")
 
1532
 
 
1533
 
1471
1534
class NoSuchExportFormat(BzrError):
1472
 
    
 
1535
 
1473
1536
    _fmt = "Export format %(format)r not supported"
1474
1537
 
1475
1538
    def __init__(self, format):
1478
1541
 
1479
1542
 
1480
1543
class TransportError(BzrError):
1481
 
    
 
1544
 
1482
1545
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1483
1546
 
1484
1547
    def __init__(self, msg=None, orig_error=None):
1529
1592
 
1530
1593
class SmartMessageHandlerError(InternalBzrError):
1531
1594
 
1532
 
    _fmt = "The message handler raised an exception: %(exc_value)s."
 
1595
    _fmt = ("The message handler raised an exception:\n"
 
1596
            "%(traceback_text)s")
1533
1597
 
1534
1598
    def __init__(self, exc_info):
1535
 
        self.exc_type, self.exc_value, self.tb = exc_info
1536
 
        
 
1599
        import traceback
 
1600
        # GZ 2010-08-10: Cycle with exc_tb/exc_info affects at least one test
 
1601
        self.exc_type, self.exc_value, self.exc_tb = exc_info
 
1602
        self.exc_info = exc_info
 
1603
        traceback_strings = traceback.format_exception(
 
1604
                self.exc_type, self.exc_value, self.exc_tb)
 
1605
        self.traceback_text = ''.join(traceback_strings)
 
1606
 
1537
1607
 
1538
1608
# A set of semi-meaningful errors which can be thrown
1539
1609
class TransportNotPossible(TransportError):
1565
1635
            self.port = ':%s' % port
1566
1636
 
1567
1637
 
 
1638
# XXX: This is also used for unexpected end of file, which is different at the
 
1639
# TCP level from "connection reset".
1568
1640
class ConnectionReset(TransportError):
1569
1641
 
1570
1642
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1571
1643
 
1572
1644
 
 
1645
class ConnectionTimeout(ConnectionError):
 
1646
 
 
1647
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
 
1648
 
 
1649
 
1573
1650
class InvalidRange(TransportError):
1574
1651
 
1575
1652
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1582
1659
 
1583
1660
class InvalidHttpResponse(TransportError):
1584
1661
 
1585
 
    _fmt = "Invalid http response for %(path)s: %(msg)s"
 
1662
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
1586
1663
 
1587
1664
    def __init__(self, path, msg, orig_error=None):
1588
1665
        self.path = path
 
1666
        if orig_error is None:
 
1667
            orig_error = ''
 
1668
        else:
 
1669
            # This is reached for obscure and unusual errors so we want to
 
1670
            # preserve as much info as possible to ease debug.
 
1671
            orig_error = ': %r' % (orig_error,)
1589
1672
        TransportError.__init__(self, msg, orig_error=orig_error)
1590
1673
 
1591
1674
 
 
1675
class CertificateError(TransportError):
 
1676
 
 
1677
    _fmt = "Certificate error: %(error)s"
 
1678
 
 
1679
    def __init__(self, error):
 
1680
        self.error = error
 
1681
 
 
1682
 
1592
1683
class InvalidHttpRange(InvalidHttpResponse):
1593
1684
 
1594
1685
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1598
1689
        InvalidHttpResponse.__init__(self, path, msg)
1599
1690
 
1600
1691
 
 
1692
class HttpBoundaryMissing(InvalidHttpResponse):
 
1693
    """A multipart response ends with no boundary marker.
 
1694
 
 
1695
    This is a special case caused by buggy proxies, described in
 
1696
    <https://bugs.launchpad.net/bzr/+bug/198646>.
 
1697
    """
 
1698
 
 
1699
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
 
1700
 
 
1701
    def __init__(self, path, msg):
 
1702
        InvalidHttpResponse.__init__(self, path, msg)
 
1703
 
 
1704
 
1601
1705
class InvalidHttpContentType(InvalidHttpResponse):
1602
1706
 
1603
1707
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1611
1715
 
1612
1716
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1613
1717
 
1614
 
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
 
1718
    def __init__(self, source, target, is_permanent=False):
1615
1719
        self.source = source
1616
1720
        self.target = target
1617
1721
        if is_permanent:
1618
1722
            self.permanently = ' permanently'
1619
1723
        else:
1620
1724
            self.permanently = ''
1621
 
        self._qualified_proto = qual_proto
1622
1725
        TransportError.__init__(self)
1623
1726
 
1624
 
    def _requalify_url(self, url):
1625
 
        """Restore the qualified proto in front of the url"""
1626
 
        # When this exception is raised, source and target are in
1627
 
        # user readable format. But some transports may use a
1628
 
        # different proto (http+urllib:// will present http:// to
1629
 
        # the user. If a qualified proto is specified, the code
1630
 
        # trapping the exception can get the qualified urls to
1631
 
        # properly handle the redirection themself (creating a
1632
 
        # new transport object from the target url for example).
1633
 
        # But checking that the scheme of the original and
1634
 
        # redirected urls are the same can be tricky. (see the
1635
 
        # FIXME in BzrDir.open_from_transport for the unique use
1636
 
        # case so far).
1637
 
        if self._qualified_proto is None:
1638
 
            return url
1639
 
 
1640
 
        # The TODO related to NotBranchError mention that doing
1641
 
        # that kind of manipulation on the urls may not be the
1642
 
        # exception object job. On the other hand, this object is
1643
 
        # the interface between the code and the user so
1644
 
        # presenting the urls in different ways is indeed its
1645
 
        # job...
1646
 
        import urlparse
1647
 
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1648
 
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1649
 
                                   query, fragment))
1650
 
 
1651
 
    def get_source_url(self):
1652
 
        return self._requalify_url(self.source)
1653
 
 
1654
 
    def get_target_url(self):
1655
 
        return self._requalify_url(self.target)
1656
 
 
1657
1727
 
1658
1728
class TooManyRedirections(TransportError):
1659
1729
 
1665
1735
    _fmt = "Working tree has conflicts."
1666
1736
 
1667
1737
 
 
1738
class ConfigContentError(BzrError):
 
1739
 
 
1740
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
 
1741
 
 
1742
    def __init__(self, filename):
 
1743
        BzrError.__init__(self)
 
1744
        self.filename = filename
 
1745
 
 
1746
 
1668
1747
class ParseConfigError(BzrError):
1669
1748
 
 
1749
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
 
1750
 
1670
1751
    def __init__(self, errors, filename):
1671
 
        if filename is None:
1672
 
            filename = ""
1673
 
        message = "Error(s) parsing config file %s:\n%s" % \
1674
 
            (filename, ('\n'.join(e.msg for e in errors)))
1675
 
        BzrError.__init__(self, message)
 
1752
        BzrError.__init__(self)
 
1753
        self.filename = filename
 
1754
        self.errors = '\n'.join(e.msg for e in errors)
 
1755
 
 
1756
 
 
1757
class ConfigOptionValueError(BzrError):
 
1758
 
 
1759
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
1760
 
 
1761
    def __init__(self, name, value):
 
1762
        BzrError.__init__(self, name=name, value=value)
1676
1763
 
1677
1764
 
1678
1765
class NoEmailInUsername(BzrError):
1686
1773
 
1687
1774
class SigningFailed(BzrError):
1688
1775
 
1689
 
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
 
1776
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
1690
1777
 
1691
1778
    def __init__(self, command_line):
1692
1779
        BzrError.__init__(self, command_line=command_line)
1693
1780
 
1694
1781
 
 
1782
class SignatureVerificationFailed(BzrError):
 
1783
 
 
1784
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
 
1785
 
 
1786
    def __init__(self, error):
 
1787
        BzrError.__init__(self, error=error)
 
1788
 
 
1789
 
 
1790
class DependencyNotPresent(BzrError):
 
1791
 
 
1792
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1793
 
 
1794
    def __init__(self, library, error):
 
1795
        BzrError.__init__(self, library=library, error=error)
 
1796
 
 
1797
 
 
1798
class GpgmeNotInstalled(DependencyNotPresent):
 
1799
 
 
1800
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
 
1801
 
 
1802
    def __init__(self, error):
 
1803
        DependencyNotPresent.__init__(self, 'gpgme', error)
 
1804
 
 
1805
 
1695
1806
class WorkingTreeNotRevision(BzrError):
1696
1807
 
1697
 
    _fmt = ("The working tree for %(basedir)s has changed since" 
 
1808
    _fmt = ("The working tree for %(basedir)s has changed since"
1698
1809
            " the last commit, but weave merge requires that it be"
1699
1810
            " unchanged")
1700
1811
 
1813
1924
        self.prefix = prefix
1814
1925
 
1815
1926
 
1816
 
class MalformedTransform(BzrError):
 
1927
class MalformedTransform(InternalBzrError):
1817
1928
 
1818
1929
    _fmt = "Tree transform is malformed %(conflicts)r"
1819
1930
 
1857
1968
    _fmt = "Moving the root directory is not supported at this time"
1858
1969
 
1859
1970
 
 
1971
class TransformRenameFailed(BzrError):
 
1972
 
 
1973
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
 
1974
 
 
1975
    def __init__(self, from_path, to_path, why, errno):
 
1976
        self.from_path = from_path
 
1977
        self.to_path = to_path
 
1978
        self.why = why
 
1979
        self.errno = errno
 
1980
 
 
1981
 
1860
1982
class BzrMoveFailedError(BzrError):
1861
1983
 
1862
 
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1984
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
 
1985
        "%(_has_extra)s%(extra)s")
1863
1986
 
1864
1987
    def __init__(self, from_path='', to_path='', extra=None):
1865
1988
        from bzrlib.osutils import splitpath
1866
1989
        BzrError.__init__(self)
1867
1990
        if extra:
1868
 
            self.extra = ': ' + str(extra)
 
1991
            self.extra, self._has_extra = extra, ': '
1869
1992
        else:
1870
 
            self.extra = ''
 
1993
            self.extra = self._has_extra = ''
1871
1994
 
1872
1995
        has_from = len(from_path) > 0
1873
1996
        has_to = len(to_path) > 0
1894
2017
 
1895
2018
class BzrRenameFailedError(BzrMoveFailedError):
1896
2019
 
1897
 
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
2020
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
 
2021
        "%(_has_extra)s%(extra)s")
1898
2022
 
1899
2023
    def __init__(self, from_path, to_path, extra=None):
1900
2024
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1901
2025
 
1902
 
class BzrRemoveChangedFilesError(BzrError):
1903
 
    """Used when user is trying to remove changed files."""
1904
 
 
1905
 
    _fmt = ("Can't safely remove modified or unknown files:\n"
1906
 
        "%(changes_as_text)s"
1907
 
        "Use --keep to not delete them, or --force to delete them regardless.")
1908
 
 
1909
 
    def __init__(self, tree_delta):
1910
 
        BzrError.__init__(self)
1911
 
        self.changes_as_text = tree_delta.get_changes_as_text()
1912
 
        #self.paths_as_string = '\n'.join(changed_files)
1913
 
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
1914
 
 
1915
2026
 
1916
2027
class BzrBadParameterNotString(BzrBadParameter):
1917
2028
 
1920
2031
 
1921
2032
class BzrBadParameterMissing(BzrBadParameter):
1922
2033
 
1923
 
    _fmt = "Parameter $(param)s is required but not present."
 
2034
    _fmt = "Parameter %(param)s is required but not present."
1924
2035
 
1925
2036
 
1926
2037
class BzrBadParameterUnicode(BzrBadParameter):
1934
2045
    _fmt = "Parameter %(param)s contains a newline."
1935
2046
 
1936
2047
 
1937
 
class DependencyNotPresent(BzrError):
1938
 
 
1939
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1940
 
 
1941
 
    def __init__(self, library, error):
1942
 
        BzrError.__init__(self, library=library, error=error)
1943
 
 
1944
 
 
1945
2048
class ParamikoNotPresent(DependencyNotPresent):
1946
2049
 
1947
2050
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1966
2069
 
1967
2070
class BadConversionTarget(BzrError):
1968
2071
 
1969
 
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
 
2072
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
 
2073
            "    %(problem)s"
1970
2074
 
1971
 
    def __init__(self, problem, format):
 
2075
    def __init__(self, problem, format, from_format=None):
1972
2076
        BzrError.__init__(self)
1973
2077
        self.problem = problem
1974
2078
        self.format = format
 
2079
        self.from_format = from_format or '(unspecified)'
1975
2080
 
1976
2081
 
1977
2082
class NoDiffFound(BzrError):
2014
2119
    _fmt = """This tree contains left-over files from a failed operation.
2015
2120
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2016
2121
    keep, and delete it when you are done."""
2017
 
    
 
2122
 
2018
2123
    def __init__(self, limbo_dir):
2019
2124
       BzrError.__init__(self)
2020
2125
       self.limbo_dir = limbo_dir
2053
2158
 
2054
2159
class OutOfDateTree(BzrError):
2055
2160
 
2056
 
    _fmt = "Working tree is out of date, please run 'bzr update'."
 
2161
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
2057
2162
 
2058
 
    def __init__(self, tree):
 
2163
    def __init__(self, tree, more=None):
 
2164
        if more is None:
 
2165
            more = ''
 
2166
        else:
 
2167
            more = ' ' + more
2059
2168
        BzrError.__init__(self)
2060
2169
        self.tree = tree
 
2170
        self.more = more
2061
2171
 
2062
2172
 
2063
2173
class PublicBranchOutOfDate(BzrError):
2101
2211
 
2102
2212
    def __init__(self, repo):
2103
2213
        BzrError.__init__(self)
2104
 
        self.repo_path = repo.bzrdir.root_transport.base
 
2214
        self.repo_path = repo.user_url
2105
2215
 
2106
2216
 
2107
2217
class InconsistentDelta(BzrError):
2117
2227
        self.reason = reason
2118
2228
 
2119
2229
 
 
2230
class InconsistentDeltaDelta(InconsistentDelta):
 
2231
    """Used when we get a delta that is not valid."""
 
2232
 
 
2233
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
 
2234
            "\nreason: %(reason)s")
 
2235
 
 
2236
    def __init__(self, delta, reason):
 
2237
        BzrError.__init__(self)
 
2238
        self.delta = delta
 
2239
        self.reason = reason
 
2240
 
 
2241
 
2120
2242
class UpgradeRequired(BzrError):
2121
2243
 
2122
2244
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2131
2253
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2132
2254
 
2133
2255
 
 
2256
class RichRootUpgradeRequired(UpgradeRequired):
 
2257
 
 
2258
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
 
2259
           " a format which supports rich roots.")
 
2260
 
 
2261
 
2134
2262
class LocalRequiresBoundBranch(BzrError):
2135
2263
 
2136
2264
    _fmt = "Cannot perform local-only commits on unbound branches."
2137
2265
 
2138
2266
 
2139
 
class MissingProgressBarFinish(BzrError):
2140
 
 
2141
 
    _fmt = "A nested progress bar was not 'finished' correctly."
2142
 
 
2143
 
 
2144
 
class InvalidProgressBarType(BzrError):
2145
 
 
2146
 
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
2147
 
            " is not a supported type Select one of: %(valid_types)s")
2148
 
 
2149
 
    def __init__(self, bar_type, valid_types):
2150
 
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
2151
 
 
2152
 
 
2153
2267
class UnsupportedOperation(BzrError):
2154
2268
 
2155
2269
    _fmt = ("The method %(mname)s is not supported on"
2171
2285
    """
2172
2286
 
2173
2287
 
 
2288
class GhostTagsNotSupported(BzrError):
 
2289
 
 
2290
    _fmt = "Ghost tags not supported by format %(format)r."
 
2291
 
 
2292
    def __init__(self, format):
 
2293
        self.format = format
 
2294
 
 
2295
 
2174
2296
class BinaryFile(BzrError):
2175
 
    
 
2297
 
2176
2298
    _fmt = "File is binary but should be text."
2177
2299
 
2178
2300
 
2198
2320
 
2199
2321
 
2200
2322
class NotABundle(BzrError):
2201
 
    
 
2323
 
2202
2324
    _fmt = "Not a bzr revision-bundle: %(text)r"
2203
2325
 
2204
2326
    def __init__(self, text):
2206
2328
        self.text = text
2207
2329
 
2208
2330
 
2209
 
class BadBundle(BzrError): 
2210
 
    
 
2331
class BadBundle(BzrError):
 
2332
 
2211
2333
    _fmt = "Bad bzr revision-bundle: %(text)r"
2212
2334
 
2213
2335
    def __init__(self, text):
2215
2337
        self.text = text
2216
2338
 
2217
2339
 
2218
 
class MalformedHeader(BadBundle): 
2219
 
    
 
2340
class MalformedHeader(BadBundle):
 
2341
 
2220
2342
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2221
2343
 
2222
2344
 
2223
 
class MalformedPatches(BadBundle): 
2224
 
    
 
2345
class MalformedPatches(BadBundle):
 
2346
 
2225
2347
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2226
2348
 
2227
2349
 
2228
 
class MalformedFooter(BadBundle): 
2229
 
    
 
2350
class MalformedFooter(BadBundle):
 
2351
 
2230
2352
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2231
2353
 
2232
2354
 
2233
2355
class UnsupportedEOLMarker(BadBundle):
2234
 
    
2235
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
 
2356
 
 
2357
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
2236
2358
 
2237
2359
    def __init__(self):
2238
 
        # XXX: BadBundle's constructor assumes there's explanatory text, 
 
2360
        # XXX: BadBundle's constructor assumes there's explanatory text,
2239
2361
        # but for this there is not
2240
2362
        BzrError.__init__(self)
2241
2363
 
2242
2364
 
2243
2365
class IncompatibleBundleFormat(BzrError):
2244
 
    
 
2366
 
2245
2367
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2246
2368
 
2247
2369
    def __init__(self, bundle_format, other):
2251
2373
 
2252
2374
 
2253
2375
class BadInventoryFormat(BzrError):
2254
 
    
 
2376
 
2255
2377
    _fmt = "Root class for inventory serialization errors"
2256
2378
 
2257
2379
 
2276
2398
        self.transport = transport
2277
2399
 
2278
2400
 
2279
 
class NoSmartServer(NotBranchError):
2280
 
 
2281
 
    _fmt = "No smart server available at %(url)s"
2282
 
 
2283
 
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
2284
 
    def __init__(self, url):
2285
 
        self.url = url
2286
 
 
2287
 
 
2288
2401
class UnknownSSH(BzrError):
2289
2402
 
2290
2403
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2310
2423
        self.revision_id = revision_id
2311
2424
        self.ghost_revision_id = ghost_revision_id
2312
2425
 
2313
 
        
 
2426
 
2314
2427
class GhostRevisionUnusableHere(BzrError):
2315
2428
 
2316
2429
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2408
2521
 
2409
2522
 
2410
2523
class UnsupportedInventoryKind(BzrError):
2411
 
    
 
2524
 
2412
2525
    _fmt = """Unsupported entry kind %(kind)s"""
2413
2526
 
2414
2527
    def __init__(self, kind):
2426
2539
 
2427
2540
 
2428
2541
class SubsumeTargetNeedsUpgrade(BzrError):
2429
 
    
 
2542
 
2430
2543
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2431
2544
 
2432
2545
    def __init__(self, other_tree):
2460
2573
    def __init__(self, branch):
2461
2574
        self.branch = branch
2462
2575
 
2463
 
        
 
2576
 
2464
2577
class TagAlreadyExists(BzrError):
2465
2578
 
2466
2579
    _fmt = "Tag %(tag_name)s already exists."
2471
2584
 
2472
2585
class MalformedBugIdentifier(BzrError):
2473
2586
 
2474
 
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2587
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
2588
            'See "bzr help bugs" for more information on this feature.')
2475
2589
 
2476
2590
    def __init__(self, bug_id, reason):
2477
2591
        self.bug_id = bug_id
2498
2612
        self.branch = branch
2499
2613
 
2500
2614
 
 
2615
class InvalidLineInBugsProperty(BzrError):
 
2616
 
 
2617
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
2618
 
 
2619
    def __init__(self, line):
 
2620
        self.line = line
 
2621
 
 
2622
 
 
2623
class InvalidBugStatus(BzrError):
 
2624
 
 
2625
    _fmt = ("Invalid bug status: '%(status)s'")
 
2626
 
 
2627
    def __init__(self, status):
 
2628
        self.status = status
 
2629
 
 
2630
 
2501
2631
class UnexpectedSmartServerResponse(BzrError):
2502
2632
 
2503
2633
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2531
2661
 
2532
2662
    This is distinct from ErrorFromSmartServer so that it is possible to
2533
2663
    distinguish between the following two cases:
2534
 
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
2535
 
        and so should provoke a traceback to the user.
2536
 
      - ErrorFromSmartServer was caught but its error_tuple could not be
2537
 
        translated.  This is probably because the server sent us garbage, and
2538
 
        should not provoke a traceback.
 
2664
 
 
2665
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2666
      and so should provoke a traceback to the user.
 
2667
    - ErrorFromSmartServer was caught but its error_tuple could not be
 
2668
      translated.  This is probably because the server sent us garbage, and
 
2669
      should not provoke a traceback.
2539
2670
    """
2540
2671
 
2541
2672
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2549
2680
        """
2550
2681
        self.error_from_smart_server = error_from_smart_server
2551
2682
        self.error_tuple = error_from_smart_server.error_tuple
2552
 
        
 
2683
 
2553
2684
 
2554
2685
class ContainerError(BzrError):
2555
2686
    """Base class of container errors."""
2558
2689
class UnknownContainerFormatError(ContainerError):
2559
2690
 
2560
2691
    _fmt = "Unrecognised container format: %(container_format)r"
2561
 
    
 
2692
 
2562
2693
    def __init__(self, container_format):
2563
2694
        self.container_format = container_format
2564
2695
 
2597
2728
    _fmt = "Container has multiple records with the same name: %(name)s"
2598
2729
 
2599
2730
    def __init__(self, name):
2600
 
        self.name = name
 
2731
        self.name = name.decode("utf-8")
2601
2732
 
2602
2733
 
2603
2734
class NoDestinationAddress(InternalBzrError):
2628
2759
 
2629
2760
class NoMailAddressSpecified(BzrError):
2630
2761
 
2631
 
    _fmt = "No mail-to address specified."
 
2762
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
2632
2763
 
2633
2764
 
2634
2765
class UnknownMailClient(BzrError):
2667
2798
 
2668
2799
    def __init__(self, bzrdir):
2669
2800
        import bzrlib.urlutils as urlutils
2670
 
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2801
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
2671
2802
                                                    'ascii')
2672
2803
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2673
2804
 
2714
2845
    _fmt = "'%(display_url)s' is already standalone."
2715
2846
 
2716
2847
 
 
2848
class AlreadyWithTrees(BzrDirError):
 
2849
 
 
2850
    _fmt = ("Shared repository '%(display_url)s' already creates "
 
2851
            "working trees.")
 
2852
 
 
2853
 
 
2854
class AlreadyWithNoTrees(BzrDirError):
 
2855
 
 
2856
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
 
2857
            "working trees.")
 
2858
 
 
2859
 
2717
2860
class ReconfigurationNotSupported(BzrDirError):
2718
2861
 
2719
2862
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2726
2869
 
2727
2870
class UncommittedChanges(BzrError):
2728
2871
 
2729
 
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
 
2872
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
 
2873
            ' (See bzr status).%(more)s')
2730
2874
 
2731
 
    def __init__(self, tree):
 
2875
    def __init__(self, tree, more=None):
 
2876
        if more is None:
 
2877
            more = ''
 
2878
        else:
 
2879
            more = ' ' + more
2732
2880
        import bzrlib.urlutils as urlutils
2733
 
        display_url = urlutils.unescape_for_display(
2734
 
            tree.bzrdir.root_transport.base, 'ascii')
2735
 
        BzrError.__init__(self, tree=tree, display_url=display_url)
 
2881
        user_url = getattr(tree, "user_url", None)
 
2882
        if user_url is None:
 
2883
            display_url = str(tree)
 
2884
        else:
 
2885
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
 
2886
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
 
2887
 
 
2888
 
 
2889
class ShelvedChanges(UncommittedChanges):
 
2890
 
 
2891
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
 
2892
            ' (See bzr shelve --list).%(more)s')
2736
2893
 
2737
2894
 
2738
2895
class MissingTemplateVariable(BzrError):
2773
2930
 
2774
2931
 
2775
2932
class CommandAvailableInPlugin(StandardError):
2776
 
    
 
2933
 
2777
2934
    internal_error = False
2778
2935
 
2779
2936
    def __init__(self, cmd_name, plugin_metadata, provider):
2780
 
        
 
2937
 
2781
2938
        self.plugin_metadata = plugin_metadata
2782
2939
        self.cmd_name = cmd_name
2783
2940
        self.provider = provider
2784
2941
 
2785
2942
    def __str__(self):
2786
2943
 
2787
 
        _fmt = ('"%s" is not a standard bzr command. \n' 
 
2944
        _fmt = ('"%s" is not a standard bzr command. \n'
2788
2945
                'However, the following official plugin provides this command: %s\n'
2789
2946
                'You can install it by going to: %s'
2790
 
                % (self.cmd_name, self.plugin_metadata['name'], 
 
2947
                % (self.cmd_name, self.plugin_metadata['name'],
2791
2948
                    self.plugin_metadata['url']))
2792
2949
 
2793
2950
        return _fmt
2794
2951
 
2795
2952
 
2796
2953
class NoPluginAvailable(BzrError):
2797
 
    pass    
2798
 
 
2799
 
 
2800
 
class NotATerminal(BzrError):
2801
 
 
2802
 
    _fmt = 'Unable to ask for a password without real terminal.'
 
2954
    pass
2803
2955
 
2804
2956
 
2805
2957
class UnableEncodePath(BzrError):
2811
2963
        from bzrlib.osutils import get_user_encoding
2812
2964
        self.path = path
2813
2965
        self.kind = kind
2814
 
        self.user_encoding = osutils.get_user_encoding()
 
2966
        self.user_encoding = get_user_encoding()
 
2967
 
 
2968
 
 
2969
class NoSuchConfig(BzrError):
 
2970
 
 
2971
    _fmt = ('The "%(config_id)s" configuration does not exist.')
 
2972
 
 
2973
    def __init__(self, config_id):
 
2974
        BzrError.__init__(self, config_id=config_id)
 
2975
 
 
2976
 
 
2977
class NoSuchConfigOption(BzrError):
 
2978
 
 
2979
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
 
2980
 
 
2981
    def __init__(self, option_name):
 
2982
        BzrError.__init__(self, option_name=option_name)
2815
2983
 
2816
2984
 
2817
2985
class NoSuchAlias(BzrError):
2849
3017
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2850
3018
 
2851
3019
    def __init__(self, host, port, orig_error):
 
3020
        # nb: in python2.4 socket.error doesn't have a useful repr
2852
3021
        BzrError.__init__(self, host=host, port=port,
2853
 
            orig_error=orig_error[1])
 
3022
            orig_error=repr(orig_error.args))
2854
3023
 
2855
3024
 
2856
3025
class UnknownRules(BzrError):
2861
3030
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2862
3031
 
2863
3032
 
2864
 
class HookFailed(BzrError):
2865
 
    """Raised when a pre_change_branch_tip hook function fails anything other
2866
 
    than TipChangeRejected.
2867
 
    """
2868
 
 
2869
 
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2870
 
            "%(traceback_text)s%(exc_value)s")
2871
 
 
2872
 
    def __init__(self, hook_stage, hook_name, exc_info):
2873
 
        import traceback
2874
 
        self.hook_stage = hook_stage
2875
 
        self.hook_name = hook_name
2876
 
        self.exc_info = exc_info
2877
 
        self.exc_type = exc_info[0]
2878
 
        self.exc_value = exc_info[1]
2879
 
        self.exc_tb = exc_info[2]
2880
 
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2881
 
 
2882
 
 
2883
3033
class TipChangeRejected(BzrError):
2884
3034
    """A pre_change_branch_tip hook function may raise this to cleanly and
2885
3035
    explicitly abort a change to a branch tip.
2886
3036
    """
2887
 
    
 
3037
 
2888
3038
    _fmt = u"Tip change rejected: %(msg)s"
2889
3039
 
2890
3040
    def __init__(self, msg):
2891
3041
        self.msg = msg
2892
3042
 
 
3043
 
 
3044
class ShelfCorrupt(BzrError):
 
3045
 
 
3046
    _fmt = "Shelf corrupt."
 
3047
 
 
3048
 
 
3049
class DecompressCorruption(BzrError):
 
3050
 
 
3051
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
 
3052
 
 
3053
    def __init__(self, orig_error=None):
 
3054
        if orig_error is not None:
 
3055
            self.orig_error = ", %s" % (orig_error,)
 
3056
        else:
 
3057
            self.orig_error = ""
 
3058
        BzrError.__init__(self)
 
3059
 
 
3060
 
 
3061
class NoSuchShelfId(BzrError):
 
3062
 
 
3063
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
 
3064
 
 
3065
    def __init__(self, shelf_id):
 
3066
        BzrError.__init__(self, shelf_id=shelf_id)
 
3067
 
 
3068
 
 
3069
class InvalidShelfId(BzrError):
 
3070
 
 
3071
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
 
3072
 
 
3073
    def __init__(self, invalid_id):
 
3074
        BzrError.__init__(self, invalid_id=invalid_id)
 
3075
 
 
3076
 
 
3077
class JailBreak(BzrError):
 
3078
 
 
3079
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
 
3080
 
 
3081
    def __init__(self, url):
 
3082
        BzrError.__init__(self, url=url)
 
3083
 
 
3084
 
 
3085
class UserAbort(BzrError):
 
3086
 
 
3087
    _fmt = 'The user aborted the operation.'
 
3088
 
 
3089
 
 
3090
class MustHaveWorkingTree(BzrError):
 
3091
 
 
3092
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
 
3093
 
 
3094
    def __init__(self, format, url):
 
3095
        BzrError.__init__(self, format=format, url=url)
 
3096
 
 
3097
 
 
3098
class NoSuchView(BzrError):
 
3099
    """A view does not exist.
 
3100
    """
 
3101
 
 
3102
    _fmt = u"No such view: %(view_name)s."
 
3103
 
 
3104
    def __init__(self, view_name):
 
3105
        self.view_name = view_name
 
3106
 
 
3107
 
 
3108
class ViewsNotSupported(BzrError):
 
3109
    """Views are not supported by a tree format.
 
3110
    """
 
3111
 
 
3112
    _fmt = ("Views are not supported by %(tree)s;"
 
3113
            " use 'bzr upgrade' to change your tree to a later format.")
 
3114
 
 
3115
    def __init__(self, tree):
 
3116
        self.tree = tree
 
3117
 
 
3118
 
 
3119
class FileOutsideView(BzrError):
 
3120
 
 
3121
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
3122
            '%(view_str)s')
 
3123
 
 
3124
    def __init__(self, file_name, view_files):
 
3125
        self.file_name = file_name
 
3126
        self.view_str = ", ".join(view_files)
 
3127
 
 
3128
 
 
3129
class UnresumableWriteGroup(BzrError):
 
3130
 
 
3131
    _fmt = ("Repository %(repository)s cannot resume write group "
 
3132
            "%(write_groups)r: %(reason)s")
 
3133
 
 
3134
    internal_error = True
 
3135
 
 
3136
    def __init__(self, repository, write_groups, reason):
 
3137
        self.repository = repository
 
3138
        self.write_groups = write_groups
 
3139
        self.reason = reason
 
3140
 
 
3141
 
 
3142
class UnsuspendableWriteGroup(BzrError):
 
3143
 
 
3144
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
 
3145
 
 
3146
    internal_error = True
 
3147
 
 
3148
    def __init__(self, repository):
 
3149
        self.repository = repository
 
3150
 
 
3151
 
 
3152
class LossyPushToSameVCS(BzrError):
 
3153
 
 
3154
    _fmt = ("Lossy push not possible between %(source_branch)r and "
 
3155
            "%(target_branch)r that are in the same VCS.")
 
3156
 
 
3157
    internal_error = True
 
3158
 
 
3159
    def __init__(self, source_branch, target_branch):
 
3160
        self.source_branch = source_branch
 
3161
        self.target_branch = target_branch
 
3162
 
 
3163
 
 
3164
class NoRoundtrippingSupport(BzrError):
 
3165
 
 
3166
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
 
3167
            "%(target_branch)r.")
 
3168
 
 
3169
    internal_error = True
 
3170
 
 
3171
    def __init__(self, source_branch, target_branch):
 
3172
        self.source_branch = source_branch
 
3173
        self.target_branch = target_branch
 
3174
 
 
3175
 
 
3176
class FileTimestampUnavailable(BzrError):
 
3177
 
 
3178
    _fmt = "The filestamp for %(path)s is not available."
 
3179
 
 
3180
    internal_error = True
 
3181
 
 
3182
    def __init__(self, path):
 
3183
        self.path = path
 
3184
 
 
3185
 
 
3186
class NoColocatedBranchSupport(BzrError):
 
3187
 
 
3188
    _fmt = ("%(bzrdir)r does not support co-located branches.")
 
3189
 
 
3190
    def __init__(self, bzrdir):
 
3191
        self.bzrdir = bzrdir
 
3192
 
 
3193
 
 
3194
class NoWhoami(BzrError):
 
3195
 
 
3196
    _fmt = ('Unable to determine your name.\n'
 
3197
        "Please, set your name with the 'whoami' command.\n"
 
3198
        'E.g. bzr whoami "Your Name <name@example.com>"')
 
3199
 
 
3200
 
 
3201
class InvalidPattern(BzrError):
 
3202
 
 
3203
    _fmt = ('Invalid pattern(s) found. %(msg)s')
 
3204
 
 
3205
    def __init__(self, msg):
 
3206
        self.msg = msg
 
3207
 
 
3208
 
 
3209
class RecursiveBind(BzrError):
 
3210
 
 
3211
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
 
3212
        'Please use `bzr unbind` to fix.')
 
3213
 
 
3214
    def __init__(self, branch_url):
 
3215
        self.branch_url = branch_url
 
3216
 
 
3217
 
 
3218
# FIXME: I would prefer to define the config related exception classes in
 
3219
# config.py but the lazy import mechanism proscribes this -- vila 20101222
 
3220
class OptionExpansionLoop(BzrError):
 
3221
 
 
3222
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
 
3223
 
 
3224
    def __init__(self, string, refs):
 
3225
        self.string = string
 
3226
        self.refs = '->'.join(refs)
 
3227
 
 
3228
 
 
3229
class ExpandingUnknownOption(BzrError):
 
3230
 
 
3231
    _fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
 
3232
 
 
3233
    def __init__(self, name, string):
 
3234
        self.name = name
 
3235
        self.string = string
 
3236
 
 
3237
 
 
3238
class NoCompatibleInter(BzrError):
 
3239
 
 
3240
    _fmt = ('No compatible object available for operations from %(source)r '
 
3241
            'to %(target)r.')
 
3242
 
 
3243
    def __init__(self, source, target):
 
3244
        self.source = source
 
3245
        self.target = target
 
3246
 
 
3247
 
 
3248
class HpssVfsRequestNotAllowed(BzrError):
 
3249
 
 
3250
    _fmt = ("VFS requests over the smart server are not allowed. Encountered: "
 
3251
            "%(method)s, %(arguments)s.")
 
3252
 
 
3253
    def __init__(self, method, arguments):
 
3254
        self.method = method
 
3255
        self.arguments = arguments
 
3256
 
 
3257
 
 
3258
class UnsupportedKindChange(BzrError):
 
3259
 
 
3260
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
 
3261
            "%(path)s not supported by format %(format)r")
 
3262
 
 
3263
    def __init__(self, path, from_kind, to_kind, format):
 
3264
        self.path = path
 
3265
        self.from_kind = from_kind
 
3266
        self.to_kind = to_kind
 
3267
        self.format = format
 
3268
 
 
3269
 
 
3270
class MissingFeature(BzrError):
 
3271
 
 
3272
    _fmt = ("Missing feature %(feature)s not provided by this "
 
3273
            "version of Bazaar or any plugin.")
 
3274
 
 
3275
    def __init__(self, feature):
 
3276
        self.feature = feature
 
3277
 
 
3278
 
 
3279
class PatchSyntax(BzrError):
 
3280
    """Base class for patch syntax errors."""
 
3281
 
 
3282
 
 
3283
class BinaryFiles(BzrError):
 
3284
 
 
3285
    _fmt = 'Binary files section encountered.'
 
3286
 
 
3287
    def __init__(self, orig_name, mod_name):
 
3288
        self.orig_name = orig_name
 
3289
        self.mod_name = mod_name
 
3290
 
 
3291
 
 
3292
class MalformedPatchHeader(PatchSyntax):
 
3293
 
 
3294
    _fmt = "Malformed patch header.  %(desc)s\n%(line)r"
 
3295
 
 
3296
    def __init__(self, desc, line):
 
3297
        self.desc = desc
 
3298
        self.line = line
 
3299
 
 
3300
 
 
3301
class MalformedHunkHeader(PatchSyntax):
 
3302
 
 
3303
    _fmt = "Malformed hunk header.  %(desc)s\n%(line)r"
 
3304
 
 
3305
    def __init__(self, desc, line):
 
3306
        self.desc = desc
 
3307
        self.line = line
 
3308
 
 
3309
 
 
3310
class MalformedLine(PatchSyntax):
 
3311
 
 
3312
    _fmt = "Malformed line.  %(desc)s\n%(line)r"
 
3313
 
 
3314
    def __init__(self, desc, line):
 
3315
        self.desc = desc
 
3316
        self.line = line
 
3317
 
 
3318
 
 
3319
class PatchConflict(BzrError):
 
3320
 
 
3321
    _fmt = ('Text contents mismatch at line %(line_no)d.  Original has '
 
3322
            '"%(orig_line)s", but patch says it should be "%(patch_line)s"')
 
3323
 
 
3324
    def __init__(self, line_no, orig_line, patch_line):
 
3325
        self.line_no = line_no
 
3326
        self.orig_line = orig_line.rstrip('\n')
 
3327
        self.patch_line = patch_line.rstrip('\n')
 
3328
 
 
3329
 
 
3330
class FeatureAlreadyRegistered(BzrError):
 
3331
 
 
3332
    _fmt = 'The feature %(feature)s has already been registered.'
 
3333
 
 
3334
    def __init__(self, feature):
 
3335
        self.feature = feature