~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

(vila) Forbid more operations on ReadonlyTransportDecorator (Vincent Ladeuil)

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,
84
 
        not subject to expansion.
 
72
           not subject to expansion. 'msg' is used instead of 'message' because
 
73
           python evolved and, in 2.6, forbids the use of 'message'.
85
74
        """
86
75
        StandardError.__init__(self)
87
76
        if msg is not None:
102
91
            fmt = self._get_format_string()
103
92
            if fmt:
104
93
                d = dict(self.__dict__)
105
 
                # special case: python2.5 puts the 'message' attribute in a
106
 
                # slot, so it isn't seen in __dict__
107
 
                d['message'] = getattr(self, 'message', 'no message')
108
94
                s = fmt % d
109
95
                # __str__() should always return a 'str' object
110
96
                # never a 'unicode' object.
111
97
                return s
112
 
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
113
 
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
114
 
                % (self.__class__.__name__,
115
 
                   self.__dict__,
116
 
                   getattr(self, '_fmt', None),
117
 
                   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)
118
107
 
119
108
    def __unicode__(self):
120
109
        u = self._format()
126
115
            # return a unicode object.
127
116
            u = unicode(u)
128
117
        return u
129
 
    
 
118
 
130
119
    def __str__(self):
131
120
        s = self._format()
132
121
        if isinstance(s, unicode):
136
125
            s = str(s)
137
126
        return s
138
127
 
 
128
    def __repr__(self):
 
129
        return '%s(%s)' % (self.__class__.__name__, str(self))
 
130
 
139
131
    def _get_format_string(self):
140
132
        """Return format string for this exception or None"""
141
133
        fmt = getattr(self, '_fmt', None)
142
134
        if fmt is not None:
143
 
            return fmt
144
 
        fmt = getattr(self, '__doc__', None)
145
 
        if fmt is not None:
146
 
            symbol_versioning.warn("%s uses its docstring as a format, "
147
 
                    "it should use _fmt instead" % self.__class__.__name__,
148
 
                    DeprecationWarning)
149
 
            return fmt
150
 
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
151
 
            % (self.__class__.__name__,
152
 
               self.__dict__,
153
 
               getattr(self, '_fmt', None),
154
 
               )
 
135
            from bzrlib.i18n import gettext
 
136
            return gettext(unicode(fmt)) # _fmt strings should be ascii
155
137
 
156
138
    def __eq__(self, other):
157
 
        if self.__class__ != other.__class__:
 
139
        if self.__class__ is not other.__class__:
158
140
            return NotImplemented
159
141
        return self.__dict__ == other.__dict__
160
142
 
170
152
    internal_error = True
171
153
 
172
154
 
173
 
class BzrNewError(BzrError):
174
 
    """Deprecated error base class."""
175
 
    # base classes should override the docstring with their human-
176
 
    # readable explanation
177
 
 
178
 
    def __init__(self, *args, **kwds):
179
 
        # XXX: Use the underlying BzrError to always generate the args
180
 
        # attribute if it doesn't exist.  We can't use super here, because
181
 
        # exceptions are old-style classes in python2.4 (but new in 2.5).
182
 
        # --bmc, 20060426
183
 
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
184
 
             'please convert %s to use BzrError instead'
185
 
             % self.__class__.__name__,
186
 
             DeprecationWarning,
187
 
             stacklevel=2)
188
 
        BzrError.__init__(self, *args)
189
 
        for key, value in kwds.items():
190
 
            setattr(self, key, value)
191
 
 
192
 
    def __str__(self):
193
 
        try:
194
 
            # __str__() should always return a 'str' object
195
 
            # never a 'unicode' object.
196
 
            s = self.__doc__ % self.__dict__
197
 
            if isinstance(s, unicode):
198
 
                return s.encode('utf8')
199
 
            return s
200
 
        except (TypeError, NameError, ValueError, KeyError), e:
201
 
            return 'Unprintable exception %s(%r): %r' \
202
 
                % (self.__class__.__name__,
203
 
                   self.__dict__, e)
204
 
 
205
 
 
206
155
class AlreadyBuilding(BzrError):
207
 
    
 
156
 
208
157
    _fmt = "The tree builder is already building a tree."
209
158
 
210
159
 
216
165
 
217
166
 
218
167
class BzrCheckError(InternalBzrError):
219
 
    
220
 
    _fmt = "Internal check failed: %(message)s"
221
 
 
222
 
    def __init__(self, message):
 
168
 
 
169
    _fmt = "Internal check failed: %(msg)s"
 
170
 
 
171
    def __init__(self, msg):
223
172
        BzrError.__init__(self)
224
 
        self.message = message
 
173
        self.msg = msg
225
174
 
226
175
 
227
176
class DirstateCorrupt(BzrError):
265
214
 
266
215
 
267
216
class InvalidEntryName(InternalBzrError):
268
 
    
 
217
 
269
218
    _fmt = "Invalid entry name: %(name)s"
270
219
 
271
220
    def __init__(self, name):
274
223
 
275
224
 
276
225
class InvalidRevisionNumber(BzrError):
277
 
    
 
226
 
278
227
    _fmt = "Invalid revision number %(revno)s"
279
228
 
280
229
    def __init__(self, revno):
304
253
class RootMissing(InternalBzrError):
305
254
 
306
255
    _fmt = ("The root entry of a tree must be the first entry supplied to "
307
 
        "record_entry_contents.")
 
256
        "the commit builder.")
308
257
 
309
258
 
310
259
class NoPublicBranch(BzrError):
329
278
class NoSuchId(BzrError):
330
279
 
331
280
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
332
 
    
 
281
 
333
282
    def __init__(self, tree, file_id):
334
283
        BzrError.__init__(self)
335
284
        self.file_id = file_id
362
311
class NoWorkingTree(BzrError):
363
312
 
364
313
    _fmt = 'No WorkingTree exists for "%(base)s".'
365
 
    
 
314
 
366
315
    def __init__(self, base):
367
316
        BzrError.__init__(self)
368
317
        self.base = base
477
426
    def __init__(self, name, value):
478
427
        BzrError.__init__(self, name=name, value=value)
479
428
 
480
 
    
 
429
 
481
430
class StrictCommitFailed(BzrError):
482
431
 
483
432
    _fmt = "Commit refused because there are unknown files in the tree"
486
435
# XXX: Should be unified with TransportError; they seem to represent the
487
436
# same thing
488
437
# 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 
 
438
# - this is finer than a TransportError - and more useful as such. It
490
439
# differentiates between 'transport has failed' and 'operation on a transport
491
440
# has failed.'
492
441
class PathError(BzrError):
493
 
    
 
442
 
494
443
    _fmt = "Generic path error: %(path)r%(extra)s)"
495
444
 
496
445
    def __init__(self, path, extra=None):
550
499
 
551
500
 
552
501
class ReadingCompleted(InternalBzrError):
553
 
    
 
502
 
554
503
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
555
504
            "called upon it - the request has been completed and no more "
556
505
            "data may be read.")
621
570
 
622
571
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
623
572
 
624
 
    def __init__(self, url, extra):
 
573
    def __init__(self, url, extra=""):
625
574
        PathError.__init__(self, url, extra=extra)
626
575
 
627
576
 
636
585
        self.url = url
637
586
 
638
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
 
639
598
class UnstackableRepositoryFormat(BzrError):
640
599
 
641
600
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
648
607
 
649
608
 
650
609
class ReadError(PathError):
651
 
    
 
610
 
652
611
    _fmt = """Error reading from %(path)r."""
653
612
 
654
613
 
670
629
 
671
630
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
672
631
 
673
 
    internal_error = True
 
632
    internal_error = False
674
633
 
675
634
    def __init__(self, path, base, extra=None):
676
635
        BzrError.__init__(self)
689
648
 
690
649
# TODO: This is given a URL; we try to unescape it but doing that from inside
691
650
# the exception object is a bit undesirable.
692
 
# TODO: Probably this behavior of should be a common superclass 
 
651
# TODO: Probably this behavior of should be a common superclass
693
652
class NotBranchError(PathError):
694
653
 
695
 
    _fmt = 'Not a branch: "%(path)s".'
 
654
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
696
655
 
697
 
    def __init__(self, path):
 
656
    def __init__(self, path, detail=None, bzrdir=None):
698
657
       import bzrlib.urlutils as urlutils
699
 
       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)
700
692
 
701
693
 
702
694
class NoSubmitBranch(PathError):
708
700
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
709
701
 
710
702
 
 
703
class AlreadyControlDirError(PathError):
 
704
 
 
705
    _fmt = 'A control directory already exists: "%(path)s".'
 
706
 
 
707
 
711
708
class AlreadyBranchError(PathError):
712
709
 
713
710
    _fmt = 'Already a branch: "%(path)s".'
714
711
 
715
712
 
 
713
class InvalidBranchName(PathError):
 
714
 
 
715
    _fmt = "Invalid branch name: %(name)s"
 
716
 
 
717
    def __init__(self, name):
 
718
        BzrError.__init__(self)
 
719
        self.name = name
 
720
 
 
721
 
 
722
class ParentBranchExists(AlreadyBranchError):
 
723
 
 
724
    _fmt = 'Parent branch already exists: "%(path)s".'
 
725
 
 
726
 
716
727
class BranchExistsWithoutWorkingTree(PathError):
717
728
 
718
729
    _fmt = 'Directory contains a branch, but no working tree \
747
758
        self.path = bzrdir.transport.clone('..').base
748
759
 
749
760
 
750
 
class FileInWrongBranch(BzrError):
751
 
 
752
 
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
753
 
 
754
 
    def __init__(self, branch, path):
755
 
        BzrError.__init__(self)
756
 
        self.branch = branch
757
 
        self.branch_base = branch.base
758
 
        self.path = path
759
 
 
760
 
 
761
761
class UnsupportedFormatError(BzrError):
762
762
 
763
763
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
764
764
 
765
765
 
766
766
class UnknownFormatError(BzrError):
767
 
    
 
767
 
768
768
    _fmt = "Unknown %(kind)s format: %(format)r"
769
769
 
770
770
    def __init__(self, format, kind='branch'):
773
773
 
774
774
 
775
775
class IncompatibleFormat(BzrError):
776
 
    
 
776
 
777
777
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
778
778
 
779
779
    def __init__(self, format, bzrdir_format):
782
782
        self.bzrdir = bzrdir_format
783
783
 
784
784
 
 
785
class ParseFormatError(BzrError):
 
786
 
 
787
    _fmt = "Parse error on line %(lineno)d of %(format)s format: %(line)s"
 
788
 
 
789
    def __init__(self, format, lineno, line, text):
 
790
        BzrError.__init__(self)
 
791
        self.format = format
 
792
        self.lineno = lineno
 
793
        self.line = line
 
794
        self.text = text
 
795
 
 
796
 
785
797
class IncompatibleRepositories(BzrError):
 
798
    """Report an error that two repositories are not compatible.
 
799
 
 
800
    Note that the source and target repositories are permitted to be strings:
 
801
    this exception is thrown from the smart server and may refer to a
 
802
    repository the client hasn't opened.
 
803
    """
786
804
 
787
805
    _fmt = "%(target)s\n" \
788
806
            "is not compatible with\n" \
796
814
 
797
815
 
798
816
class IncompatibleRevision(BzrError):
799
 
    
 
817
 
800
818
    _fmt = "Revision is not compatible with %(repo_format)s"
801
819
 
802
820
    def __init__(self, repo_format):
813
831
        """Construct a new AlreadyVersionedError.
814
832
 
815
833
        :param path: This is the path which is versioned,
816
 
        which should be in a user friendly form.
 
834
            which should be in a user friendly form.
817
835
        :param context_info: If given, this is information about the context,
818
 
        which could explain why this is expected to not be versioned.
 
836
            which could explain why this is expected to not be versioned.
819
837
        """
820
838
        BzrError.__init__(self)
821
839
        self.path = path
834
852
        """Construct a new NotVersionedError.
835
853
 
836
854
        :param path: This is the path which is not versioned,
837
 
        which should be in a user friendly form.
 
855
            which should be in a user friendly form.
838
856
        :param context_info: If given, this is information about the context,
839
 
        which could explain why this is expected to be versioned.
 
857
            which could explain why this is expected to be versioned.
840
858
        """
841
859
        BzrError.__init__(self)
842
860
        self.path = path
910
928
    # original exception is available as e.original_error
911
929
    #
912
930
    # New code should prefer to raise specific subclasses
913
 
    def __init__(self, message):
914
 
        # Python 2.5 uses a slot for StandardError.message,
915
 
        # so use a different variable name.  We now work around this in
916
 
        # BzrError.__str__, but this member name is kept for compatability.
917
 
        self.msg = message
 
931
    def __init__(self, msg):
 
932
        self.msg = msg
918
933
 
919
934
 
920
935
class LockActive(LockError):
1003
1018
 
1004
1019
class LockContention(LockError):
1005
1020
 
1006
 
    _fmt = 'Could not acquire lock "%(lock)s"'
1007
 
    # TODO: show full url for lock, combining the transport and relative
1008
 
    # bits?
 
1021
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
1009
1022
 
1010
1023
    internal_error = False
1011
1024
 
1012
 
    def __init__(self, lock):
 
1025
    def __init__(self, lock, msg=''):
1013
1026
        self.lock = lock
 
1027
        self.msg = msg
1014
1028
 
1015
1029
 
1016
1030
class LockBroken(LockError):
1037
1051
        self.target = target
1038
1052
 
1039
1053
 
 
1054
class LockCorrupt(LockError):
 
1055
 
 
1056
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
 
1057
            "Use 'bzr break-lock' to clear it")
 
1058
 
 
1059
    internal_error = False
 
1060
 
 
1061
    def __init__(self, corruption_info, file_data=None):
 
1062
        self.corruption_info = corruption_info
 
1063
        self.file_data = file_data
 
1064
 
 
1065
 
1040
1066
class LockNotHeld(LockError):
1041
1067
 
1042
1068
    _fmt = "Lock not held: %(lock)s"
1081
1107
        BzrError.__init__(self, files=files, files_str=files_str)
1082
1108
 
1083
1109
 
 
1110
class ExcludesUnsupported(BzrError):
 
1111
 
 
1112
    _fmt = ('Excluding paths during commit is not supported by '
 
1113
            'repository at %(repository)r.')
 
1114
 
 
1115
    def __init__(self, repository):
 
1116
        BzrError.__init__(self, repository=repository)
 
1117
 
 
1118
 
1084
1119
class BadCommitMessageEncoding(BzrError):
1085
1120
 
1086
1121
    _fmt = 'The specified commit message contains characters unsupported by '\
1130
1165
 
1131
1166
class NoSuchRevisionInTree(NoSuchRevision):
1132
1167
    """When using Tree.revision_tree, and the revision is not accessible."""
1133
 
    
 
1168
 
1134
1169
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1135
1170
 
1136
1171
    def __init__(self, tree, revision_id):
1141
1176
 
1142
1177
class InvalidRevisionSpec(BzrError):
1143
1178
 
1144
 
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
1145
 
            " %(branch)s%(extra)s")
 
1179
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
 
1180
            " %(branch_url)s%(extra)s")
1146
1181
 
1147
1182
    def __init__(self, spec, branch, extra=None):
1148
1183
        BzrError.__init__(self, branch=branch, spec=spec)
 
1184
        self.branch_url = getattr(branch, 'user_url', str(branch))
1149
1185
        if extra:
1150
1186
            self.extra = '\n' + str(extra)
1151
1187
        else:
1152
1188
            self.extra = ''
1153
1189
 
1154
1190
 
1155
 
class HistoryMissing(BzrError):
1156
 
 
1157
 
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
1158
 
 
1159
 
 
1160
1191
class AppendRevisionsOnlyViolation(BzrError):
1161
1192
 
1162
1193
    _fmt = ('Operation denied because it would change the main history,'
1172
1203
class DivergedBranches(BzrError):
1173
1204
 
1174
1205
    _fmt = ("These branches have diverged."
1175
 
            " Use the merge command to reconcile them.")
 
1206
            " Use the missing command to see how.\n"
 
1207
            "Use the merge command to reconcile them.")
1176
1208
 
1177
1209
    def __init__(self, branch1, branch2):
1178
1210
        self.branch1 = branch1
1200
1232
 
1201
1233
 
1202
1234
class NoCommonAncestor(BzrError):
1203
 
    
 
1235
 
1204
1236
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1205
1237
 
1206
1238
    def __init__(self, revision_a, revision_b):
1226
1258
            not_ancestor_id=not_ancestor_id)
1227
1259
 
1228
1260
 
1229
 
class InstallFailed(BzrError):
1230
 
 
1231
 
    def __init__(self, revisions):
1232
 
        revision_str = ", ".join(str(r) for r in revisions)
1233
 
        msg = "Could not install revisions:\n%s" % revision_str
1234
 
        BzrError.__init__(self, msg)
1235
 
        self.revisions = revisions
1236
 
 
1237
 
 
1238
 
class AmbiguousBase(BzrError):
1239
 
 
1240
 
    def __init__(self, bases):
1241
 
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
1242
 
                DeprecationWarning)
1243
 
        msg = ("The correct base is unclear, because %s are all equally close"
1244
 
                % ", ".join(bases))
1245
 
        BzrError.__init__(self, msg)
1246
 
        self.bases = bases
1247
 
 
1248
 
 
1249
1261
class NoCommits(BranchError):
1250
1262
 
1251
1263
    _fmt = "Branch %(branch)s has no commits."
1267
1279
class BoundBranchOutOfDate(BzrError):
1268
1280
 
1269
1281
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1270
 
            " %(master)s.")
 
1282
            " %(master)s.%(extra_help)s")
1271
1283
 
1272
1284
    def __init__(self, branch, master):
1273
1285
        BzrError.__init__(self)
1274
1286
        self.branch = branch
1275
1287
        self.master = master
1276
 
 
1277
 
        
 
1288
        self.extra_help = ''
 
1289
 
 
1290
 
1278
1291
class CommitToDoubleBoundBranch(BzrError):
1279
1292
 
1280
1293
    _fmt = ("Cannot commit to branch %(branch)s."
1310
1323
 
1311
1324
class WeaveError(BzrError):
1312
1325
 
1313
 
    _fmt = "Error in processing weave: %(message)s"
 
1326
    _fmt = "Error in processing weave: %(msg)s"
1314
1327
 
1315
 
    def __init__(self, message=None):
 
1328
    def __init__(self, msg=None):
1316
1329
        BzrError.__init__(self)
1317
 
        self.message = message
 
1330
        self.msg = msg
1318
1331
 
1319
1332
 
1320
1333
class WeaveRevisionAlreadyPresent(WeaveError):
1349
1362
 
1350
1363
class WeaveParentMismatch(WeaveError):
1351
1364
 
1352
 
    _fmt = "Parents are mismatched between two revisions. %(message)s"
1353
 
    
 
1365
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
 
1366
 
1354
1367
 
1355
1368
class WeaveInvalidChecksum(WeaveError):
1356
1369
 
1357
 
    _fmt = "Text did not match it's checksum: %(message)s"
 
1370
    _fmt = "Text did not match its checksum: %(msg)s"
1358
1371
 
1359
1372
 
1360
1373
class WeaveTextDiffers(WeaveError):
1382
1395
 
1383
1396
 
1384
1397
class VersionedFileError(BzrError):
1385
 
    
 
1398
 
1386
1399
    _fmt = "Versioned file error"
1387
1400
 
1388
1401
 
1389
1402
class RevisionNotPresent(VersionedFileError):
1390
 
    
 
1403
 
1391
1404
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1392
1405
 
1393
1406
    def __init__(self, revision_id, file_id):
1397
1410
 
1398
1411
 
1399
1412
class RevisionAlreadyPresent(VersionedFileError):
1400
 
    
 
1413
 
1401
1414
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1402
1415
 
1403
1416
    def __init__(self, revision_id, file_id):
1408
1421
 
1409
1422
class VersionedFileInvalidChecksum(VersionedFileError):
1410
1423
 
1411
 
    _fmt = "Text did not match its checksum: %(message)s"
 
1424
    _fmt = "Text did not match its checksum: %(msg)s"
1412
1425
 
1413
1426
 
1414
1427
class KnitError(InternalBzrError):
1415
 
    
 
1428
 
1416
1429
    _fmt = "Knit error"
1417
1430
 
1418
1431
 
1426
1439
        self.how = how
1427
1440
 
1428
1441
 
 
1442
class SHA1KnitCorrupt(KnitCorrupt):
 
1443
 
 
1444
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
 
1445
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
 
1446
        "sha %(actual)s")
 
1447
 
 
1448
    def __init__(self, filename, actual, expected, key, content):
 
1449
        KnitError.__init__(self)
 
1450
        self.filename = filename
 
1451
        self.actual = actual
 
1452
        self.expected = expected
 
1453
        self.key = key
 
1454
        self.content = content
 
1455
 
 
1456
 
1429
1457
class KnitDataStreamIncompatible(KnitError):
1430
1458
    # Not raised anymore, as we can convert data streams.  In future we may
1431
1459
    # need it again for more exotic cases, so we're keeping it around for now.
1435
1463
    def __init__(self, stream_format, target_format):
1436
1464
        self.stream_format = stream_format
1437
1465
        self.target_format = target_format
1438
 
        
 
1466
 
1439
1467
 
1440
1468
class KnitDataStreamUnknown(KnitError):
1441
1469
    # Indicates a data stream we don't know how to handle.
1444
1472
 
1445
1473
    def __init__(self, stream_format):
1446
1474
        self.stream_format = stream_format
1447
 
        
 
1475
 
1448
1476
 
1449
1477
class KnitHeaderError(KnitError):
1450
1478
 
1460
1488
 
1461
1489
    Currently only 'fulltext' and 'line-delta' are supported.
1462
1490
    """
1463
 
    
 
1491
 
1464
1492
    _fmt = ("Knit index %(filename)s does not have a known method"
1465
1493
            " in options: %(options)r")
1466
1494
 
1470
1498
        self.options = options
1471
1499
 
1472
1500
 
 
1501
class RetryWithNewPacks(BzrError):
 
1502
    """Raised when we realize that the packs on disk have changed.
 
1503
 
 
1504
    This is meant as more of a signaling exception, to trap between where a
 
1505
    local error occurred and the code that can actually handle the error and
 
1506
    code that can retry appropriately.
 
1507
    """
 
1508
 
 
1509
    internal_error = True
 
1510
 
 
1511
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
 
1512
            " %(orig_error)s")
 
1513
 
 
1514
    def __init__(self, context, reload_occurred, exc_info):
 
1515
        """create a new RetryWithNewPacks error.
 
1516
 
 
1517
        :param reload_occurred: Set to True if we know that the packs have
 
1518
            already been reloaded, and we are failing because of an in-memory
 
1519
            cache miss. If set to True then we will ignore if a reload says
 
1520
            nothing has changed, because we assume it has already reloaded. If
 
1521
            False, then a reload with nothing changed will force an error.
 
1522
        :param exc_info: The original exception traceback, so if there is a
 
1523
            problem we can raise the original error (value from sys.exc_info())
 
1524
        """
 
1525
        BzrError.__init__(self)
 
1526
        self.context = context
 
1527
        self.reload_occurred = reload_occurred
 
1528
        self.exc_info = exc_info
 
1529
        self.orig_error = exc_info[1]
 
1530
        # TODO: The global error handler should probably treat this by
 
1531
        #       raising/printing the original exception with a bit about
 
1532
        #       RetryWithNewPacks also not being caught
 
1533
 
 
1534
 
 
1535
class RetryAutopack(RetryWithNewPacks):
 
1536
    """Raised when we are autopacking and we find a missing file.
 
1537
 
 
1538
    Meant as a signaling exception, to tell the autopack code it should try
 
1539
    again.
 
1540
    """
 
1541
 
 
1542
    internal_error = True
 
1543
 
 
1544
    _fmt = ("Pack files have changed, reload and try autopack again."
 
1545
            " context: %(context)s %(orig_error)s")
 
1546
 
 
1547
 
1473
1548
class NoSuchExportFormat(BzrError):
1474
 
    
 
1549
 
1475
1550
    _fmt = "Export format %(format)r not supported"
1476
1551
 
1477
1552
    def __init__(self, format):
1480
1555
 
1481
1556
 
1482
1557
class TransportError(BzrError):
1483
 
    
 
1558
 
1484
1559
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1485
1560
 
1486
1561
    def __init__(self, msg=None, orig_error=None):
1531
1606
 
1532
1607
class SmartMessageHandlerError(InternalBzrError):
1533
1608
 
1534
 
    _fmt = "The message handler raised an exception: %(exc_value)s."
 
1609
    _fmt = ("The message handler raised an exception:\n"
 
1610
            "%(traceback_text)s")
1535
1611
 
1536
1612
    def __init__(self, exc_info):
1537
 
        self.exc_type, self.exc_value, self.tb = exc_info
1538
 
        
 
1613
        import traceback
 
1614
        # GZ 2010-08-10: Cycle with exc_tb/exc_info affects at least one test
 
1615
        self.exc_type, self.exc_value, self.exc_tb = exc_info
 
1616
        self.exc_info = exc_info
 
1617
        traceback_strings = traceback.format_exception(
 
1618
                self.exc_type, self.exc_value, self.exc_tb)
 
1619
        self.traceback_text = ''.join(traceback_strings)
 
1620
 
1539
1621
 
1540
1622
# A set of semi-meaningful errors which can be thrown
1541
1623
class TransportNotPossible(TransportError):
1567
1649
            self.port = ':%s' % port
1568
1650
 
1569
1651
 
 
1652
# XXX: This is also used for unexpected end of file, which is different at the
 
1653
# TCP level from "connection reset".
1570
1654
class ConnectionReset(TransportError):
1571
1655
 
1572
1656
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1573
1657
 
1574
1658
 
 
1659
class ConnectionTimeout(ConnectionError):
 
1660
 
 
1661
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
 
1662
 
 
1663
 
1575
1664
class InvalidRange(TransportError):
1576
1665
 
1577
1666
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1584
1673
 
1585
1674
class InvalidHttpResponse(TransportError):
1586
1675
 
1587
 
    _fmt = "Invalid http response for %(path)s: %(msg)s"
 
1676
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
1588
1677
 
1589
1678
    def __init__(self, path, msg, orig_error=None):
1590
1679
        self.path = path
 
1680
        if orig_error is None:
 
1681
            orig_error = ''
 
1682
        else:
 
1683
            # This is reached for obscure and unusual errors so we want to
 
1684
            # preserve as much info as possible to ease debug.
 
1685
            orig_error = ': %r' % (orig_error,)
1591
1686
        TransportError.__init__(self, msg, orig_error=orig_error)
1592
1687
 
1593
1688
 
 
1689
class CertificateError(TransportError):
 
1690
 
 
1691
    _fmt = "Certificate error: %(error)s"
 
1692
 
 
1693
    def __init__(self, error):
 
1694
        self.error = error
 
1695
 
 
1696
 
1594
1697
class InvalidHttpRange(InvalidHttpResponse):
1595
1698
 
1596
1699
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1600
1703
        InvalidHttpResponse.__init__(self, path, msg)
1601
1704
 
1602
1705
 
 
1706
class HttpBoundaryMissing(InvalidHttpResponse):
 
1707
    """A multipart response ends with no boundary marker.
 
1708
 
 
1709
    This is a special case caused by buggy proxies, described in
 
1710
    <https://bugs.launchpad.net/bzr/+bug/198646>.
 
1711
    """
 
1712
 
 
1713
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
 
1714
 
 
1715
    def __init__(self, path, msg):
 
1716
        InvalidHttpResponse.__init__(self, path, msg)
 
1717
 
 
1718
 
1603
1719
class InvalidHttpContentType(InvalidHttpResponse):
1604
1720
 
1605
1721
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1613
1729
 
1614
1730
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1615
1731
 
1616
 
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
 
1732
    def __init__(self, source, target, is_permanent=False):
1617
1733
        self.source = source
1618
1734
        self.target = target
1619
1735
        if is_permanent:
1620
1736
            self.permanently = ' permanently'
1621
1737
        else:
1622
1738
            self.permanently = ''
1623
 
        self._qualified_proto = qual_proto
1624
1739
        TransportError.__init__(self)
1625
1740
 
1626
 
    def _requalify_url(self, url):
1627
 
        """Restore the qualified proto in front of the url"""
1628
 
        # When this exception is raised, source and target are in
1629
 
        # user readable format. But some transports may use a
1630
 
        # different proto (http+urllib:// will present http:// to
1631
 
        # the user. If a qualified proto is specified, the code
1632
 
        # trapping the exception can get the qualified urls to
1633
 
        # properly handle the redirection themself (creating a
1634
 
        # new transport object from the target url for example).
1635
 
        # But checking that the scheme of the original and
1636
 
        # redirected urls are the same can be tricky. (see the
1637
 
        # FIXME in BzrDir.open_from_transport for the unique use
1638
 
        # case so far).
1639
 
        if self._qualified_proto is None:
1640
 
            return url
1641
 
 
1642
 
        # The TODO related to NotBranchError mention that doing
1643
 
        # that kind of manipulation on the urls may not be the
1644
 
        # exception object job. On the other hand, this object is
1645
 
        # the interface between the code and the user so
1646
 
        # presenting the urls in different ways is indeed its
1647
 
        # job...
1648
 
        import urlparse
1649
 
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1650
 
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1651
 
                                   query, fragment))
1652
 
 
1653
 
    def get_source_url(self):
1654
 
        return self._requalify_url(self.source)
1655
 
 
1656
 
    def get_target_url(self):
1657
 
        return self._requalify_url(self.target)
1658
 
 
1659
1741
 
1660
1742
class TooManyRedirections(TransportError):
1661
1743
 
1667
1749
    _fmt = "Working tree has conflicts."
1668
1750
 
1669
1751
 
 
1752
class ConfigContentError(BzrError):
 
1753
 
 
1754
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
 
1755
 
 
1756
    def __init__(self, filename):
 
1757
        BzrError.__init__(self)
 
1758
        self.filename = filename
 
1759
 
 
1760
 
1670
1761
class ParseConfigError(BzrError):
1671
1762
 
 
1763
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
 
1764
 
1672
1765
    def __init__(self, errors, filename):
1673
 
        if filename is None:
1674
 
            filename = ""
1675
 
        message = "Error(s) parsing config file %s:\n%s" % \
1676
 
            (filename, ('\n'.join(e.message for e in errors)))
1677
 
        BzrError.__init__(self, message)
 
1766
        BzrError.__init__(self)
 
1767
        self.filename = filename
 
1768
        self.errors = '\n'.join(e.msg for e in errors)
 
1769
 
 
1770
 
 
1771
class ConfigOptionValueError(BzrError):
 
1772
 
 
1773
    _fmt = ('Bad value "%(value)s" for option "%(name)s".\n'
 
1774
            'See ``bzr help %(name)s``')
 
1775
 
 
1776
    def __init__(self, name, value):
 
1777
        BzrError.__init__(self, name=name, value=value)
1678
1778
 
1679
1779
 
1680
1780
class NoEmailInUsername(BzrError):
1688
1788
 
1689
1789
class SigningFailed(BzrError):
1690
1790
 
1691
 
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
 
1791
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
1692
1792
 
1693
1793
    def __init__(self, command_line):
1694
1794
        BzrError.__init__(self, command_line=command_line)
1695
1795
 
1696
1796
 
 
1797
class SignatureVerificationFailed(BzrError):
 
1798
 
 
1799
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
 
1800
 
 
1801
    def __init__(self, error):
 
1802
        BzrError.__init__(self, error=error)
 
1803
 
 
1804
 
 
1805
class DependencyNotPresent(BzrError):
 
1806
 
 
1807
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1808
 
 
1809
    def __init__(self, library, error):
 
1810
        BzrError.__init__(self, library=library, error=error)
 
1811
 
 
1812
 
 
1813
class GpgmeNotInstalled(DependencyNotPresent):
 
1814
 
 
1815
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
 
1816
 
 
1817
    def __init__(self, error):
 
1818
        DependencyNotPresent.__init__(self, 'gpgme', error)
 
1819
 
 
1820
 
1697
1821
class WorkingTreeNotRevision(BzrError):
1698
1822
 
1699
 
    _fmt = ("The working tree for %(basedir)s has changed since" 
 
1823
    _fmt = ("The working tree for %(basedir)s has changed since"
1700
1824
            " the last commit, but weave merge requires that it be"
1701
1825
            " unchanged")
1702
1826
 
1815
1939
        self.prefix = prefix
1816
1940
 
1817
1941
 
1818
 
class MalformedTransform(BzrError):
 
1942
class MalformedTransform(InternalBzrError):
1819
1943
 
1820
1944
    _fmt = "Tree transform is malformed %(conflicts)r"
1821
1945
 
1859
1983
    _fmt = "Moving the root directory is not supported at this time"
1860
1984
 
1861
1985
 
 
1986
class TransformRenameFailed(BzrError):
 
1987
 
 
1988
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
 
1989
 
 
1990
    def __init__(self, from_path, to_path, why, errno):
 
1991
        self.from_path = from_path
 
1992
        self.to_path = to_path
 
1993
        self.why = why
 
1994
        self.errno = errno
 
1995
 
 
1996
 
1862
1997
class BzrMoveFailedError(BzrError):
1863
1998
 
1864
 
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1999
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
 
2000
        "%(_has_extra)s%(extra)s")
1865
2001
 
1866
2002
    def __init__(self, from_path='', to_path='', extra=None):
 
2003
        from bzrlib.osutils import splitpath
1867
2004
        BzrError.__init__(self)
1868
2005
        if extra:
1869
 
            self.extra = ': ' + str(extra)
 
2006
            self.extra, self._has_extra = extra, ': '
1870
2007
        else:
1871
 
            self.extra = ''
 
2008
            self.extra = self._has_extra = ''
1872
2009
 
1873
2010
        has_from = len(from_path) > 0
1874
2011
        has_to = len(to_path) > 0
1875
2012
        if has_from:
1876
 
            self.from_path = osutils.splitpath(from_path)[-1]
 
2013
            self.from_path = splitpath(from_path)[-1]
1877
2014
        else:
1878
2015
            self.from_path = ''
1879
2016
 
1880
2017
        if has_to:
1881
 
            self.to_path = osutils.splitpath(to_path)[-1]
 
2018
            self.to_path = splitpath(to_path)[-1]
1882
2019
        else:
1883
2020
            self.to_path = ''
1884
2021
 
1895
2032
 
1896
2033
class BzrRenameFailedError(BzrMoveFailedError):
1897
2034
 
1898
 
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
2035
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
 
2036
        "%(_has_extra)s%(extra)s")
1899
2037
 
1900
2038
    def __init__(self, from_path, to_path, extra=None):
1901
2039
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1902
2040
 
1903
 
class BzrRemoveChangedFilesError(BzrError):
1904
 
    """Used when user is trying to remove changed files."""
1905
 
 
1906
 
    _fmt = ("Can't safely remove modified or unknown files:\n"
1907
 
        "%(changes_as_text)s"
1908
 
        "Use --keep to not delete them, or --force to delete them regardless.")
1909
 
 
1910
 
    def __init__(self, tree_delta):
1911
 
        BzrError.__init__(self)
1912
 
        self.changes_as_text = tree_delta.get_changes_as_text()
1913
 
        #self.paths_as_string = '\n'.join(changed_files)
1914
 
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
1915
 
 
1916
2041
 
1917
2042
class BzrBadParameterNotString(BzrBadParameter):
1918
2043
 
1921
2046
 
1922
2047
class BzrBadParameterMissing(BzrBadParameter):
1923
2048
 
1924
 
    _fmt = "Parameter $(param)s is required but not present."
 
2049
    _fmt = "Parameter %(param)s is required but not present."
1925
2050
 
1926
2051
 
1927
2052
class BzrBadParameterUnicode(BzrBadParameter):
1935
2060
    _fmt = "Parameter %(param)s contains a newline."
1936
2061
 
1937
2062
 
1938
 
class DependencyNotPresent(BzrError):
1939
 
 
1940
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1941
 
 
1942
 
    def __init__(self, library, error):
1943
 
        BzrError.__init__(self, library=library, error=error)
1944
 
 
1945
 
 
1946
2063
class ParamikoNotPresent(DependencyNotPresent):
1947
2064
 
1948
2065
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1967
2084
 
1968
2085
class BadConversionTarget(BzrError):
1969
2086
 
1970
 
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
 
2087
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
 
2088
            "    %(problem)s"
1971
2089
 
1972
 
    def __init__(self, problem, format):
 
2090
    def __init__(self, problem, format, from_format=None):
1973
2091
        BzrError.__init__(self)
1974
2092
        self.problem = problem
1975
2093
        self.format = format
 
2094
        self.from_format = from_format or '(unspecified)'
1976
2095
 
1977
2096
 
1978
2097
class NoDiffFound(BzrError):
2015
2134
    _fmt = """This tree contains left-over files from a failed operation.
2016
2135
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2017
2136
    keep, and delete it when you are done."""
2018
 
    
 
2137
 
2019
2138
    def __init__(self, limbo_dir):
2020
2139
       BzrError.__init__(self)
2021
2140
       self.limbo_dir = limbo_dir
2054
2173
 
2055
2174
class OutOfDateTree(BzrError):
2056
2175
 
2057
 
    _fmt = "Working tree is out of date, please run 'bzr update'."
 
2176
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
2058
2177
 
2059
 
    def __init__(self, tree):
 
2178
    def __init__(self, tree, more=None):
 
2179
        if more is None:
 
2180
            more = ''
 
2181
        else:
 
2182
            more = ' ' + more
2060
2183
        BzrError.__init__(self)
2061
2184
        self.tree = tree
 
2185
        self.more = more
2062
2186
 
2063
2187
 
2064
2188
class PublicBranchOutOfDate(BzrError):
2102
2226
 
2103
2227
    def __init__(self, repo):
2104
2228
        BzrError.__init__(self)
2105
 
        self.repo_path = repo.bzrdir.root_transport.base
 
2229
        self.repo_path = repo.user_url
2106
2230
 
2107
2231
 
2108
2232
class InconsistentDelta(BzrError):
2118
2242
        self.reason = reason
2119
2243
 
2120
2244
 
 
2245
class InconsistentDeltaDelta(InconsistentDelta):
 
2246
    """Used when we get a delta that is not valid."""
 
2247
 
 
2248
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
 
2249
            "\nreason: %(reason)s")
 
2250
 
 
2251
    def __init__(self, delta, reason):
 
2252
        BzrError.__init__(self)
 
2253
        self.delta = delta
 
2254
        self.reason = reason
 
2255
 
 
2256
 
2121
2257
class UpgradeRequired(BzrError):
2122
2258
 
2123
2259
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2132
2268
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2133
2269
 
2134
2270
 
 
2271
class RichRootUpgradeRequired(UpgradeRequired):
 
2272
 
 
2273
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
 
2274
           " a format which supports rich roots.")
 
2275
 
 
2276
 
2135
2277
class LocalRequiresBoundBranch(BzrError):
2136
2278
 
2137
2279
    _fmt = "Cannot perform local-only commits on unbound branches."
2138
2280
 
2139
2281
 
2140
 
class MissingProgressBarFinish(BzrError):
2141
 
 
2142
 
    _fmt = "A nested progress bar was not 'finished' correctly."
2143
 
 
2144
 
 
2145
 
class InvalidProgressBarType(BzrError):
2146
 
 
2147
 
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
2148
 
            " is not a supported type Select one of: %(valid_types)s")
2149
 
 
2150
 
    def __init__(self, bar_type, valid_types):
2151
 
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
2152
 
 
2153
 
 
2154
2282
class UnsupportedOperation(BzrError):
2155
2283
 
2156
2284
    _fmt = ("The method %(mname)s is not supported on"
2172
2300
    """
2173
2301
 
2174
2302
 
 
2303
class GhostTagsNotSupported(BzrError):
 
2304
 
 
2305
    _fmt = "Ghost tags not supported by format %(format)r."
 
2306
 
 
2307
    def __init__(self, format):
 
2308
        self.format = format
 
2309
 
 
2310
 
2175
2311
class BinaryFile(BzrError):
2176
 
    
 
2312
 
2177
2313
    _fmt = "File is binary but should be text."
2178
2314
 
2179
2315
 
2199
2335
 
2200
2336
 
2201
2337
class NotABundle(BzrError):
2202
 
    
 
2338
 
2203
2339
    _fmt = "Not a bzr revision-bundle: %(text)r"
2204
2340
 
2205
2341
    def __init__(self, text):
2207
2343
        self.text = text
2208
2344
 
2209
2345
 
2210
 
class BadBundle(BzrError): 
2211
 
    
 
2346
class BadBundle(BzrError):
 
2347
 
2212
2348
    _fmt = "Bad bzr revision-bundle: %(text)r"
2213
2349
 
2214
2350
    def __init__(self, text):
2216
2352
        self.text = text
2217
2353
 
2218
2354
 
2219
 
class MalformedHeader(BadBundle): 
2220
 
    
 
2355
class MalformedHeader(BadBundle):
 
2356
 
2221
2357
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2222
2358
 
2223
2359
 
2224
 
class MalformedPatches(BadBundle): 
2225
 
    
 
2360
class MalformedPatches(BadBundle):
 
2361
 
2226
2362
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2227
2363
 
2228
2364
 
2229
 
class MalformedFooter(BadBundle): 
2230
 
    
 
2365
class MalformedFooter(BadBundle):
 
2366
 
2231
2367
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2232
2368
 
2233
2369
 
2234
2370
class UnsupportedEOLMarker(BadBundle):
2235
 
    
2236
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
 
2371
 
 
2372
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
2237
2373
 
2238
2374
    def __init__(self):
2239
 
        # XXX: BadBundle's constructor assumes there's explanatory text, 
 
2375
        # XXX: BadBundle's constructor assumes there's explanatory text,
2240
2376
        # but for this there is not
2241
2377
        BzrError.__init__(self)
2242
2378
 
2243
2379
 
2244
2380
class IncompatibleBundleFormat(BzrError):
2245
 
    
 
2381
 
2246
2382
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2247
2383
 
2248
2384
    def __init__(self, bundle_format, other):
2252
2388
 
2253
2389
 
2254
2390
class BadInventoryFormat(BzrError):
2255
 
    
 
2391
 
2256
2392
    _fmt = "Root class for inventory serialization errors"
2257
2393
 
2258
2394
 
2277
2413
        self.transport = transport
2278
2414
 
2279
2415
 
2280
 
class NoSmartServer(NotBranchError):
2281
 
 
2282
 
    _fmt = "No smart server available at %(url)s"
2283
 
 
2284
 
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
2285
 
    def __init__(self, url):
2286
 
        self.url = url
2287
 
 
2288
 
 
2289
2416
class UnknownSSH(BzrError):
2290
2417
 
2291
2418
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2311
2438
        self.revision_id = revision_id
2312
2439
        self.ghost_revision_id = ghost_revision_id
2313
2440
 
2314
 
        
 
2441
 
2315
2442
class GhostRevisionUnusableHere(BzrError):
2316
2443
 
2317
2444
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2409
2536
 
2410
2537
 
2411
2538
class UnsupportedInventoryKind(BzrError):
2412
 
    
 
2539
 
2413
2540
    _fmt = """Unsupported entry kind %(kind)s"""
2414
2541
 
2415
2542
    def __init__(self, kind):
2427
2554
 
2428
2555
 
2429
2556
class SubsumeTargetNeedsUpgrade(BzrError):
2430
 
    
 
2557
 
2431
2558
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2432
2559
 
2433
2560
    def __init__(self, other_tree):
2461
2588
    def __init__(self, branch):
2462
2589
        self.branch = branch
2463
2590
 
2464
 
        
 
2591
 
2465
2592
class TagAlreadyExists(BzrError):
2466
2593
 
2467
2594
    _fmt = "Tag %(tag_name)s already exists."
2472
2599
 
2473
2600
class MalformedBugIdentifier(BzrError):
2474
2601
 
2475
 
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2602
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
2603
            'See "bzr help bugs" for more information on this feature.')
2476
2604
 
2477
2605
    def __init__(self, bug_id, reason):
2478
2606
        self.bug_id = bug_id
2499
2627
        self.branch = branch
2500
2628
 
2501
2629
 
 
2630
class InvalidLineInBugsProperty(BzrError):
 
2631
 
 
2632
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
2633
 
 
2634
    def __init__(self, line):
 
2635
        self.line = line
 
2636
 
 
2637
 
 
2638
class InvalidBugStatus(BzrError):
 
2639
 
 
2640
    _fmt = ("Invalid bug status: '%(status)s'")
 
2641
 
 
2642
    def __init__(self, status):
 
2643
        self.status = status
 
2644
 
 
2645
 
2502
2646
class UnexpectedSmartServerResponse(BzrError):
2503
2647
 
2504
2648
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2508
2652
 
2509
2653
 
2510
2654
class ErrorFromSmartServer(BzrError):
 
2655
    """An error was received from a smart server.
 
2656
 
 
2657
    :seealso: UnknownErrorFromSmartServer
 
2658
    """
2511
2659
 
2512
2660
    _fmt = "Error received from smart server: %(error_tuple)r"
2513
2661
 
2522
2670
        self.error_args = error_tuple[1:]
2523
2671
 
2524
2672
 
 
2673
class UnknownErrorFromSmartServer(BzrError):
 
2674
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
 
2675
    error.
 
2676
 
 
2677
    This is distinct from ErrorFromSmartServer so that it is possible to
 
2678
    distinguish between the following two cases:
 
2679
 
 
2680
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2681
      and so should provoke a traceback to the user.
 
2682
    - ErrorFromSmartServer was caught but its error_tuple could not be
 
2683
      translated.  This is probably because the server sent us garbage, and
 
2684
      should not provoke a traceback.
 
2685
    """
 
2686
 
 
2687
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
 
2688
 
 
2689
    internal_error = False
 
2690
 
 
2691
    def __init__(self, error_from_smart_server):
 
2692
        """Constructor.
 
2693
 
 
2694
        :param error_from_smart_server: An ErrorFromSmartServer instance.
 
2695
        """
 
2696
        self.error_from_smart_server = error_from_smart_server
 
2697
        self.error_tuple = error_from_smart_server.error_tuple
 
2698
 
 
2699
 
2525
2700
class ContainerError(BzrError):
2526
2701
    """Base class of container errors."""
2527
2702
 
2529
2704
class UnknownContainerFormatError(ContainerError):
2530
2705
 
2531
2706
    _fmt = "Unrecognised container format: %(container_format)r"
2532
 
    
 
2707
 
2533
2708
    def __init__(self, container_format):
2534
2709
        self.container_format = container_format
2535
2710
 
2568
2743
    _fmt = "Container has multiple records with the same name: %(name)s"
2569
2744
 
2570
2745
    def __init__(self, name):
2571
 
        self.name = name
 
2746
        self.name = name.decode("utf-8")
2572
2747
 
2573
2748
 
2574
2749
class NoDestinationAddress(InternalBzrError):
2599
2774
 
2600
2775
class NoMailAddressSpecified(BzrError):
2601
2776
 
2602
 
    _fmt = "No mail-to address specified."
2603
 
 
2604
 
 
2605
 
class UnknownMailClient(BzrError):
2606
 
 
2607
 
    _fmt = "Unknown mail client: %(mail_client)s"
2608
 
 
2609
 
    def __init__(self, mail_client):
2610
 
        BzrError.__init__(self, mail_client=mail_client)
 
2777
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
2611
2778
 
2612
2779
 
2613
2780
class MailClientNotFound(BzrError):
2638
2805
 
2639
2806
    def __init__(self, bzrdir):
2640
2807
        import bzrlib.urlutils as urlutils
2641
 
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2808
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
2642
2809
                                                    'ascii')
2643
2810
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2644
2811
 
2685
2852
    _fmt = "'%(display_url)s' is already standalone."
2686
2853
 
2687
2854
 
 
2855
class AlreadyWithTrees(BzrDirError):
 
2856
 
 
2857
    _fmt = ("Shared repository '%(display_url)s' already creates "
 
2858
            "working trees.")
 
2859
 
 
2860
 
 
2861
class AlreadyWithNoTrees(BzrDirError):
 
2862
 
 
2863
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
 
2864
            "working trees.")
 
2865
 
 
2866
 
2688
2867
class ReconfigurationNotSupported(BzrDirError):
2689
2868
 
2690
2869
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2697
2876
 
2698
2877
class UncommittedChanges(BzrError):
2699
2878
 
2700
 
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2701
 
 
2702
 
    def __init__(self, tree):
2703
 
        import bzrlib.urlutils as urlutils
2704
 
        display_url = urlutils.unescape_for_display(
2705
 
            tree.bzrdir.root_transport.base, 'ascii')
2706
 
        BzrError.__init__(self, tree=tree, display_url=display_url)
 
2879
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
 
2880
            ' (See bzr status).%(more)s')
 
2881
 
 
2882
    def __init__(self, tree, more=None):
 
2883
        if more is None:
 
2884
            more = ''
 
2885
        else:
 
2886
            more = ' ' + more
 
2887
        import bzrlib.urlutils as urlutils
 
2888
        user_url = getattr(tree, "user_url", None)
 
2889
        if user_url is None:
 
2890
            display_url = str(tree)
 
2891
        else:
 
2892
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
 
2893
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
 
2894
 
 
2895
 
 
2896
class StoringUncommittedNotSupported(BzrError):
 
2897
 
 
2898
    _fmt = ('Branch "%(display_url)s" does not support storing uncommitted'
 
2899
            ' changes.')
 
2900
 
 
2901
    def __init__(self, branch):
 
2902
        import bzrlib.urlutils as urlutils
 
2903
        user_url = getattr(branch, "user_url", None)
 
2904
        if user_url is None:
 
2905
            display_url = str(branch)
 
2906
        else:
 
2907
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
 
2908
        BzrError.__init__(self, branch=branch, display_url=display_url)
 
2909
 
 
2910
 
 
2911
class ShelvedChanges(UncommittedChanges):
 
2912
 
 
2913
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
 
2914
            ' (See bzr shelve --list).%(more)s')
2707
2915
 
2708
2916
 
2709
2917
class MissingTemplateVariable(BzrError):
2744
2952
 
2745
2953
 
2746
2954
class CommandAvailableInPlugin(StandardError):
2747
 
    
 
2955
 
2748
2956
    internal_error = False
2749
2957
 
2750
2958
    def __init__(self, cmd_name, plugin_metadata, provider):
2751
 
        
 
2959
 
2752
2960
        self.plugin_metadata = plugin_metadata
2753
2961
        self.cmd_name = cmd_name
2754
2962
        self.provider = provider
2755
2963
 
2756
2964
    def __str__(self):
2757
2965
 
2758
 
        _fmt = ('"%s" is not a standard bzr command. \n' 
 
2966
        _fmt = ('"%s" is not a standard bzr command. \n'
2759
2967
                'However, the following official plugin provides this command: %s\n'
2760
2968
                'You can install it by going to: %s'
2761
 
                % (self.cmd_name, self.plugin_metadata['name'], 
 
2969
                % (self.cmd_name, self.plugin_metadata['name'],
2762
2970
                    self.plugin_metadata['url']))
2763
2971
 
2764
2972
        return _fmt
2765
2973
 
2766
2974
 
2767
2975
class NoPluginAvailable(BzrError):
2768
 
    pass    
2769
 
 
2770
 
 
2771
 
class NotATerminal(BzrError):
2772
 
 
2773
 
    _fmt = 'Unable to ask for a password without real terminal.'
 
2976
    pass
2774
2977
 
2775
2978
 
2776
2979
class UnableEncodePath(BzrError):
2779
2982
            'user encoding %(user_encoding)s')
2780
2983
 
2781
2984
    def __init__(self, path, kind):
 
2985
        from bzrlib.osutils import get_user_encoding
2782
2986
        self.path = path
2783
2987
        self.kind = kind
2784
 
        self.user_encoding = osutils.get_user_encoding()
 
2988
        self.user_encoding = get_user_encoding()
 
2989
 
 
2990
 
 
2991
class NoSuchConfig(BzrError):
 
2992
 
 
2993
    _fmt = ('The "%(config_id)s" configuration does not exist.')
 
2994
 
 
2995
    def __init__(self, config_id):
 
2996
        BzrError.__init__(self, config_id=config_id)
 
2997
 
 
2998
 
 
2999
class NoSuchConfigOption(BzrError):
 
3000
 
 
3001
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
 
3002
 
 
3003
    def __init__(self, option_name):
 
3004
        BzrError.__init__(self, option_name=option_name)
2785
3005
 
2786
3006
 
2787
3007
class NoSuchAlias(BzrError):
2819
3039
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2820
3040
 
2821
3041
    def __init__(self, host, port, orig_error):
 
3042
        # nb: in python2.4 socket.error doesn't have a useful repr
2822
3043
        BzrError.__init__(self, host=host, port=port,
2823
 
            orig_error=orig_error[1])
 
3044
            orig_error=repr(orig_error.args))
2824
3045
 
2825
3046
 
2826
3047
class UnknownRules(BzrError):
2831
3052
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2832
3053
 
2833
3054
 
2834
 
class HookFailed(BzrError):
2835
 
    """Raised when a pre_change_branch_tip hook function fails anything other
2836
 
    than TipChangeRejected.
2837
 
    """
2838
 
 
2839
 
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2840
 
            "%(traceback_text)s%(exc_value)s")
2841
 
 
2842
 
    def __init__(self, hook_stage, hook_name, exc_info):
2843
 
        import traceback
2844
 
        self.hook_stage = hook_stage
2845
 
        self.hook_name = hook_name
2846
 
        self.exc_info = exc_info
2847
 
        self.exc_type = exc_info[0]
2848
 
        self.exc_value = exc_info[1]
2849
 
        self.exc_tb = exc_info[2]
2850
 
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2851
 
 
2852
 
 
2853
3055
class TipChangeRejected(BzrError):
2854
3056
    """A pre_change_branch_tip hook function may raise this to cleanly and
2855
3057
    explicitly abort a change to a branch tip.
2856
3058
    """
2857
 
    
 
3059
 
2858
3060
    _fmt = u"Tip change rejected: %(msg)s"
2859
3061
 
2860
3062
    def __init__(self, msg):
2861
3063
        self.msg = msg
2862
3064
 
 
3065
 
 
3066
class ShelfCorrupt(BzrError):
 
3067
 
 
3068
    _fmt = "Shelf corrupt."
 
3069
 
 
3070
 
 
3071
class DecompressCorruption(BzrError):
 
3072
 
 
3073
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
 
3074
 
 
3075
    def __init__(self, orig_error=None):
 
3076
        if orig_error is not None:
 
3077
            self.orig_error = ", %s" % (orig_error,)
 
3078
        else:
 
3079
            self.orig_error = ""
 
3080
        BzrError.__init__(self)
 
3081
 
 
3082
 
 
3083
class NoSuchShelfId(BzrError):
 
3084
 
 
3085
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
 
3086
 
 
3087
    def __init__(self, shelf_id):
 
3088
        BzrError.__init__(self, shelf_id=shelf_id)
 
3089
 
 
3090
 
 
3091
class InvalidShelfId(BzrError):
 
3092
 
 
3093
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
 
3094
 
 
3095
    def __init__(self, invalid_id):
 
3096
        BzrError.__init__(self, invalid_id=invalid_id)
 
3097
 
 
3098
 
 
3099
class JailBreak(BzrError):
 
3100
 
 
3101
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
 
3102
 
 
3103
    def __init__(self, url):
 
3104
        BzrError.__init__(self, url=url)
 
3105
 
 
3106
 
 
3107
class UserAbort(BzrError):
 
3108
 
 
3109
    _fmt = 'The user aborted the operation.'
 
3110
 
 
3111
 
 
3112
class MustHaveWorkingTree(BzrError):
 
3113
 
 
3114
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
 
3115
 
 
3116
    def __init__(self, format, url):
 
3117
        BzrError.__init__(self, format=format, url=url)
 
3118
 
 
3119
 
 
3120
class NoSuchView(BzrError):
 
3121
    """A view does not exist.
 
3122
    """
 
3123
 
 
3124
    _fmt = u"No such view: %(view_name)s."
 
3125
 
 
3126
    def __init__(self, view_name):
 
3127
        self.view_name = view_name
 
3128
 
 
3129
 
 
3130
class ViewsNotSupported(BzrError):
 
3131
    """Views are not supported by a tree format.
 
3132
    """
 
3133
 
 
3134
    _fmt = ("Views are not supported by %(tree)s;"
 
3135
            " use 'bzr upgrade' to change your tree to a later format.")
 
3136
 
 
3137
    def __init__(self, tree):
 
3138
        self.tree = tree
 
3139
 
 
3140
 
 
3141
class FileOutsideView(BzrError):
 
3142
 
 
3143
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
3144
            '%(view_str)s')
 
3145
 
 
3146
    def __init__(self, file_name, view_files):
 
3147
        self.file_name = file_name
 
3148
        self.view_str = ", ".join(view_files)
 
3149
 
 
3150
 
 
3151
class UnresumableWriteGroup(BzrError):
 
3152
 
 
3153
    _fmt = ("Repository %(repository)s cannot resume write group "
 
3154
            "%(write_groups)r: %(reason)s")
 
3155
 
 
3156
    internal_error = True
 
3157
 
 
3158
    def __init__(self, repository, write_groups, reason):
 
3159
        self.repository = repository
 
3160
        self.write_groups = write_groups
 
3161
        self.reason = reason
 
3162
 
 
3163
 
 
3164
class UnsuspendableWriteGroup(BzrError):
 
3165
 
 
3166
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
 
3167
 
 
3168
    internal_error = True
 
3169
 
 
3170
    def __init__(self, repository):
 
3171
        self.repository = repository
 
3172
 
 
3173
 
 
3174
class LossyPushToSameVCS(BzrError):
 
3175
 
 
3176
    _fmt = ("Lossy push not possible between %(source_branch)r and "
 
3177
            "%(target_branch)r that are in the same VCS.")
 
3178
 
 
3179
    internal_error = True
 
3180
 
 
3181
    def __init__(self, source_branch, target_branch):
 
3182
        self.source_branch = source_branch
 
3183
        self.target_branch = target_branch
 
3184
 
 
3185
 
 
3186
class NoRoundtrippingSupport(BzrError):
 
3187
 
 
3188
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
 
3189
            "%(target_branch)r.")
 
3190
 
 
3191
    internal_error = True
 
3192
 
 
3193
    def __init__(self, source_branch, target_branch):
 
3194
        self.source_branch = source_branch
 
3195
        self.target_branch = target_branch
 
3196
 
 
3197
 
 
3198
class FileTimestampUnavailable(BzrError):
 
3199
 
 
3200
    _fmt = "The filestamp for %(path)s is not available."
 
3201
 
 
3202
    internal_error = True
 
3203
 
 
3204
    def __init__(self, path):
 
3205
        self.path = path
 
3206
 
 
3207
 
 
3208
class NoColocatedBranchSupport(BzrError):
 
3209
 
 
3210
    _fmt = ("%(bzrdir)r does not support co-located branches.")
 
3211
 
 
3212
    def __init__(self, bzrdir):
 
3213
        self.bzrdir = bzrdir
 
3214
 
 
3215
 
 
3216
class NoWhoami(BzrError):
 
3217
 
 
3218
    _fmt = ('Unable to determine your name.\n'
 
3219
        "Please, set your name with the 'whoami' command.\n"
 
3220
        'E.g. bzr whoami "Your Name <name@example.com>"')
 
3221
 
 
3222
 
 
3223
class InvalidPattern(BzrError):
 
3224
 
 
3225
    _fmt = ('Invalid pattern(s) found. %(msg)s')
 
3226
 
 
3227
    def __init__(self, msg):
 
3228
        self.msg = msg
 
3229
 
 
3230
 
 
3231
class RecursiveBind(BzrError):
 
3232
 
 
3233
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
 
3234
        'Please use `bzr unbind` to fix.')
 
3235
 
 
3236
    def __init__(self, branch_url):
 
3237
        self.branch_url = branch_url
 
3238
 
 
3239
 
 
3240
# FIXME: I would prefer to define the config related exception classes in
 
3241
# config.py but the lazy import mechanism proscribes this -- vila 20101222
 
3242
class OptionExpansionLoop(BzrError):
 
3243
 
 
3244
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
 
3245
 
 
3246
    def __init__(self, string, refs):
 
3247
        self.string = string
 
3248
        self.refs = '->'.join(refs)
 
3249
 
 
3250
 
 
3251
class ExpandingUnknownOption(BzrError):
 
3252
 
 
3253
    _fmt = 'Option "%(name)s" is not defined while expanding "%(string)s".'
 
3254
 
 
3255
    def __init__(self, name, string):
 
3256
        self.name = name
 
3257
        self.string = string
 
3258
 
 
3259
 
 
3260
class IllegalOptionName(BzrError):
 
3261
 
 
3262
    _fmt = 'Option "%(name)s" is not allowed.'
 
3263
 
 
3264
    def __init__(self, name):
 
3265
        self.name = name
 
3266
 
 
3267
 
 
3268
class NoCompatibleInter(BzrError):
 
3269
 
 
3270
    _fmt = ('No compatible object available for operations from %(source)r '
 
3271
            'to %(target)r.')
 
3272
 
 
3273
    def __init__(self, source, target):
 
3274
        self.source = source
 
3275
        self.target = target
 
3276
 
 
3277
 
 
3278
class HpssVfsRequestNotAllowed(BzrError):
 
3279
 
 
3280
    _fmt = ("VFS requests over the smart server are not allowed. Encountered: "
 
3281
            "%(method)s, %(arguments)s.")
 
3282
 
 
3283
    def __init__(self, method, arguments):
 
3284
        self.method = method
 
3285
        self.arguments = arguments
 
3286
 
 
3287
 
 
3288
class UnsupportedKindChange(BzrError):
 
3289
 
 
3290
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
 
3291
            "%(path)s not supported by format %(format)r")
 
3292
 
 
3293
    def __init__(self, path, from_kind, to_kind, format):
 
3294
        self.path = path
 
3295
        self.from_kind = from_kind
 
3296
        self.to_kind = to_kind
 
3297
        self.format = format
 
3298
 
 
3299
 
 
3300
class MissingFeature(BzrError):
 
3301
 
 
3302
    _fmt = ("Missing feature %(feature)s not provided by this "
 
3303
            "version of Bazaar or any plugin.")
 
3304
 
 
3305
    def __init__(self, feature):
 
3306
        self.feature = feature
 
3307
 
 
3308
 
 
3309
class PatchSyntax(BzrError):
 
3310
    """Base class for patch syntax errors."""
 
3311
 
 
3312
 
 
3313
class BinaryFiles(BzrError):
 
3314
 
 
3315
    _fmt = 'Binary files section encountered.'
 
3316
 
 
3317
    def __init__(self, orig_name, mod_name):
 
3318
        self.orig_name = orig_name
 
3319
        self.mod_name = mod_name
 
3320
 
 
3321
 
 
3322
class MalformedPatchHeader(PatchSyntax):
 
3323
 
 
3324
    _fmt = "Malformed patch header.  %(desc)s\n%(line)r"
 
3325
 
 
3326
    def __init__(self, desc, line):
 
3327
        self.desc = desc
 
3328
        self.line = line
 
3329
 
 
3330
 
 
3331
class MalformedHunkHeader(PatchSyntax):
 
3332
 
 
3333
    _fmt = "Malformed hunk header.  %(desc)s\n%(line)r"
 
3334
 
 
3335
    def __init__(self, desc, line):
 
3336
        self.desc = desc
 
3337
        self.line = line
 
3338
 
 
3339
 
 
3340
class MalformedLine(PatchSyntax):
 
3341
 
 
3342
    _fmt = "Malformed line.  %(desc)s\n%(line)r"
 
3343
 
 
3344
    def __init__(self, desc, line):
 
3345
        self.desc = desc
 
3346
        self.line = line
 
3347
 
 
3348
 
 
3349
class PatchConflict(BzrError):
 
3350
 
 
3351
    _fmt = ('Text contents mismatch at line %(line_no)d.  Original has '
 
3352
            '"%(orig_line)s", but patch says it should be "%(patch_line)s"')
 
3353
 
 
3354
    def __init__(self, line_no, orig_line, patch_line):
 
3355
        self.line_no = line_no
 
3356
        self.orig_line = orig_line.rstrip('\n')
 
3357
        self.patch_line = patch_line.rstrip('\n')
 
3358
 
 
3359
 
 
3360
class FeatureAlreadyRegistered(BzrError):
 
3361
 
 
3362
    _fmt = 'The feature %(feature)s has already been registered.'
 
3363
 
 
3364
    def __init__(self, feature):
 
3365
        self.feature = feature
 
3366
 
 
3367
 
 
3368
class ChangesAlreadyStored(BzrCommandError):
 
3369
 
 
3370
    _fmt = ('Cannot store uncommitted changes because this branch already'
 
3371
            ' stores uncommitted changes.')