~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Martin Pool
  • Date: 2009-01-13 03:06:36 UTC
  • mfrom: (3932.2.3 1.11)
  • mto: This revision was merged to the branch mainline in revision 3937.
  • Revision ID: mbp@sourcefrog.net-20090113030636-dqx4t8yaaqgdvam5
MergeĀ 1.11rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
20
 
from __future__ import absolute_import
 
20
from bzrlib import (
 
21
    osutils,
 
22
    symbol_versioning,
 
23
    )
 
24
from bzrlib.patches import (
 
25
    MalformedHunkHeader,
 
26
    MalformedLine,
 
27
    MalformedPatchHeader,
 
28
    PatchConflict,
 
29
    PatchSyntax,
 
30
    )
 
31
 
21
32
 
22
33
# TODO: is there any value in providing the .args field used by standard
23
 
# python exceptions?   A list of values with no names seems less useful
 
34
# python exceptions?   A list of values with no names seems less useful 
24
35
# to me.
25
36
 
26
 
# TODO: Perhaps convert the exception to a string at the moment it's
 
37
# TODO: Perhaps convert the exception to a string at the moment it's 
27
38
# constructed to make sure it will succeed.  But that says nothing about
28
39
# exceptions that are never raised.
29
40
 
43
54
    Base class for errors raised by bzrlib.
44
55
 
45
56
    :cvar internal_error: if True this was probably caused by a bzr bug and
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.)
 
57
    should be displayed with a traceback; if False (or absent) this was
 
58
    probably a user or environment error and they don't need the gory details.
 
59
    (That can be overridden by -Derror on the command line.)
49
60
 
50
61
    :cvar _fmt: Format string to display the error; this is expanded
51
 
        by the instance's dict.
 
62
    by the instance's dict.
52
63
    """
53
 
 
 
64
    
54
65
    internal_error = False
55
66
 
56
67
    def __init__(self, msg=None, **kwds):
61
72
        arguments can be given.  The first is for generic "user" errors which
62
73
        are not intended to be caught and so do not need a specific subclass.
63
74
        The second case is for use with subclasses that provide a _fmt format
64
 
        string to print the arguments.
 
75
        string to print the arguments.  
65
76
 
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
 
77
        Keyword arguments are taken as parameters to the error, which can 
 
78
        be inserted into the format string template.  It's recommended 
 
79
        that subclasses override the __init__ method to require specific 
69
80
        parameters.
70
81
 
71
82
        :param msg: If given, this is the literal complete text for the error,
95
106
                # __str__() should always return a 'str' object
96
107
                # never a 'unicode' object.
97
108
                return s
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)
 
109
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
 
110
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
111
                % (self.__class__.__name__,
 
112
                   self.__dict__,
 
113
                   getattr(self, '_fmt', None),
 
114
                   e)
107
115
 
108
116
    def __unicode__(self):
109
117
        u = self._format()
132
140
        """Return format string for this exception or None"""
133
141
        fmt = getattr(self, '_fmt', None)
134
142
        if fmt is not None:
135
 
            from bzrlib.i18n import gettext
136
 
            return gettext(unicode(fmt)) # _fmt strings should be ascii
 
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
               )
137
155
 
138
156
    def __eq__(self, other):
139
 
        if self.__class__ is not other.__class__:
 
157
        if self.__class__ != other.__class__:
140
158
            return NotImplemented
141
159
        return self.__dict__ == other.__dict__
142
160
 
152
170
    internal_error = True
153
171
 
154
172
 
 
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
 
155
206
class AlreadyBuilding(BzrError):
156
207
 
157
208
    _fmt = "The tree builder is already building a tree."
214
265
 
215
266
 
216
267
class InvalidEntryName(InternalBzrError):
217
 
 
 
268
    
218
269
    _fmt = "Invalid entry name: %(name)s"
219
270
 
220
271
    def __init__(self, name):
223
274
 
224
275
 
225
276
class InvalidRevisionNumber(BzrError):
226
 
 
 
277
    
227
278
    _fmt = "Invalid revision number %(revno)s"
228
279
 
229
280
    def __init__(self, revno):
253
304
class RootMissing(InternalBzrError):
254
305
 
255
306
    _fmt = ("The root entry of a tree must be the first entry supplied to "
256
 
        "the commit builder.")
 
307
        "record_entry_contents.")
257
308
 
258
309
 
259
310
class NoPublicBranch(BzrError):
278
329
class NoSuchId(BzrError):
279
330
 
280
331
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
281
 
 
 
332
    
282
333
    def __init__(self, tree, file_id):
283
334
        BzrError.__init__(self)
284
335
        self.file_id = file_id
311
362
class NoWorkingTree(BzrError):
312
363
 
313
364
    _fmt = 'No WorkingTree exists for "%(base)s".'
314
 
 
 
365
    
315
366
    def __init__(self, base):
316
367
        BzrError.__init__(self)
317
368
        self.base = base
426
477
    def __init__(self, name, value):
427
478
        BzrError.__init__(self, name=name, value=value)
428
479
 
429
 
 
 
480
    
430
481
class StrictCommitFailed(BzrError):
431
482
 
432
483
    _fmt = "Commit refused because there are unknown files in the tree"
435
486
# XXX: Should be unified with TransportError; they seem to represent the
436
487
# same thing
437
488
# RBC 20060929: I think that unifiying with TransportError would be a mistake
438
 
# - this is finer than a TransportError - and more useful as such. It
 
489
# - this is finer than a TransportError - and more useful as such. It 
439
490
# differentiates between 'transport has failed' and 'operation on a transport
440
491
# has failed.'
441
492
class PathError(BzrError):
442
 
 
 
493
    
443
494
    _fmt = "Generic path error: %(path)r%(extra)s)"
444
495
 
445
496
    def __init__(self, path, extra=None):
499
550
 
500
551
 
501
552
class ReadingCompleted(InternalBzrError):
502
 
 
 
553
    
503
554
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
504
555
            "called upon it - the request has been completed and no more "
505
556
            "data may be read.")
570
621
 
571
622
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
572
623
 
573
 
    def __init__(self, url, extra=""):
 
624
    def __init__(self, url, extra):
574
625
        PathError.__init__(self, url, extra=extra)
575
626
 
576
627
 
585
636
        self.url = url
586
637
 
587
638
 
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
 
 
598
639
class UnstackableRepositoryFormat(BzrError):
599
640
 
600
641
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
607
648
 
608
649
 
609
650
class ReadError(PathError):
610
 
 
 
651
    
611
652
    _fmt = """Error reading from %(path)r."""
612
653
 
613
654
 
629
670
 
630
671
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
631
672
 
632
 
    internal_error = False
 
673
    internal_error = True
633
674
 
634
675
    def __init__(self, path, base, extra=None):
635
676
        BzrError.__init__(self)
648
689
 
649
690
# TODO: This is given a URL; we try to unescape it but doing that from inside
650
691
# the exception object is a bit undesirable.
651
 
# TODO: Probably this behavior of should be a common superclass
 
692
# TODO: Probably this behavior of should be a common superclass 
652
693
class NotBranchError(PathError):
653
694
 
654
 
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
 
695
    _fmt = 'Not a branch: "%(path)s".'
655
696
 
656
 
    def __init__(self, path, detail=None, bzrdir=None):
 
697
    def __init__(self, path):
657
698
       import bzrlib.urlutils as urlutils
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)
 
699
       self.path = urlutils.unescape_for_display(path, 'ascii')
692
700
 
693
701
 
694
702
class NoSubmitBranch(PathError):
700
708
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
701
709
 
702
710
 
703
 
class AlreadyControlDirError(PathError):
704
 
 
705
 
    _fmt = 'A control directory already exists: "%(path)s".'
706
 
 
707
 
 
708
711
class AlreadyBranchError(PathError):
709
712
 
710
713
    _fmt = 'Already a branch: "%(path)s".'
711
714
 
712
715
 
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
 
 
727
716
class BranchExistsWithoutWorkingTree(PathError):
728
717
 
729
718
    _fmt = 'Directory contains a branch, but no working tree \
758
747
        self.path = bzrdir.transport.clone('..').base
759
748
 
760
749
 
 
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
 
 
797
785
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
 
    """
804
786
 
805
787
    _fmt = "%(target)s\n" \
806
788
            "is not compatible with\n" \
814
796
 
815
797
 
816
798
class IncompatibleRevision(BzrError):
817
 
 
 
799
    
818
800
    _fmt = "Revision is not compatible with %(repo_format)s"
819
801
 
820
802
    def __init__(self, repo_format):
831
813
        """Construct a new AlreadyVersionedError.
832
814
 
833
815
        :param path: This is the path which is versioned,
834
 
            which should be in a user friendly form.
 
816
        which should be in a user friendly form.
835
817
        :param context_info: If given, this is information about the context,
836
 
            which could explain why this is expected to not be versioned.
 
818
        which could explain why this is expected to not be versioned.
837
819
        """
838
820
        BzrError.__init__(self)
839
821
        self.path = path
852
834
        """Construct a new NotVersionedError.
853
835
 
854
836
        :param path: This is the path which is not versioned,
855
 
            which should be in a user friendly form.
 
837
        which should be in a user friendly form.
856
838
        :param context_info: If given, this is information about the context,
857
 
            which could explain why this is expected to be versioned.
 
839
        which could explain why this is expected to be versioned.
858
840
        """
859
841
        BzrError.__init__(self)
860
842
        self.path = path
928
910
    # original exception is available as e.original_error
929
911
    #
930
912
    # New code should prefer to raise specific subclasses
931
 
    def __init__(self, msg):
932
 
        self.msg = msg
 
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
933
918
 
934
919
 
935
920
class LockActive(LockError):
1018
1003
 
1019
1004
class LockContention(LockError):
1020
1005
 
1021
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
 
1006
    _fmt = 'Could not acquire lock "%(lock)s"'
 
1007
    # TODO: show full url for lock, combining the transport and relative
 
1008
    # bits?
1022
1009
 
1023
1010
    internal_error = False
1024
1011
 
1025
 
    def __init__(self, lock, msg=''):
 
1012
    def __init__(self, lock):
1026
1013
        self.lock = lock
1027
 
        self.msg = msg
1028
1014
 
1029
1015
 
1030
1016
class LockBroken(LockError):
1051
1037
        self.target = target
1052
1038
 
1053
1039
 
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
 
 
1066
1040
class LockNotHeld(LockError):
1067
1041
 
1068
1042
    _fmt = "Lock not held: %(lock)s"
1107
1081
        BzrError.__init__(self, files=files, files_str=files_str)
1108
1082
 
1109
1083
 
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
 
 
1119
1084
class BadCommitMessageEncoding(BzrError):
1120
1085
 
1121
1086
    _fmt = 'The specified commit message contains characters unsupported by '\
1165
1130
 
1166
1131
class NoSuchRevisionInTree(NoSuchRevision):
1167
1132
    """When using Tree.revision_tree, and the revision is not accessible."""
1168
 
 
 
1133
    
1169
1134
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1170
1135
 
1171
1136
    def __init__(self, tree, revision_id):
1176
1141
 
1177
1142
class InvalidRevisionSpec(BzrError):
1178
1143
 
1179
 
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
1180
 
            " %(branch_url)s%(extra)s")
 
1144
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
 
1145
            " %(branch)s%(extra)s")
1181
1146
 
1182
1147
    def __init__(self, spec, branch, extra=None):
1183
1148
        BzrError.__init__(self, branch=branch, spec=spec)
1184
 
        self.branch_url = getattr(branch, 'user_url', str(branch))
1185
1149
        if extra:
1186
1150
            self.extra = '\n' + str(extra)
1187
1151
        else:
1188
1152
            self.extra = ''
1189
1153
 
1190
1154
 
 
1155
class HistoryMissing(BzrError):
 
1156
 
 
1157
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
 
1158
 
 
1159
 
1191
1160
class AppendRevisionsOnlyViolation(BzrError):
1192
1161
 
1193
1162
    _fmt = ('Operation denied because it would change the main history,'
1203
1172
class DivergedBranches(BzrError):
1204
1173
 
1205
1174
    _fmt = ("These branches have diverged."
1206
 
            " Use the missing command to see how.\n"
1207
 
            "Use the merge command to reconcile them.")
 
1175
            " Use the merge command to reconcile them.")
1208
1176
 
1209
1177
    def __init__(self, branch1, branch2):
1210
1178
        self.branch1 = branch1
1232
1200
 
1233
1201
 
1234
1202
class NoCommonAncestor(BzrError):
1235
 
 
 
1203
    
1236
1204
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1237
1205
 
1238
1206
    def __init__(self, revision_a, revision_b):
1258
1226
            not_ancestor_id=not_ancestor_id)
1259
1227
 
1260
1228
 
 
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
 
1261
1249
class NoCommits(BranchError):
1262
1250
 
1263
1251
    _fmt = "Branch %(branch)s has no commits."
1279
1267
class BoundBranchOutOfDate(BzrError):
1280
1268
 
1281
1269
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1282
 
            " %(master)s.%(extra_help)s")
 
1270
            " %(master)s.")
1283
1271
 
1284
1272
    def __init__(self, branch, master):
1285
1273
        BzrError.__init__(self)
1286
1274
        self.branch = branch
1287
1275
        self.master = master
1288
 
        self.extra_help = ''
1289
 
 
1290
 
 
 
1276
 
 
1277
        
1291
1278
class CommitToDoubleBoundBranch(BzrError):
1292
1279
 
1293
1280
    _fmt = ("Cannot commit to branch %(branch)s."
1362
1349
 
1363
1350
class WeaveParentMismatch(WeaveError):
1364
1351
 
1365
 
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
1366
 
 
 
1352
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
1353
    
1367
1354
 
1368
1355
class WeaveInvalidChecksum(WeaveError):
1369
1356
 
1370
 
    _fmt = "Text did not match its checksum: %(msg)s"
 
1357
    _fmt = "Text did not match it's checksum: %(message)s"
1371
1358
 
1372
1359
 
1373
1360
class WeaveTextDiffers(WeaveError):
1395
1382
 
1396
1383
 
1397
1384
class VersionedFileError(BzrError):
1398
 
 
 
1385
    
1399
1386
    _fmt = "Versioned file error"
1400
1387
 
1401
1388
 
1402
1389
class RevisionNotPresent(VersionedFileError):
1403
 
 
 
1390
    
1404
1391
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1405
1392
 
1406
1393
    def __init__(self, revision_id, file_id):
1410
1397
 
1411
1398
 
1412
1399
class RevisionAlreadyPresent(VersionedFileError):
1413
 
 
 
1400
    
1414
1401
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1415
1402
 
1416
1403
    def __init__(self, revision_id, file_id):
1421
1408
 
1422
1409
class VersionedFileInvalidChecksum(VersionedFileError):
1423
1410
 
1424
 
    _fmt = "Text did not match its checksum: %(msg)s"
 
1411
    _fmt = "Text did not match its checksum: %(message)s"
1425
1412
 
1426
1413
 
1427
1414
class KnitError(InternalBzrError):
1428
 
 
 
1415
    
1429
1416
    _fmt = "Knit error"
1430
1417
 
1431
1418
 
1463
1450
    def __init__(self, stream_format, target_format):
1464
1451
        self.stream_format = stream_format
1465
1452
        self.target_format = target_format
1466
 
 
 
1453
        
1467
1454
 
1468
1455
class KnitDataStreamUnknown(KnitError):
1469
1456
    # Indicates a data stream we don't know how to handle.
1472
1459
 
1473
1460
    def __init__(self, stream_format):
1474
1461
        self.stream_format = stream_format
1475
 
 
 
1462
        
1476
1463
 
1477
1464
class KnitHeaderError(KnitError):
1478
1465
 
1488
1475
 
1489
1476
    Currently only 'fulltext' and 'line-delta' are supported.
1490
1477
    """
1491
 
 
 
1478
    
1492
1479
    _fmt = ("Knit index %(filename)s does not have a known method"
1493
1480
            " in options: %(options)r")
1494
1481
 
1523
1510
            problem we can raise the original error (value from sys.exc_info())
1524
1511
        """
1525
1512
        BzrError.__init__(self)
1526
 
        self.context = context
1527
1513
        self.reload_occurred = reload_occurred
1528
1514
        self.exc_info = exc_info
1529
1515
        self.orig_error = exc_info[1]
1546
1532
 
1547
1533
 
1548
1534
class NoSuchExportFormat(BzrError):
1549
 
 
 
1535
    
1550
1536
    _fmt = "Export format %(format)r not supported"
1551
1537
 
1552
1538
    def __init__(self, format):
1555
1541
 
1556
1542
 
1557
1543
class TransportError(BzrError):
1558
 
 
 
1544
    
1559
1545
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1560
1546
 
1561
1547
    def __init__(self, msg=None, orig_error=None):
1611
1597
 
1612
1598
    def __init__(self, exc_info):
1613
1599
        import traceback
1614
 
        # GZ 2010-08-10: Cycle with exc_tb/exc_info affects at least one test
1615
1600
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1616
1601
        self.exc_info = exc_info
1617
1602
        traceback_strings = traceback.format_exception(
1649
1634
            self.port = ':%s' % port
1650
1635
 
1651
1636
 
1652
 
# XXX: This is also used for unexpected end of file, which is different at the
1653
 
# TCP level from "connection reset".
1654
1637
class ConnectionReset(TransportError):
1655
1638
 
1656
1639
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1657
1640
 
1658
1641
 
1659
 
class ConnectionTimeout(ConnectionError):
1660
 
 
1661
 
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
1662
 
 
1663
 
 
1664
1642
class InvalidRange(TransportError):
1665
1643
 
1666
1644
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1673
1651
 
1674
1652
class InvalidHttpResponse(TransportError):
1675
1653
 
1676
 
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
 
1654
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1677
1655
 
1678
1656
    def __init__(self, path, msg, orig_error=None):
1679
1657
        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,)
1686
1658
        TransportError.__init__(self, msg, orig_error=orig_error)
1687
1659
 
1688
1660
 
1689
 
class CertificateError(TransportError):
1690
 
 
1691
 
    _fmt = "Certificate error: %(error)s"
1692
 
 
1693
 
    def __init__(self, error):
1694
 
        self.error = error
1695
 
 
1696
 
 
1697
1661
class InvalidHttpRange(InvalidHttpResponse):
1698
1662
 
1699
1663
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1703
1667
        InvalidHttpResponse.__init__(self, path, msg)
1704
1668
 
1705
1669
 
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
 
 
1719
1670
class InvalidHttpContentType(InvalidHttpResponse):
1720
1671
 
1721
1672
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1749
1700
    _fmt = "Working tree has conflicts."
1750
1701
 
1751
1702
 
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
 
 
1761
1703
class ParseConfigError(BzrError):
1762
1704
 
1763
 
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
1764
 
 
1765
1705
    def __init__(self, errors, filename):
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)
 
1706
        if filename is None:
 
1707
            filename = ""
 
1708
        message = "Error(s) parsing config file %s:\n%s" % \
 
1709
            (filename, ('\n'.join(e.msg for e in errors)))
 
1710
        BzrError.__init__(self, message)
1778
1711
 
1779
1712
 
1780
1713
class NoEmailInUsername(BzrError):
1788
1721
 
1789
1722
class SigningFailed(BzrError):
1790
1723
 
1791
 
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
 
1724
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
1792
1725
 
1793
1726
    def __init__(self, command_line):
1794
1727
        BzrError.__init__(self, command_line=command_line)
1795
1728
 
1796
1729
 
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
 
 
1821
1730
class WorkingTreeNotRevision(BzrError):
1822
1731
 
1823
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1732
    _fmt = ("The working tree for %(basedir)s has changed since" 
1824
1733
            " the last commit, but weave merge requires that it be"
1825
1734
            " unchanged")
1826
1735
 
1939
1848
        self.prefix = prefix
1940
1849
 
1941
1850
 
1942
 
class MalformedTransform(InternalBzrError):
 
1851
class MalformedTransform(BzrError):
1943
1852
 
1944
1853
    _fmt = "Tree transform is malformed %(conflicts)r"
1945
1854
 
1983
1892
    _fmt = "Moving the root directory is not supported at this time"
1984
1893
 
1985
1894
 
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
 
 
1997
1895
class BzrMoveFailedError(BzrError):
1998
1896
 
1999
 
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
2000
 
        "%(_has_extra)s%(extra)s")
 
1897
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
2001
1898
 
2002
1899
    def __init__(self, from_path='', to_path='', extra=None):
2003
1900
        from bzrlib.osutils import splitpath
2004
1901
        BzrError.__init__(self)
2005
1902
        if extra:
2006
 
            self.extra, self._has_extra = extra, ': '
 
1903
            self.extra = ': ' + str(extra)
2007
1904
        else:
2008
 
            self.extra = self._has_extra = ''
 
1905
            self.extra = ''
2009
1906
 
2010
1907
        has_from = len(from_path) > 0
2011
1908
        has_to = len(to_path) > 0
2032
1929
 
2033
1930
class BzrRenameFailedError(BzrMoveFailedError):
2034
1931
 
2035
 
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
2036
 
        "%(_has_extra)s%(extra)s")
 
1932
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
2037
1933
 
2038
1934
    def __init__(self, from_path, to_path, extra=None):
2039
1935
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
2040
1936
 
 
1937
class BzrRemoveChangedFilesError(BzrError):
 
1938
    """Used when user is trying to remove changed files."""
 
1939
 
 
1940
    _fmt = ("Can't safely remove modified or unknown files:\n"
 
1941
        "%(changes_as_text)s"
 
1942
        "Use --keep to not delete them, or --force to delete them regardless.")
 
1943
 
 
1944
    def __init__(self, tree_delta):
 
1945
        BzrError.__init__(self)
 
1946
        self.changes_as_text = tree_delta.get_changes_as_text()
 
1947
        #self.paths_as_string = '\n'.join(changed_files)
 
1948
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
 
1949
 
2041
1950
 
2042
1951
class BzrBadParameterNotString(BzrBadParameter):
2043
1952
 
2046
1955
 
2047
1956
class BzrBadParameterMissing(BzrBadParameter):
2048
1957
 
2049
 
    _fmt = "Parameter %(param)s is required but not present."
 
1958
    _fmt = "Parameter $(param)s is required but not present."
2050
1959
 
2051
1960
 
2052
1961
class BzrBadParameterUnicode(BzrBadParameter):
2060
1969
    _fmt = "Parameter %(param)s contains a newline."
2061
1970
 
2062
1971
 
 
1972
class DependencyNotPresent(BzrError):
 
1973
 
 
1974
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1975
 
 
1976
    def __init__(self, library, error):
 
1977
        BzrError.__init__(self, library=library, error=error)
 
1978
 
 
1979
 
2063
1980
class ParamikoNotPresent(DependencyNotPresent):
2064
1981
 
2065
1982
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
2084
2001
 
2085
2002
class BadConversionTarget(BzrError):
2086
2003
 
2087
 
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
2088
 
            "    %(problem)s"
 
2004
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
2089
2005
 
2090
 
    def __init__(self, problem, format, from_format=None):
 
2006
    def __init__(self, problem, format):
2091
2007
        BzrError.__init__(self)
2092
2008
        self.problem = problem
2093
2009
        self.format = format
2094
 
        self.from_format = from_format or '(unspecified)'
2095
2010
 
2096
2011
 
2097
2012
class NoDiffFound(BzrError):
2134
2049
    _fmt = """This tree contains left-over files from a failed operation.
2135
2050
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2136
2051
    keep, and delete it when you are done."""
2137
 
 
 
2052
    
2138
2053
    def __init__(self, limbo_dir):
2139
2054
       BzrError.__init__(self)
2140
2055
       self.limbo_dir = limbo_dir
2173
2088
 
2174
2089
class OutOfDateTree(BzrError):
2175
2090
 
2176
 
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
 
2091
    _fmt = "Working tree is out of date, please run 'bzr update'."
2177
2092
 
2178
 
    def __init__(self, tree, more=None):
2179
 
        if more is None:
2180
 
            more = ''
2181
 
        else:
2182
 
            more = ' ' + more
 
2093
    def __init__(self, tree):
2183
2094
        BzrError.__init__(self)
2184
2095
        self.tree = tree
2185
 
        self.more = more
2186
2096
 
2187
2097
 
2188
2098
class PublicBranchOutOfDate(BzrError):
2226
2136
 
2227
2137
    def __init__(self, repo):
2228
2138
        BzrError.__init__(self)
2229
 
        self.repo_path = repo.user_url
 
2139
        self.repo_path = repo.bzrdir.root_transport.base
2230
2140
 
2231
2141
 
2232
2142
class InconsistentDelta(BzrError):
2242
2152
        self.reason = reason
2243
2153
 
2244
2154
 
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
 
 
2257
2155
class UpgradeRequired(BzrError):
2258
2156
 
2259
2157
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2268
2166
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2269
2167
 
2270
2168
 
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
 
 
2277
2169
class LocalRequiresBoundBranch(BzrError):
2278
2170
 
2279
2171
    _fmt = "Cannot perform local-only commits on unbound branches."
2280
2172
 
2281
2173
 
 
2174
class MissingProgressBarFinish(BzrError):
 
2175
 
 
2176
    _fmt = "A nested progress bar was not 'finished' correctly."
 
2177
 
 
2178
 
 
2179
class InvalidProgressBarType(BzrError):
 
2180
 
 
2181
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
 
2182
            " is not a supported type Select one of: %(valid_types)s")
 
2183
 
 
2184
    def __init__(self, bar_type, valid_types):
 
2185
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
2186
 
 
2187
 
2282
2188
class UnsupportedOperation(BzrError):
2283
2189
 
2284
2190
    _fmt = ("The method %(mname)s is not supported on"
2300
2206
    """
2301
2207
 
2302
2208
 
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
 
 
2311
2209
class BinaryFile(BzrError):
2312
 
 
 
2210
    
2313
2211
    _fmt = "File is binary but should be text."
2314
2212
 
2315
2213
 
2335
2233
 
2336
2234
 
2337
2235
class NotABundle(BzrError):
2338
 
 
 
2236
    
2339
2237
    _fmt = "Not a bzr revision-bundle: %(text)r"
2340
2238
 
2341
2239
    def __init__(self, text):
2343
2241
        self.text = text
2344
2242
 
2345
2243
 
2346
 
class BadBundle(BzrError):
2347
 
 
 
2244
class BadBundle(BzrError): 
 
2245
    
2348
2246
    _fmt = "Bad bzr revision-bundle: %(text)r"
2349
2247
 
2350
2248
    def __init__(self, text):
2352
2250
        self.text = text
2353
2251
 
2354
2252
 
2355
 
class MalformedHeader(BadBundle):
2356
 
 
 
2253
class MalformedHeader(BadBundle): 
 
2254
    
2357
2255
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2358
2256
 
2359
2257
 
2360
 
class MalformedPatches(BadBundle):
2361
 
 
 
2258
class MalformedPatches(BadBundle): 
 
2259
    
2362
2260
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2363
2261
 
2364
2262
 
2365
 
class MalformedFooter(BadBundle):
2366
 
 
 
2263
class MalformedFooter(BadBundle): 
 
2264
    
2367
2265
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2368
2266
 
2369
2267
 
2370
2268
class UnsupportedEOLMarker(BadBundle):
2371
 
 
2372
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
2269
    
 
2270
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
2373
2271
 
2374
2272
    def __init__(self):
2375
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
2273
        # XXX: BadBundle's constructor assumes there's explanatory text, 
2376
2274
        # but for this there is not
2377
2275
        BzrError.__init__(self)
2378
2276
 
2379
2277
 
2380
2278
class IncompatibleBundleFormat(BzrError):
2381
 
 
 
2279
    
2382
2280
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2383
2281
 
2384
2282
    def __init__(self, bundle_format, other):
2388
2286
 
2389
2287
 
2390
2288
class BadInventoryFormat(BzrError):
2391
 
 
 
2289
    
2392
2290
    _fmt = "Root class for inventory serialization errors"
2393
2291
 
2394
2292
 
2413
2311
        self.transport = transport
2414
2312
 
2415
2313
 
 
2314
class NoSmartServer(NotBranchError):
 
2315
 
 
2316
    _fmt = "No smart server available at %(url)s"
 
2317
 
 
2318
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
 
2319
    def __init__(self, url):
 
2320
        self.url = url
 
2321
 
 
2322
 
2416
2323
class UnknownSSH(BzrError):
2417
2324
 
2418
2325
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2438
2345
        self.revision_id = revision_id
2439
2346
        self.ghost_revision_id = ghost_revision_id
2440
2347
 
2441
 
 
 
2348
        
2442
2349
class GhostRevisionUnusableHere(BzrError):
2443
2350
 
2444
2351
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2536
2443
 
2537
2444
 
2538
2445
class UnsupportedInventoryKind(BzrError):
2539
 
 
 
2446
    
2540
2447
    _fmt = """Unsupported entry kind %(kind)s"""
2541
2448
 
2542
2449
    def __init__(self, kind):
2554
2461
 
2555
2462
 
2556
2463
class SubsumeTargetNeedsUpgrade(BzrError):
2557
 
 
 
2464
    
2558
2465
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2559
2466
 
2560
2467
    def __init__(self, other_tree):
2588
2495
    def __init__(self, branch):
2589
2496
        self.branch = branch
2590
2497
 
2591
 
 
 
2498
        
2592
2499
class TagAlreadyExists(BzrError):
2593
2500
 
2594
2501
    _fmt = "Tag %(tag_name)s already exists."
2599
2506
 
2600
2507
class MalformedBugIdentifier(BzrError):
2601
2508
 
2602
 
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
2603
 
            'See "bzr help bugs" for more information on this feature.')
 
2509
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2604
2510
 
2605
2511
    def __init__(self, bug_id, reason):
2606
2512
        self.bug_id = bug_id
2627
2533
        self.branch = branch
2628
2534
 
2629
2535
 
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
 
 
2646
2536
class UnexpectedSmartServerResponse(BzrError):
2647
2537
 
2648
2538
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2676
2566
 
2677
2567
    This is distinct from ErrorFromSmartServer so that it is possible to
2678
2568
    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.
 
2569
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2570
        and so should provoke a traceback to the user.
 
2571
      - ErrorFromSmartServer was caught but its error_tuple could not be
 
2572
        translated.  This is probably because the server sent us garbage, and
 
2573
        should not provoke a traceback.
2685
2574
    """
2686
2575
 
2687
2576
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2695
2584
        """
2696
2585
        self.error_from_smart_server = error_from_smart_server
2697
2586
        self.error_tuple = error_from_smart_server.error_tuple
2698
 
 
 
2587
        
2699
2588
 
2700
2589
class ContainerError(BzrError):
2701
2590
    """Base class of container errors."""
2704
2593
class UnknownContainerFormatError(ContainerError):
2705
2594
 
2706
2595
    _fmt = "Unrecognised container format: %(container_format)r"
2707
 
 
 
2596
    
2708
2597
    def __init__(self, container_format):
2709
2598
        self.container_format = container_format
2710
2599
 
2743
2632
    _fmt = "Container has multiple records with the same name: %(name)s"
2744
2633
 
2745
2634
    def __init__(self, name):
2746
 
        self.name = name.decode("utf-8")
 
2635
        self.name = name
2747
2636
 
2748
2637
 
2749
2638
class NoDestinationAddress(InternalBzrError):
2774
2663
 
2775
2664
class NoMailAddressSpecified(BzrError):
2776
2665
 
2777
 
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
 
2666
    _fmt = "No mail-to address specified."
 
2667
 
 
2668
 
 
2669
class UnknownMailClient(BzrError):
 
2670
 
 
2671
    _fmt = "Unknown mail client: %(mail_client)s"
 
2672
 
 
2673
    def __init__(self, mail_client):
 
2674
        BzrError.__init__(self, mail_client=mail_client)
2778
2675
 
2779
2676
 
2780
2677
class MailClientNotFound(BzrError):
2805
2702
 
2806
2703
    def __init__(self, bzrdir):
2807
2704
        import bzrlib.urlutils as urlutils
2808
 
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
 
2705
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
2809
2706
                                                    'ascii')
2810
2707
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2811
2708
 
2852
2749
    _fmt = "'%(display_url)s' is already standalone."
2853
2750
 
2854
2751
 
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
 
 
2867
2752
class ReconfigurationNotSupported(BzrDirError):
2868
2753
 
2869
2754
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2876
2761
 
2877
2762
class UncommittedChanges(BzrError):
2878
2763
 
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')
 
2764
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
 
2765
 
 
2766
    def __init__(self, tree):
 
2767
        import bzrlib.urlutils as urlutils
 
2768
        display_url = urlutils.unescape_for_display(
 
2769
            tree.bzrdir.root_transport.base, 'ascii')
 
2770
        BzrError.__init__(self, tree=tree, display_url=display_url)
2915
2771
 
2916
2772
 
2917
2773
class MissingTemplateVariable(BzrError):
2952
2808
 
2953
2809
 
2954
2810
class CommandAvailableInPlugin(StandardError):
2955
 
 
 
2811
    
2956
2812
    internal_error = False
2957
2813
 
2958
2814
    def __init__(self, cmd_name, plugin_metadata, provider):
2959
 
 
 
2815
        
2960
2816
        self.plugin_metadata = plugin_metadata
2961
2817
        self.cmd_name = cmd_name
2962
2818
        self.provider = provider
2963
2819
 
2964
2820
    def __str__(self):
2965
2821
 
2966
 
        _fmt = ('"%s" is not a standard bzr command. \n'
 
2822
        _fmt = ('"%s" is not a standard bzr command. \n' 
2967
2823
                'However, the following official plugin provides this command: %s\n'
2968
2824
                'You can install it by going to: %s'
2969
 
                % (self.cmd_name, self.plugin_metadata['name'],
 
2825
                % (self.cmd_name, self.plugin_metadata['name'], 
2970
2826
                    self.plugin_metadata['url']))
2971
2827
 
2972
2828
        return _fmt
2973
2829
 
2974
2830
 
2975
2831
class NoPluginAvailable(BzrError):
2976
 
    pass
 
2832
    pass    
 
2833
 
 
2834
 
 
2835
class NotATerminal(BzrError):
 
2836
 
 
2837
    _fmt = 'Unable to ask for a password without real terminal.'
2977
2838
 
2978
2839
 
2979
2840
class UnableEncodePath(BzrError):
2985
2846
        from bzrlib.osutils import get_user_encoding
2986
2847
        self.path = path
2987
2848
        self.kind = kind
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)
 
2849
        self.user_encoding = osutils.get_user_encoding()
3005
2850
 
3006
2851
 
3007
2852
class NoSuchAlias(BzrError):
3039
2884
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
3040
2885
 
3041
2886
    def __init__(self, host, port, orig_error):
3042
 
        # nb: in python2.4 socket.error doesn't have a useful repr
3043
2887
        BzrError.__init__(self, host=host, port=port,
3044
 
            orig_error=repr(orig_error.args))
 
2888
            orig_error=orig_error[1])
3045
2889
 
3046
2890
 
3047
2891
class UnknownRules(BzrError):
3052
2896
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
3053
2897
 
3054
2898
 
 
2899
class HookFailed(BzrError):
 
2900
    """Raised when a pre_change_branch_tip hook function fails anything other
 
2901
    than TipChangeRejected.
 
2902
    """
 
2903
 
 
2904
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
 
2905
            "%(traceback_text)s%(exc_value)s")
 
2906
 
 
2907
    def __init__(self, hook_stage, hook_name, exc_info):
 
2908
        import traceback
 
2909
        self.hook_stage = hook_stage
 
2910
        self.hook_name = hook_name
 
2911
        self.exc_info = exc_info
 
2912
        self.exc_type = exc_info[0]
 
2913
        self.exc_value = exc_info[1]
 
2914
        self.exc_tb = exc_info[2]
 
2915
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
 
2916
 
 
2917
 
3055
2918
class TipChangeRejected(BzrError):
3056
2919
    """A pre_change_branch_tip hook function may raise this to cleanly and
3057
2920
    explicitly abort a change to a branch tip.
3058
2921
    """
3059
 
 
 
2922
    
3060
2923
    _fmt = u"Tip change rejected: %(msg)s"
3061
2924
 
3062
2925
    def __init__(self, msg):
3068
2931
    _fmt = "Shelf corrupt."
3069
2932
 
3070
2933
 
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
2934
class NoSuchShelfId(BzrError):
3084
2935
 
3085
2936
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
3088
2939
        BzrError.__init__(self, shelf_id=shelf_id)
3089
2940
 
3090
2941
 
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
2942
class UserAbort(BzrError):
3108
2943
 
3109
2944
    _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 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.')