~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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-2013, 2016 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
 
1600
1695
        InvalidHttpResponse.__init__(self, path, msg)
1601
1696
 
1602
1697
 
 
1698
class HttpBoundaryMissing(InvalidHttpResponse):
 
1699
    """A multipart response ends with no boundary marker.
 
1700
 
 
1701
    This is a special case caused by buggy proxies, described in
 
1702
    <https://bugs.launchpad.net/bzr/+bug/198646>.
 
1703
    """
 
1704
 
 
1705
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
 
1706
 
 
1707
    def __init__(self, path, msg):
 
1708
        InvalidHttpResponse.__init__(self, path, msg)
 
1709
 
 
1710
 
1603
1711
class InvalidHttpContentType(InvalidHttpResponse):
1604
1712
 
1605
1713
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1613
1721
 
1614
1722
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1615
1723
 
1616
 
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
 
1724
    def __init__(self, source, target, is_permanent=False):
1617
1725
        self.source = source
1618
1726
        self.target = target
1619
1727
        if is_permanent:
1620
1728
            self.permanently = ' permanently'
1621
1729
        else:
1622
1730
            self.permanently = ''
1623
 
        self._qualified_proto = qual_proto
1624
1731
        TransportError.__init__(self)
1625
1732
 
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
1733
 
1660
1734
class TooManyRedirections(TransportError):
1661
1735
 
1667
1741
    _fmt = "Working tree has conflicts."
1668
1742
 
1669
1743
 
 
1744
class ConfigContentError(BzrError):
 
1745
 
 
1746
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
 
1747
 
 
1748
    def __init__(self, filename):
 
1749
        BzrError.__init__(self)
 
1750
        self.filename = filename
 
1751
 
 
1752
 
1670
1753
class ParseConfigError(BzrError):
1671
1754
 
 
1755
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
 
1756
 
1672
1757
    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)
 
1758
        BzrError.__init__(self)
 
1759
        self.filename = filename
 
1760
        self.errors = '\n'.join(e.msg for e in errors)
 
1761
 
 
1762
 
 
1763
class ConfigOptionValueError(BzrError):
 
1764
 
 
1765
    _fmt = ('Bad value "%(value)s" for option "%(name)s".\n'
 
1766
            'See ``bzr help %(name)s``')
 
1767
 
 
1768
    def __init__(self, name, value):
 
1769
        BzrError.__init__(self, name=name, value=value)
1678
1770
 
1679
1771
 
1680
1772
class NoEmailInUsername(BzrError):
1688
1780
 
1689
1781
class SigningFailed(BzrError):
1690
1782
 
1691
 
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
 
1783
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
1692
1784
 
1693
1785
    def __init__(self, command_line):
1694
1786
        BzrError.__init__(self, command_line=command_line)
1695
1787
 
1696
1788
 
 
1789
class SignatureVerificationFailed(BzrError):
 
1790
 
 
1791
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
 
1792
 
 
1793
    def __init__(self, error):
 
1794
        BzrError.__init__(self, error=error)
 
1795
 
 
1796
 
 
1797
class DependencyNotPresent(BzrError):
 
1798
 
 
1799
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1800
 
 
1801
    def __init__(self, library, error):
 
1802
        BzrError.__init__(self, library=library, error=error)
 
1803
 
 
1804
 
 
1805
class GpgmeNotInstalled(DependencyNotPresent):
 
1806
 
 
1807
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
 
1808
 
 
1809
    def __init__(self, error):
 
1810
        DependencyNotPresent.__init__(self, 'gpgme', error)
 
1811
 
 
1812
 
1697
1813
class WorkingTreeNotRevision(BzrError):
1698
1814
 
1699
 
    _fmt = ("The working tree for %(basedir)s has changed since" 
 
1815
    _fmt = ("The working tree for %(basedir)s has changed since"
1700
1816
            " the last commit, but weave merge requires that it be"
1701
1817
            " unchanged")
1702
1818
 
1815
1931
        self.prefix = prefix
1816
1932
 
1817
1933
 
1818
 
class MalformedTransform(BzrError):
 
1934
class MalformedTransform(InternalBzrError):
1819
1935
 
1820
1936
    _fmt = "Tree transform is malformed %(conflicts)r"
1821
1937
 
1859
1975
    _fmt = "Moving the root directory is not supported at this time"
1860
1976
 
1861
1977
 
 
1978
class TransformRenameFailed(BzrError):
 
1979
 
 
1980
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
 
1981
 
 
1982
    def __init__(self, from_path, to_path, why, errno):
 
1983
        self.from_path = from_path
 
1984
        self.to_path = to_path
 
1985
        self.why = why
 
1986
        self.errno = errno
 
1987
 
 
1988
 
1862
1989
class BzrMoveFailedError(BzrError):
1863
1990
 
1864
 
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1991
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
 
1992
        "%(_has_extra)s%(extra)s")
1865
1993
 
1866
1994
    def __init__(self, from_path='', to_path='', extra=None):
 
1995
        from bzrlib.osutils import splitpath
1867
1996
        BzrError.__init__(self)
1868
1997
        if extra:
1869
 
            self.extra = ': ' + str(extra)
 
1998
            self.extra, self._has_extra = extra, ': '
1870
1999
        else:
1871
 
            self.extra = ''
 
2000
            self.extra = self._has_extra = ''
1872
2001
 
1873
2002
        has_from = len(from_path) > 0
1874
2003
        has_to = len(to_path) > 0
1875
2004
        if has_from:
1876
 
            self.from_path = osutils.splitpath(from_path)[-1]
 
2005
            self.from_path = splitpath(from_path)[-1]
1877
2006
        else:
1878
2007
            self.from_path = ''
1879
2008
 
1880
2009
        if has_to:
1881
 
            self.to_path = osutils.splitpath(to_path)[-1]
 
2010
            self.to_path = splitpath(to_path)[-1]
1882
2011
        else:
1883
2012
            self.to_path = ''
1884
2013
 
1895
2024
 
1896
2025
class BzrRenameFailedError(BzrMoveFailedError):
1897
2026
 
1898
 
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
2027
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
 
2028
        "%(_has_extra)s%(extra)s")
1899
2029
 
1900
2030
    def __init__(self, from_path, to_path, extra=None):
1901
2031
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1902
2032
 
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
2033
 
1917
2034
class BzrBadParameterNotString(BzrBadParameter):
1918
2035
 
1921
2038
 
1922
2039
class BzrBadParameterMissing(BzrBadParameter):
1923
2040
 
1924
 
    _fmt = "Parameter $(param)s is required but not present."
 
2041
    _fmt = "Parameter %(param)s is required but not present."
1925
2042
 
1926
2043
 
1927
2044
class BzrBadParameterUnicode(BzrBadParameter):
1935
2052
    _fmt = "Parameter %(param)s contains a newline."
1936
2053
 
1937
2054
 
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
2055
class ParamikoNotPresent(DependencyNotPresent):
1947
2056
 
1948
2057
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1967
2076
 
1968
2077
class BadConversionTarget(BzrError):
1969
2078
 
1970
 
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
 
2079
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
 
2080
            "    %(problem)s"
1971
2081
 
1972
 
    def __init__(self, problem, format):
 
2082
    def __init__(self, problem, format, from_format=None):
1973
2083
        BzrError.__init__(self)
1974
2084
        self.problem = problem
1975
2085
        self.format = format
 
2086
        self.from_format = from_format or '(unspecified)'
1976
2087
 
1977
2088
 
1978
2089
class NoDiffFound(BzrError):
2015
2126
    _fmt = """This tree contains left-over files from a failed operation.
2016
2127
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2017
2128
    keep, and delete it when you are done."""
2018
 
    
 
2129
 
2019
2130
    def __init__(self, limbo_dir):
2020
2131
       BzrError.__init__(self)
2021
2132
       self.limbo_dir = limbo_dir
2054
2165
 
2055
2166
class OutOfDateTree(BzrError):
2056
2167
 
2057
 
    _fmt = "Working tree is out of date, please run 'bzr update'."
 
2168
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
2058
2169
 
2059
 
    def __init__(self, tree):
 
2170
    def __init__(self, tree, more=None):
 
2171
        if more is None:
 
2172
            more = ''
 
2173
        else:
 
2174
            more = ' ' + more
2060
2175
        BzrError.__init__(self)
2061
2176
        self.tree = tree
 
2177
        self.more = more
2062
2178
 
2063
2179
 
2064
2180
class PublicBranchOutOfDate(BzrError):
2102
2218
 
2103
2219
    def __init__(self, repo):
2104
2220
        BzrError.__init__(self)
2105
 
        self.repo_path = repo.bzrdir.root_transport.base
 
2221
        self.repo_path = repo.user_url
2106
2222
 
2107
2223
 
2108
2224
class InconsistentDelta(BzrError):
2118
2234
        self.reason = reason
2119
2235
 
2120
2236
 
 
2237
class InconsistentDeltaDelta(InconsistentDelta):
 
2238
    """Used when we get a delta that is not valid."""
 
2239
 
 
2240
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
 
2241
            "\nreason: %(reason)s")
 
2242
 
 
2243
    def __init__(self, delta, reason):
 
2244
        BzrError.__init__(self)
 
2245
        self.delta = delta
 
2246
        self.reason = reason
 
2247
 
 
2248
 
2121
2249
class UpgradeRequired(BzrError):
2122
2250
 
2123
2251
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2132
2260
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2133
2261
 
2134
2262
 
 
2263
class RichRootUpgradeRequired(UpgradeRequired):
 
2264
 
 
2265
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
 
2266
           " a format which supports rich roots.")
 
2267
 
 
2268
 
2135
2269
class LocalRequiresBoundBranch(BzrError):
2136
2270
 
2137
2271
    _fmt = "Cannot perform local-only commits on unbound branches."
2138
2272
 
2139
2273
 
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
2274
class UnsupportedOperation(BzrError):
2155
2275
 
2156
2276
    _fmt = ("The method %(mname)s is not supported on"
2172
2292
    """
2173
2293
 
2174
2294
 
 
2295
class GhostTagsNotSupported(BzrError):
 
2296
 
 
2297
    _fmt = "Ghost tags not supported by format %(format)r."
 
2298
 
 
2299
    def __init__(self, format):
 
2300
        self.format = format
 
2301
 
 
2302
 
2175
2303
class BinaryFile(BzrError):
2176
 
    
 
2304
 
2177
2305
    _fmt = "File is binary but should be text."
2178
2306
 
2179
2307
 
2199
2327
 
2200
2328
 
2201
2329
class NotABundle(BzrError):
2202
 
    
 
2330
 
2203
2331
    _fmt = "Not a bzr revision-bundle: %(text)r"
2204
2332
 
2205
2333
    def __init__(self, text):
2207
2335
        self.text = text
2208
2336
 
2209
2337
 
2210
 
class BadBundle(BzrError): 
2211
 
    
 
2338
class BadBundle(BzrError):
 
2339
 
2212
2340
    _fmt = "Bad bzr revision-bundle: %(text)r"
2213
2341
 
2214
2342
    def __init__(self, text):
2216
2344
        self.text = text
2217
2345
 
2218
2346
 
2219
 
class MalformedHeader(BadBundle): 
2220
 
    
 
2347
class MalformedHeader(BadBundle):
 
2348
 
2221
2349
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2222
2350
 
2223
2351
 
2224
 
class MalformedPatches(BadBundle): 
2225
 
    
 
2352
class MalformedPatches(BadBundle):
 
2353
 
2226
2354
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2227
2355
 
2228
2356
 
2229
 
class MalformedFooter(BadBundle): 
2230
 
    
 
2357
class MalformedFooter(BadBundle):
 
2358
 
2231
2359
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2232
2360
 
2233
2361
 
2234
2362
class UnsupportedEOLMarker(BadBundle):
2235
 
    
2236
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
 
2363
 
 
2364
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
2237
2365
 
2238
2366
    def __init__(self):
2239
 
        # XXX: BadBundle's constructor assumes there's explanatory text, 
 
2367
        # XXX: BadBundle's constructor assumes there's explanatory text,
2240
2368
        # but for this there is not
2241
2369
        BzrError.__init__(self)
2242
2370
 
2243
2371
 
2244
2372
class IncompatibleBundleFormat(BzrError):
2245
 
    
 
2373
 
2246
2374
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2247
2375
 
2248
2376
    def __init__(self, bundle_format, other):
2252
2380
 
2253
2381
 
2254
2382
class BadInventoryFormat(BzrError):
2255
 
    
 
2383
 
2256
2384
    _fmt = "Root class for inventory serialization errors"
2257
2385
 
2258
2386
 
2277
2405
        self.transport = transport
2278
2406
 
2279
2407
 
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
2408
class UnknownSSH(BzrError):
2290
2409
 
2291
2410
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2311
2430
        self.revision_id = revision_id
2312
2431
        self.ghost_revision_id = ghost_revision_id
2313
2432
 
2314
 
        
 
2433
 
2315
2434
class GhostRevisionUnusableHere(BzrError):
2316
2435
 
2317
2436
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2409
2528
 
2410
2529
 
2411
2530
class UnsupportedInventoryKind(BzrError):
2412
 
    
 
2531
 
2413
2532
    _fmt = """Unsupported entry kind %(kind)s"""
2414
2533
 
2415
2534
    def __init__(self, kind):
2427
2546
 
2428
2547
 
2429
2548
class SubsumeTargetNeedsUpgrade(BzrError):
2430
 
    
 
2549
 
2431
2550
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2432
2551
 
2433
2552
    def __init__(self, other_tree):
2461
2580
    def __init__(self, branch):
2462
2581
        self.branch = branch
2463
2582
 
2464
 
        
 
2583
 
2465
2584
class TagAlreadyExists(BzrError):
2466
2585
 
2467
2586
    _fmt = "Tag %(tag_name)s already exists."
2472
2591
 
2473
2592
class MalformedBugIdentifier(BzrError):
2474
2593
 
2475
 
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2594
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
2595
            'See "bzr help bugs" for more information on this feature.')
2476
2596
 
2477
2597
    def __init__(self, bug_id, reason):
2478
2598
        self.bug_id = bug_id
2499
2619
        self.branch = branch
2500
2620
 
2501
2621
 
 
2622
class InvalidLineInBugsProperty(BzrError):
 
2623
 
 
2624
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
2625
 
 
2626
    def __init__(self, line):
 
2627
        self.line = line
 
2628
 
 
2629
 
 
2630
class InvalidBugStatus(BzrError):
 
2631
 
 
2632
    _fmt = ("Invalid bug status: '%(status)s'")
 
2633
 
 
2634
    def __init__(self, status):
 
2635
        self.status = status
 
2636
 
 
2637
 
2502
2638
class UnexpectedSmartServerResponse(BzrError):
2503
2639
 
2504
2640
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2508
2644
 
2509
2645
 
2510
2646
class ErrorFromSmartServer(BzrError):
 
2647
    """An error was received from a smart server.
 
2648
 
 
2649
    :seealso: UnknownErrorFromSmartServer
 
2650
    """
2511
2651
 
2512
2652
    _fmt = "Error received from smart server: %(error_tuple)r"
2513
2653
 
2522
2662
        self.error_args = error_tuple[1:]
2523
2663
 
2524
2664
 
 
2665
class UnknownErrorFromSmartServer(BzrError):
 
2666
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
 
2667
    error.
 
2668
 
 
2669
    This is distinct from ErrorFromSmartServer so that it is possible to
 
2670
    distinguish between the following two cases:
 
2671
 
 
2672
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2673
      and so should provoke a traceback to the user.
 
2674
    - ErrorFromSmartServer was caught but its error_tuple could not be
 
2675
      translated.  This is probably because the server sent us garbage, and
 
2676
      should not provoke a traceback.
 
2677
    """
 
2678
 
 
2679
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
 
2680
 
 
2681
    internal_error = False
 
2682
 
 
2683
    def __init__(self, error_from_smart_server):
 
2684
        """Constructor.
 
2685
 
 
2686
        :param error_from_smart_server: An ErrorFromSmartServer instance.
 
2687
        """
 
2688
        self.error_from_smart_server = error_from_smart_server
 
2689
        self.error_tuple = error_from_smart_server.error_tuple
 
2690
 
 
2691
 
2525
2692
class ContainerError(BzrError):
2526
2693
    """Base class of container errors."""
2527
2694
 
2529
2696
class UnknownContainerFormatError(ContainerError):
2530
2697
 
2531
2698
    _fmt = "Unrecognised container format: %(container_format)r"
2532
 
    
 
2699
 
2533
2700
    def __init__(self, container_format):
2534
2701
        self.container_format = container_format
2535
2702
 
2568
2735
    _fmt = "Container has multiple records with the same name: %(name)s"
2569
2736
 
2570
2737
    def __init__(self, name):
2571
 
        self.name = name
 
2738
        self.name = name.decode("utf-8")
2572
2739
 
2573
2740
 
2574
2741
class NoDestinationAddress(InternalBzrError):
2599
2766
 
2600
2767
class NoMailAddressSpecified(BzrError):
2601
2768
 
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)
 
2769
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
2611
2770
 
2612
2771
 
2613
2772
class MailClientNotFound(BzrError):
2638
2797
 
2639
2798
    def __init__(self, bzrdir):
2640
2799
        import bzrlib.urlutils as urlutils
2641
 
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2800
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
2642
2801
                                                    'ascii')
2643
2802
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2644
2803
 
2685
2844
    _fmt = "'%(display_url)s' is already standalone."
2686
2845
 
2687
2846
 
 
2847
class AlreadyWithTrees(BzrDirError):
 
2848
 
 
2849
    _fmt = ("Shared repository '%(display_url)s' already creates "
 
2850
            "working trees.")
 
2851
 
 
2852
 
 
2853
class AlreadyWithNoTrees(BzrDirError):
 
2854
 
 
2855
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
 
2856
            "working trees.")
 
2857
 
 
2858
 
2688
2859
class ReconfigurationNotSupported(BzrDirError):
2689
2860
 
2690
2861
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2697
2868
 
2698
2869
class UncommittedChanges(BzrError):
2699
2870
 
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)
 
2871
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
 
2872
            ' (See bzr status).%(more)s')
 
2873
 
 
2874
    def __init__(self, tree, more=None):
 
2875
        if more is None:
 
2876
            more = ''
 
2877
        else:
 
2878
            more = ' ' + more
 
2879
        import bzrlib.urlutils as urlutils
 
2880
        user_url = getattr(tree, "user_url", None)
 
2881
        if user_url is None:
 
2882
            display_url = str(tree)
 
2883
        else:
 
2884
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
 
2885
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
 
2886
 
 
2887
 
 
2888
class StoringUncommittedNotSupported(BzrError):
 
2889
 
 
2890
    _fmt = ('Branch "%(display_url)s" does not support storing uncommitted'
 
2891
            ' changes.')
 
2892
 
 
2893
    def __init__(self, branch):
 
2894
        import bzrlib.urlutils as urlutils
 
2895
        user_url = getattr(branch, "user_url", None)
 
2896
        if user_url is None:
 
2897
            display_url = str(branch)
 
2898
        else:
 
2899
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
 
2900
        BzrError.__init__(self, branch=branch, display_url=display_url)
 
2901
 
 
2902
 
 
2903
class ShelvedChanges(UncommittedChanges):
 
2904
 
 
2905
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
 
2906
            ' (See bzr shelve --list).%(more)s')
2707
2907
 
2708
2908
 
2709
2909
class MissingTemplateVariable(BzrError):
2744
2944
 
2745
2945
 
2746
2946
class CommandAvailableInPlugin(StandardError):
2747
 
    
 
2947
 
2748
2948
    internal_error = False
2749
2949
 
2750
2950
    def __init__(self, cmd_name, plugin_metadata, provider):
2751
 
        
 
2951
 
2752
2952
        self.plugin_metadata = plugin_metadata
2753
2953
        self.cmd_name = cmd_name
2754
2954
        self.provider = provider
2755
2955
 
2756
2956
    def __str__(self):
2757
2957
 
2758
 
        _fmt = ('"%s" is not a standard bzr command. \n' 
 
2958
        _fmt = ('"%s" is not a standard bzr command. \n'
2759
2959
                'However, the following official plugin provides this command: %s\n'
2760
2960
                'You can install it by going to: %s'
2761
 
                % (self.cmd_name, self.plugin_metadata['name'], 
 
2961
                % (self.cmd_name, self.plugin_metadata['name'],
2762
2962
                    self.plugin_metadata['url']))
2763
2963
 
2764
2964
        return _fmt
2765
2965
 
2766
2966
 
2767
2967
class NoPluginAvailable(BzrError):
2768
 
    pass    
2769
 
 
2770
 
 
2771
 
class NotATerminal(BzrError):
2772
 
 
2773
 
    _fmt = 'Unable to ask for a password without real terminal.'
 
2968
    pass
2774
2969
 
2775
2970
 
2776
2971
class UnableEncodePath(BzrError):
2779
2974
            'user encoding %(user_encoding)s')
2780
2975
 
2781
2976
    def __init__(self, path, kind):
 
2977
        from bzrlib.osutils import get_user_encoding
2782
2978
        self.path = path
2783
2979
        self.kind = kind
2784
 
        self.user_encoding = osutils.get_user_encoding()
 
2980
        self.user_encoding = get_user_encoding()
 
2981
 
 
2982
 
 
2983
class NoSuchConfig(BzrError):
 
2984
 
 
2985
    _fmt = ('The "%(config_id)s" configuration does not exist.')
 
2986
 
 
2987
    def __init__(self, config_id):
 
2988
        BzrError.__init__(self, config_id=config_id)
 
2989
 
 
2990
 
 
2991
class NoSuchConfigOption(BzrError):
 
2992
 
 
2993
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
 
2994
 
 
2995
    def __init__(self, option_name):
 
2996
        BzrError.__init__(self, option_name=option_name)
2785
2997
 
2786
2998
 
2787
2999
class NoSuchAlias(BzrError):
2819
3031
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2820
3032
 
2821
3033
    def __init__(self, host, port, orig_error):
 
3034
        # nb: in python2.4 socket.error doesn't have a useful repr
2822
3035
        BzrError.__init__(self, host=host, port=port,
2823
 
            orig_error=orig_error[1])
 
3036
            orig_error=repr(orig_error.args))
2824
3037
 
2825
3038
 
2826
3039
class UnknownRules(BzrError):
2831
3044
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2832
3045
 
2833
3046
 
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
3047
class TipChangeRejected(BzrError):
2854
3048
    """A pre_change_branch_tip hook function may raise this to cleanly and
2855
3049
    explicitly abort a change to a branch tip.
2856
3050
    """
2857
 
    
 
3051
 
2858
3052
    _fmt = u"Tip change rejected: %(msg)s"
2859
3053
 
2860
3054
    def __init__(self, msg):
2861
3055
        self.msg = msg
2862
3056
 
 
3057
 
 
3058
class ShelfCorrupt(BzrError):
 
3059
 
 
3060
    _fmt = "Shelf corrupt."
 
3061
 
 
3062
 
 
3063
class DecompressCorruption(BzrError):
 
3064
 
 
3065
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
 
3066
 
 
3067
    def __init__(self, orig_error=None):
 
3068
        if orig_error is not None:
 
3069
            self.orig_error = ", %s" % (orig_error,)
 
3070
        else:
 
3071
            self.orig_error = ""
 
3072
        BzrError.__init__(self)
 
3073
 
 
3074
 
 
3075
class NoSuchShelfId(BzrError):
 
3076
 
 
3077
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
 
3078
 
 
3079
    def __init__(self, shelf_id):
 
3080
        BzrError.__init__(self, shelf_id=shelf_id)
 
3081
 
 
3082
 
 
3083
class InvalidShelfId(BzrError):
 
3084
 
 
3085
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
 
3086
 
 
3087
    def __init__(self, invalid_id):
 
3088
        BzrError.__init__(self, invalid_id=invalid_id)
 
3089
 
 
3090
 
 
3091
class JailBreak(BzrError):
 
3092
 
 
3093
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
 
3094
 
 
3095
    def __init__(self, url):
 
3096
        BzrError.__init__(self, url=url)
 
3097
 
 
3098
 
 
3099
class UserAbort(BzrError):
 
3100
 
 
3101
    _fmt = 'The user aborted the operation.'
 
3102
 
 
3103
 
 
3104
class MustHaveWorkingTree(BzrError):
 
3105
 
 
3106
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
 
3107
 
 
3108
    def __init__(self, format, url):
 
3109
        BzrError.__init__(self, format=format, url=url)
 
3110
 
 
3111
 
 
3112
class NoSuchView(BzrError):
 
3113
    """A view does not exist.
 
3114
    """
 
3115
 
 
3116
    _fmt = u"No such view: %(view_name)s."
 
3117
 
 
3118
    def __init__(self, view_name):
 
3119
        self.view_name = view_name
 
3120
 
 
3121
 
 
3122
class ViewsNotSupported(BzrError):
 
3123
    """Views are not supported by a tree format.
 
3124
    """
 
3125
 
 
3126
    _fmt = ("Views are not supported by %(tree)s;"
 
3127
            " use 'bzr upgrade' to change your tree to a later format.")
 
3128
 
 
3129
    def __init__(self, tree):
 
3130
        self.tree = tree
 
3131
 
 
3132
 
 
3133
class FileOutsideView(BzrError):
 
3134
 
 
3135
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
3136
            '%(view_str)s')
 
3137
 
 
3138
    def __init__(self, file_name, view_files):
 
3139
        self.file_name = file_name
 
3140
        self.view_str = ", ".join(view_files)
 
3141
 
 
3142
 
 
3143
class UnresumableWriteGroup(BzrError):
 
3144
 
 
3145
    _fmt = ("Repository %(repository)s cannot resume write group "
 
3146
            "%(write_groups)r: %(reason)s")
 
3147
 
 
3148
    internal_error = True
 
3149
 
 
3150
    def __init__(self, repository, write_groups, reason):
 
3151
        self.repository = repository
 
3152
        self.write_groups = write_groups
 
3153
        self.reason = reason
 
3154
 
 
3155
 
 
3156
class UnsuspendableWriteGroup(BzrError):
 
3157
 
 
3158
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
 
3159
 
 
3160
    internal_error = True
 
3161
 
 
3162
    def __init__(self, repository):
 
3163
        self.repository = repository
 
3164
 
 
3165
 
 
3166
class LossyPushToSameVCS(BzrError):
 
3167
 
 
3168
    _fmt = ("Lossy push not possible between %(source_branch)r and "
 
3169
            "%(target_branch)r that are in the same VCS.")
 
3170
 
 
3171
    internal_error = True
 
3172
 
 
3173
    def __init__(self, source_branch, target_branch):
 
3174
        self.source_branch = source_branch
 
3175
        self.target_branch = target_branch
 
3176
 
 
3177
 
 
3178
class NoRoundtrippingSupport(BzrError):
 
3179
 
 
3180
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
 
3181
            "%(target_branch)r.")
 
3182
 
 
3183
    internal_error = True
 
3184
 
 
3185
    def __init__(self, source_branch, target_branch):
 
3186
        self.source_branch = source_branch
 
3187
        self.target_branch = target_branch
 
3188
 
 
3189
 
 
3190
class FileTimestampUnavailable(BzrError):
 
3191
 
 
3192
    _fmt = "The filestamp for %(path)s is not available."
 
3193
 
 
3194
    internal_error = True
 
3195
 
 
3196
    def __init__(self, path):
 
3197
        self.path = path
 
3198
 
 
3199
 
 
3200
class NoColocatedBranchSupport(BzrError):
 
3201
 
 
3202
    _fmt = ("%(bzrdir)r does not support co-located branches.")
 
3203
 
 
3204
    def __init__(self, bzrdir):
 
3205
        self.bzrdir = bzrdir
 
3206
 
 
3207
 
 
3208
class NoWhoami(BzrError):
 
3209
 
 
3210
    _fmt = ('Unable to determine your name.\n'
 
3211
        "Please, set your name with the 'whoami' command.\n"
 
3212
        'E.g. bzr whoami "Your Name <name@example.com>"')
 
3213
 
 
3214
 
 
3215
class InvalidPattern(BzrError):
 
3216
 
 
3217
    _fmt = ('Invalid pattern(s) found. %(msg)s')
 
3218
 
 
3219
    def __init__(self, msg):
 
3220
        self.msg = msg
 
3221
 
 
3222
 
 
3223
class RecursiveBind(BzrError):
 
3224
 
 
3225
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
 
3226
        'Please use `bzr unbind` to fix.')
 
3227
 
 
3228
    def __init__(self, branch_url):
 
3229
        self.branch_url = branch_url
 
3230
 
 
3231
 
 
3232
# FIXME: I would prefer to define the config related exception classes in
 
3233
# config.py but the lazy import mechanism proscribes this -- vila 20101222
 
3234
class OptionExpansionLoop(BzrError):
 
3235
 
 
3236
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
 
3237
 
 
3238
    def __init__(self, string, refs):
 
3239
        self.string = string
 
3240
        self.refs = '->'.join(refs)
 
3241
 
 
3242
 
 
3243
class ExpandingUnknownOption(BzrError):
 
3244
 
 
3245
    _fmt = 'Option "%(name)s" is not defined while expanding "%(string)s".'
 
3246
 
 
3247
    def __init__(self, name, string):
 
3248
        self.name = name
 
3249
        self.string = string
 
3250
 
 
3251
 
 
3252
class IllegalOptionName(BzrError):
 
3253
 
 
3254
    _fmt = 'Option "%(name)s" is not allowed.'
 
3255
 
 
3256
    def __init__(self, name):
 
3257
        self.name = name
 
3258
 
 
3259
 
 
3260
class NoCompatibleInter(BzrError):
 
3261
 
 
3262
    _fmt = ('No compatible object available for operations from %(source)r '
 
3263
            'to %(target)r.')
 
3264
 
 
3265
    def __init__(self, source, target):
 
3266
        self.source = source
 
3267
        self.target = target
 
3268
 
 
3269
 
 
3270
class HpssVfsRequestNotAllowed(BzrError):
 
3271
 
 
3272
    _fmt = ("VFS requests over the smart server are not allowed. Encountered: "
 
3273
            "%(method)s, %(arguments)s.")
 
3274
 
 
3275
    def __init__(self, method, arguments):
 
3276
        self.method = method
 
3277
        self.arguments = arguments
 
3278
 
 
3279
 
 
3280
class UnsupportedKindChange(BzrError):
 
3281
 
 
3282
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
 
3283
            "%(path)s not supported by format %(format)r")
 
3284
 
 
3285
    def __init__(self, path, from_kind, to_kind, format):
 
3286
        self.path = path
 
3287
        self.from_kind = from_kind
 
3288
        self.to_kind = to_kind
 
3289
        self.format = format
 
3290
 
 
3291
 
 
3292
class MissingFeature(BzrError):
 
3293
 
 
3294
    _fmt = ("Missing feature %(feature)s not provided by this "
 
3295
            "version of Bazaar or any plugin.")
 
3296
 
 
3297
    def __init__(self, feature):
 
3298
        self.feature = feature
 
3299
 
 
3300
 
 
3301
class PatchSyntax(BzrError):
 
3302
    """Base class for patch syntax errors."""
 
3303
 
 
3304
 
 
3305
class BinaryFiles(BzrError):
 
3306
 
 
3307
    _fmt = 'Binary files section encountered.'
 
3308
 
 
3309
    def __init__(self, orig_name, mod_name):
 
3310
        self.orig_name = orig_name
 
3311
        self.mod_name = mod_name
 
3312
 
 
3313
 
 
3314
class MalformedPatchHeader(PatchSyntax):
 
3315
 
 
3316
    _fmt = "Malformed patch header.  %(desc)s\n%(line)r"
 
3317
 
 
3318
    def __init__(self, desc, line):
 
3319
        self.desc = desc
 
3320
        self.line = line
 
3321
 
 
3322
 
 
3323
class MalformedHunkHeader(PatchSyntax):
 
3324
 
 
3325
    _fmt = "Malformed hunk header.  %(desc)s\n%(line)r"
 
3326
 
 
3327
    def __init__(self, desc, line):
 
3328
        self.desc = desc
 
3329
        self.line = line
 
3330
 
 
3331
 
 
3332
class MalformedLine(PatchSyntax):
 
3333
 
 
3334
    _fmt = "Malformed line.  %(desc)s\n%(line)r"
 
3335
 
 
3336
    def __init__(self, desc, line):
 
3337
        self.desc = desc
 
3338
        self.line = line
 
3339
 
 
3340
 
 
3341
class PatchConflict(BzrError):
 
3342
 
 
3343
    _fmt = ('Text contents mismatch at line %(line_no)d.  Original has '
 
3344
            '"%(orig_line)s", but patch says it should be "%(patch_line)s"')
 
3345
 
 
3346
    def __init__(self, line_no, orig_line, patch_line):
 
3347
        self.line_no = line_no
 
3348
        self.orig_line = orig_line.rstrip('\n')
 
3349
        self.patch_line = patch_line.rstrip('\n')
 
3350
 
 
3351
 
 
3352
class FeatureAlreadyRegistered(BzrError):
 
3353
 
 
3354
    _fmt = 'The feature %(feature)s has already been registered.'
 
3355
 
 
3356
    def __init__(self, feature):
 
3357
        self.feature = feature
 
3358
 
 
3359
 
 
3360
class ChangesAlreadyStored(BzrCommandError):
 
3361
 
 
3362
    _fmt = ('Cannot store uncommitted changes because this branch already'
 
3363
            ' stores uncommitted changes.')