~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Ian Clatworthy
  • Date: 2009-09-09 11:43:10 UTC
  • mto: (4634.37.2 prepare-2.0)
  • mto: This revision was merged to the branch mainline in revision 4689.
  • Revision ID: ian.clatworthy@canonical.com-20090909114310-glw7tv76i5gnx9pt
put rules back in Makefile supporting plain-style docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 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., 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
20
from bzrlib import (
22
21
    osutils,
23
22
    symbol_versioning,
32
31
 
33
32
 
34
33
# 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 
 
34
# python exceptions?   A list of values with no names seems less useful
36
35
# to me.
37
36
 
38
 
# 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
39
38
# constructed to make sure it will succeed.  But that says nothing about
40
39
# exceptions that are never raised.
41
40
 
44
43
# 'unprintable'.
45
44
 
46
45
 
 
46
# return codes from the bzr program
 
47
EXIT_OK = 0
 
48
EXIT_ERROR = 3
 
49
EXIT_INTERNAL_ERROR = 4
 
50
 
 
51
 
47
52
class BzrError(StandardError):
48
53
    """
49
54
    Base class for errors raised by bzrlib.
56
61
    :cvar _fmt: Format string to display the error; this is expanded
57
62
    by the instance's dict.
58
63
    """
59
 
    
 
64
 
60
65
    internal_error = False
61
66
 
62
67
    def __init__(self, msg=None, **kwds):
67
72
        arguments can be given.  The first is for generic "user" errors which
68
73
        are not intended to be caught and so do not need a specific subclass.
69
74
        The second case is for use with subclasses that provide a _fmt format
70
 
        string to print the arguments.  
 
75
        string to print the arguments.
71
76
 
72
 
        Keyword arguments are taken as parameters to the error, which can 
73
 
        be inserted into the format string template.  It's recommended 
74
 
        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
75
80
        parameters.
76
81
 
77
82
        :param msg: If given, this is the literal complete text for the error,
78
 
        not subject to expansion.
 
83
           not subject to expansion. 'msg' is used instead of 'message' because
 
84
           python evolved and, in 2.6, forbids the use of 'message'.
79
85
        """
80
86
        StandardError.__init__(self)
81
87
        if msg is not None:
87
93
            for key, value in kwds.items():
88
94
                setattr(self, key, value)
89
95
 
90
 
    def __str__(self):
 
96
    def _format(self):
91
97
        s = getattr(self, '_preformatted_string', None)
92
98
        if s is not None:
93
 
            # contains a preformatted message; must be cast to plain str
94
 
            return str(s)
 
99
            # contains a preformatted message
 
100
            return s
95
101
        try:
96
102
            fmt = self._get_format_string()
97
103
            if fmt:
98
 
                s = fmt % self.__dict__
 
104
                d = dict(self.__dict__)
 
105
                s = fmt % d
99
106
                # __str__() should always return a 'str' object
100
107
                # never a 'unicode' object.
101
 
                if isinstance(s, unicode):
102
 
                    return s.encode('utf8')
103
108
                return s
104
109
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
105
110
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
108
113
                   getattr(self, '_fmt', None),
109
114
                   e)
110
115
 
 
116
    def __unicode__(self):
 
117
        u = self._format()
 
118
        if isinstance(u, str):
 
119
            # Try decoding the str using the default encoding.
 
120
            u = unicode(u)
 
121
        elif not isinstance(u, unicode):
 
122
            # Try to make a unicode object from it, because __unicode__ must
 
123
            # return a unicode object.
 
124
            u = unicode(u)
 
125
        return u
 
126
 
 
127
    def __str__(self):
 
128
        s = self._format()
 
129
        if isinstance(s, unicode):
 
130
            s = s.encode('utf8')
 
131
        else:
 
132
            # __str__ must return a str.
 
133
            s = str(s)
 
134
        return s
 
135
 
 
136
    def __repr__(self):
 
137
        return '%s(%s)' % (self.__class__.__name__, str(self))
 
138
 
111
139
    def _get_format_string(self):
112
140
        """Return format string for this exception or None"""
113
141
        fmt = getattr(self, '_fmt', None)
125
153
               getattr(self, '_fmt', None),
126
154
               )
127
155
 
 
156
    def __eq__(self, other):
 
157
        if self.__class__ is not other.__class__:
 
158
            return NotImplemented
 
159
        return self.__dict__ == other.__dict__
 
160
 
 
161
 
 
162
class InternalBzrError(BzrError):
 
163
    """Base class for errors that are internal in nature.
 
164
 
 
165
    This is a convenience class for errors that are internal. The
 
166
    internal_error attribute can still be altered in subclasses, if needed.
 
167
    Using this class is simply an easy way to get internal errors.
 
168
    """
 
169
 
 
170
    internal_error = True
 
171
 
128
172
 
129
173
class BzrNewError(BzrError):
130
174
    """Deprecated error base class."""
160
204
 
161
205
 
162
206
class AlreadyBuilding(BzrError):
163
 
    
 
207
 
164
208
    _fmt = "The tree builder is already building a tree."
165
209
 
166
210
 
167
 
class BzrCheckError(BzrError):
168
 
    
169
 
    _fmt = "Internal check failed: %(message)s"
170
 
 
171
 
    internal_error = True
172
 
 
173
 
    def __init__(self, message):
174
 
        BzrError.__init__(self)
175
 
        self.message = message
176
 
 
177
 
 
178
 
class DisabledMethod(BzrError):
 
211
class BranchError(BzrError):
 
212
    """Base class for concrete 'errors about a branch'."""
 
213
 
 
214
    def __init__(self, branch):
 
215
        BzrError.__init__(self, branch=branch)
 
216
 
 
217
 
 
218
class BzrCheckError(InternalBzrError):
 
219
 
 
220
    _fmt = "Internal check failed: %(msg)s"
 
221
 
 
222
    def __init__(self, msg):
 
223
        BzrError.__init__(self)
 
224
        self.msg = msg
 
225
 
 
226
 
 
227
class DirstateCorrupt(BzrError):
 
228
 
 
229
    _fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
 
230
 
 
231
    def __init__(self, state, msg):
 
232
        BzrError.__init__(self)
 
233
        self.state = state
 
234
        self.msg = msg
 
235
 
 
236
 
 
237
class DisabledMethod(InternalBzrError):
179
238
 
180
239
    _fmt = "The smart server method '%(class_name)s' is disabled."
181
240
 
182
 
    internal_error = True
183
 
 
184
241
    def __init__(self, class_name):
185
242
        BzrError.__init__(self)
186
243
        self.class_name = class_name
207
264
        self.transport = transport
208
265
 
209
266
 
210
 
class InvalidEntryName(BzrError):
211
 
    
 
267
class InvalidEntryName(InternalBzrError):
 
268
 
212
269
    _fmt = "Invalid entry name: %(name)s"
213
270
 
214
 
    internal_error = True
215
 
 
216
271
    def __init__(self, name):
217
272
        BzrError.__init__(self)
218
273
        self.name = name
219
274
 
220
275
 
221
276
class InvalidRevisionNumber(BzrError):
222
 
    
 
277
 
223
278
    _fmt = "Invalid revision number %(revno)s"
224
279
 
225
280
    def __init__(self, revno):
237
292
        self.revision_id = revision_id
238
293
        self.branch = branch
239
294
 
 
295
 
240
296
class ReservedId(BzrError):
241
297
 
242
298
    _fmt = "Reserved revision-id {%(revision_id)s}"
245
301
        self.revision_id = revision_id
246
302
 
247
303
 
 
304
class RootMissing(InternalBzrError):
 
305
 
 
306
    _fmt = ("The root entry of a tree must be the first entry supplied to "
 
307
        "record_entry_contents.")
 
308
 
 
309
 
 
310
class NoPublicBranch(BzrError):
 
311
 
 
312
    _fmt = 'There is no public branch set for "%(branch_url)s".'
 
313
 
 
314
    def __init__(self, branch):
 
315
        import bzrlib.urlutils as urlutils
 
316
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
 
317
        BzrError.__init__(self, branch_url=public_location)
 
318
 
 
319
 
248
320
class NoHelpTopic(BzrError):
249
321
 
250
322
    _fmt = ("No help could be found for '%(topic)s'. "
257
329
class NoSuchId(BzrError):
258
330
 
259
331
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
260
 
    
 
332
 
261
333
    def __init__(self, tree, file_id):
262
334
        BzrError.__init__(self)
263
335
        self.file_id = file_id
273
345
        BzrError.__init__(self, repository=repository, file_id=file_id)
274
346
 
275
347
 
276
 
class InventoryModified(BzrError):
 
348
class NotStacked(BranchError):
 
349
 
 
350
    _fmt = "The branch '%(branch)s' is not stacked."
 
351
 
 
352
 
 
353
class InventoryModified(InternalBzrError):
277
354
 
278
355
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
279
356
            " so a clean inventory cannot be read without data loss.")
280
357
 
281
 
    internal_error = True
282
 
 
283
358
    def __init__(self, tree):
284
359
        self.tree = tree
285
360
 
287
362
class NoWorkingTree(BzrError):
288
363
 
289
364
    _fmt = 'No WorkingTree exists for "%(base)s".'
290
 
    
 
365
 
291
366
    def __init__(self, base):
292
367
        BzrError.__init__(self)
293
368
        self.base = base
306
381
        self.url = url
307
382
 
308
383
 
309
 
class WorkingTreeAlreadyPopulated(BzrError):
 
384
class WorkingTreeAlreadyPopulated(InternalBzrError):
310
385
 
311
386
    _fmt = 'Working tree already populated in "%(base)s"'
312
387
 
313
 
    internal_error = True
314
 
 
315
388
    def __init__(self, base):
316
389
        self.base = base
317
390
 
 
391
 
318
392
class BzrCommandError(BzrError):
319
393
    """Error from user command"""
320
394
 
321
 
    internal_error = False
322
 
 
323
395
    # Error from malformed user command; please avoid raising this as a
324
396
    # generic exception not caused by user input.
325
397
    #
327
399
    # are not intended to be caught anyway.  UI code need not subclass
328
400
    # BzrCommandError, and non-UI code should not throw a subclass of
329
401
    # BzrCommandError.  ADHB 20051211
330
 
    def __init__(self, msg):
331
 
        # Object.__str__() must return a real string
332
 
        # returning a Unicode string is a python error.
333
 
        if isinstance(msg, unicode):
334
 
            self.msg = msg.encode('utf8')
335
 
        else:
336
 
            self.msg = msg
337
 
 
338
 
    def __str__(self):
339
 
        return self.msg
340
402
 
341
403
 
342
404
class NotWriteLocked(BzrError):
415
477
    def __init__(self, name, value):
416
478
        BzrError.__init__(self, name=name, value=value)
417
479
 
418
 
    
 
480
 
419
481
class StrictCommitFailed(BzrError):
420
482
 
421
483
    _fmt = "Commit refused because there are unknown files in the tree"
424
486
# XXX: Should be unified with TransportError; they seem to represent the
425
487
# same thing
426
488
# RBC 20060929: I think that unifiying with TransportError would be a mistake
427
 
# - 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
428
490
# differentiates between 'transport has failed' and 'operation on a transport
429
491
# has failed.'
430
492
class PathError(BzrError):
431
 
    
 
493
 
432
494
    _fmt = "Generic path error: %(path)r%(extra)s)"
433
495
 
434
496
    def __init__(self, path, extra=None):
454
516
    """Used when renaming and both source and dest exist."""
455
517
 
456
518
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
457
 
            "%(extra)s")
 
519
            " (Use --after to tell bzr about a rename that has already"
 
520
            " happened)%(extra)s")
458
521
 
459
522
    def __init__(self, source, dest, extra=None):
460
523
        BzrError.__init__(self)
481
544
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
482
545
 
483
546
 
484
 
class ReadingCompleted(BzrError):
485
 
    
 
547
class HardLinkNotSupported(PathError):
 
548
 
 
549
    _fmt = 'Hard-linking "%(path)s" is not supported'
 
550
 
 
551
 
 
552
class ReadingCompleted(InternalBzrError):
 
553
 
486
554
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
487
555
            "called upon it - the request has been completed and no more "
488
556
            "data may be read.")
489
557
 
490
 
    internal_error = True
491
 
 
492
558
    def __init__(self, request):
493
559
        self.request = request
494
560
 
510
576
 
511
577
class InvalidURLJoin(PathError):
512
578
 
513
 
    _fmt = 'Invalid URL join request: "%(args)s"%(extra)s'
514
 
 
515
 
    def __init__(self, msg, base, args):
516
 
        PathError.__init__(self, base, msg)
517
 
        self.args = [base] + list(args)
 
579
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
 
580
 
 
581
    def __init__(self, reason, base, join_args):
 
582
        self.reason = reason
 
583
        self.base = base
 
584
        self.join_args = join_args
 
585
        PathError.__init__(self, base, reason)
 
586
 
 
587
 
 
588
class InvalidRebaseURLs(PathError):
 
589
 
 
590
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
 
591
 
 
592
    def __init__(self, from_, to):
 
593
        self.from_ = from_
 
594
        self.to = to
 
595
        PathError.__init__(self, from_, 'URLs differ by more than path.')
 
596
 
 
597
 
 
598
class UnavailableRepresentation(InternalBzrError):
 
599
 
 
600
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
 
601
        "is encoded as '%(native)s'.")
 
602
 
 
603
    def __init__(self, key, wanted, native):
 
604
        InternalBzrError.__init__(self)
 
605
        self.wanted = wanted
 
606
        self.native = native
 
607
        self.key = key
518
608
 
519
609
 
520
610
class UnknownHook(BzrError):
535
625
        PathError.__init__(self, url, extra=extra)
536
626
 
537
627
 
 
628
class UnstackableBranchFormat(BzrError):
 
629
 
 
630
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
 
631
        "You will need to upgrade the branch to permit branch stacking.")
 
632
 
 
633
    def __init__(self, format, url):
 
634
        BzrError.__init__(self)
 
635
        self.format = format
 
636
        self.url = url
 
637
 
 
638
 
 
639
class UnstackableLocationError(BzrError):
 
640
 
 
641
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
 
642
 
 
643
    def __init__(self, branch_url, target_url):
 
644
        BzrError.__init__(self)
 
645
        self.branch_url = branch_url
 
646
        self.target_url = target_url
 
647
 
 
648
 
 
649
class UnstackableRepositoryFormat(BzrError):
 
650
 
 
651
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
 
652
        "You will need to upgrade the repository to permit branch stacking.")
 
653
 
 
654
    def __init__(self, format, url):
 
655
        BzrError.__init__(self)
 
656
        self.format = format
 
657
        self.url = url
 
658
 
 
659
 
538
660
class ReadError(PathError):
539
 
    
 
661
 
540
662
    _fmt = """Error reading from %(path)r."""
541
663
 
542
664
 
577
699
 
578
700
# TODO: This is given a URL; we try to unescape it but doing that from inside
579
701
# the exception object is a bit undesirable.
580
 
# TODO: Probably this behavior of should be a common superclass 
 
702
# TODO: Probably this behavior of should be a common superclass
581
703
class NotBranchError(PathError):
582
704
 
583
705
    _fmt = 'Not a branch: "%(path)s".'
637
759
 
638
760
class FileInWrongBranch(BzrError):
639
761
 
640
 
    _fmt = 'File "%(path)s" in not in branch %(branch_base)s.'
 
762
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
641
763
 
642
764
    def __init__(self, branch, path):
643
765
        BzrError.__init__(self)
652
774
 
653
775
 
654
776
class UnknownFormatError(BzrError):
655
 
    
656
 
    _fmt = "Unknown branch format: %(format)r"
 
777
 
 
778
    _fmt = "Unknown %(kind)s format: %(format)r"
 
779
 
 
780
    def __init__(self, format, kind='branch'):
 
781
        self.kind = kind
 
782
        self.format = format
657
783
 
658
784
 
659
785
class IncompatibleFormat(BzrError):
660
 
    
 
786
 
661
787
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
662
788
 
663
789
    def __init__(self, format, bzrdir_format):
667
793
 
668
794
 
669
795
class IncompatibleRepositories(BzrError):
670
 
 
671
 
    _fmt = "Repository %(target)s is not compatible with repository"\
672
 
        " %(source)s"
673
 
 
674
 
    def __init__(self, source, target):
675
 
        BzrError.__init__(self, target=target, source=source)
 
796
    """Report an error that two repositories are not compatible.
 
797
 
 
798
    Note that the source and target repositories are permitted to be strings:
 
799
    this exception is thrown from the smart server and may refer to a
 
800
    repository the client hasn't opened.
 
801
    """
 
802
 
 
803
    _fmt = "%(target)s\n" \
 
804
            "is not compatible with\n" \
 
805
            "%(source)s\n" \
 
806
            "%(details)s"
 
807
 
 
808
    def __init__(self, source, target, details=None):
 
809
        if details is None:
 
810
            details = "(no details)"
 
811
        BzrError.__init__(self, target=target, source=source, details=details)
676
812
 
677
813
 
678
814
class IncompatibleRevision(BzrError):
679
 
    
 
815
 
680
816
    _fmt = "Revision is not compatible with %(repo_format)s"
681
817
 
682
818
    def __init__(self, repo_format):
765
901
        BzrError.__init__(self, filename=filename, kind=kind)
766
902
 
767
903
 
 
904
class BadFilenameEncoding(BzrError):
 
905
 
 
906
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
 
907
            ' encoding %(fs_encoding)s')
 
908
 
 
909
    def __init__(self, filename, fs_encoding):
 
910
        BzrError.__init__(self)
 
911
        self.filename = filename
 
912
        self.fs_encoding = fs_encoding
 
913
 
 
914
 
768
915
class ForbiddenControlFileError(BzrError):
769
916
 
770
917
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
771
918
 
772
919
 
773
 
class LockError(BzrError):
 
920
class LockError(InternalBzrError):
774
921
 
775
922
    _fmt = "Lock error: %(msg)s"
776
923
 
777
 
    internal_error = True
778
 
 
779
924
    # All exceptions from the lock/unlock functions should be from
780
925
    # this exception class.  They will be translated as necessary. The
781
926
    # original exception is available as e.original_error
783
928
    # New code should prefer to raise specific subclasses
784
929
    def __init__(self, message):
785
930
        # Python 2.5 uses a slot for StandardError.message,
786
 
        # so use a different variable name
787
 
        # so it is exposed in self.__dict__
 
931
        # so use a different variable name.  We now work around this in
 
932
        # BzrError.__str__, but this member name is kept for compatability.
788
933
        self.msg = message
789
934
 
790
935
 
825
970
        self.obj = obj
826
971
 
827
972
 
828
 
class ReadOnlyLockError(LockError):
829
 
 
830
 
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
831
 
 
832
 
    def __init__(self, fname, msg):
 
973
class LockFailed(LockError):
 
974
 
 
975
    internal_error = False
 
976
 
 
977
    _fmt = "Cannot lock %(lock)s: %(why)s"
 
978
 
 
979
    def __init__(self, lock, why):
833
980
        LockError.__init__(self, '')
834
 
        self.fname = fname
835
 
        self.msg = msg
 
981
        self.lock = lock
 
982
        self.why = why
836
983
 
837
984
 
838
985
class OutSideTransaction(BzrError):
862
1009
 
863
1010
class UnlockableTransport(LockError):
864
1011
 
 
1012
    internal_error = False
 
1013
 
865
1014
    _fmt = "Cannot lock: transport is read only: %(transport)s"
866
1015
 
867
1016
    def __init__(self, transport):
870
1019
 
871
1020
class LockContention(LockError):
872
1021
 
873
 
    _fmt = 'Could not acquire lock "%(lock)s"'
 
1022
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
874
1023
    # TODO: show full url for lock, combining the transport and relative
875
1024
    # bits?
876
1025
 
877
1026
    internal_error = False
878
1027
 
879
 
    def __init__(self, lock):
 
1028
    def __init__(self, lock, msg=''):
880
1029
        self.lock = lock
 
1030
        self.msg = msg
881
1031
 
882
1032
 
883
1033
class LockBroken(LockError):
918
1068
 
919
1069
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
920
1070
 
921
 
    internal_error = True
922
 
 
923
1071
    def __init__(self, obj):
924
1072
        self.obj = obj
925
1073
 
975
1123
    _fmt = "Commit refused because there are unknowns in the tree."
976
1124
 
977
1125
 
978
 
class NoSuchRevision(BzrError):
 
1126
class NoSuchRevision(InternalBzrError):
979
1127
 
980
1128
    _fmt = "%(branch)s has no revision %(revision)s"
981
1129
 
982
 
    internal_error = True
983
 
 
984
1130
    def __init__(self, branch, revision):
985
1131
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
986
1132
        BzrError.__init__(self, branch=branch, revision=revision)
987
1133
 
988
1134
 
989
 
# zero_ninetyone: this exception is no longer raised and should be removed
990
 
class NotLeftParentDescendant(BzrError):
991
 
 
992
 
    _fmt = ("Revision %(old_revision)s is not the left parent of"
993
 
            " %(new_revision)s, but branch %(branch_location)s expects this")
994
 
 
995
 
    internal_error = True
996
 
 
997
 
    def __init__(self, branch, old_revision, new_revision):
998
 
        BzrError.__init__(self, branch_location=branch.base,
999
 
                          old_revision=old_revision,
1000
 
                          new_revision=new_revision)
1001
 
 
1002
 
 
1003
1135
class RangeInChangeOption(BzrError):
1004
1136
 
1005
1137
    _fmt = "Option --change does not accept revision ranges"
1015
1147
 
1016
1148
class NoSuchRevisionInTree(NoSuchRevision):
1017
1149
    """When using Tree.revision_tree, and the revision is not accessible."""
1018
 
    
 
1150
 
1019
1151
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1020
1152
 
1021
1153
    def __init__(self, tree, revision_id):
1057
1189
class DivergedBranches(BzrError):
1058
1190
 
1059
1191
    _fmt = ("These branches have diverged."
1060
 
            " Use the merge command to reconcile them.")
1061
 
 
1062
 
    internal_error = False
 
1192
            " Use the missing command to see how.\n"
 
1193
            "Use the merge command to reconcile them.")
1063
1194
 
1064
1195
    def __init__(self, branch1, branch2):
1065
1196
        self.branch1 = branch1
1066
1197
        self.branch2 = branch2
1067
1198
 
1068
1199
 
1069
 
class NotLefthandHistory(BzrError):
 
1200
class NotLefthandHistory(InternalBzrError):
1070
1201
 
1071
1202
    _fmt = "Supplied history does not follow left-hand parents"
1072
1203
 
1073
 
    internal_error = True
1074
 
 
1075
1204
    def __init__(self, history):
1076
1205
        BzrError.__init__(self, history=history)
1077
1206
 
1081
1210
    _fmt = ("Branches have no common ancestor, and"
1082
1211
            " no merge base revision was specified.")
1083
1212
 
1084
 
    internal_error = False
 
1213
 
 
1214
class CannotReverseCherrypick(BzrError):
 
1215
 
 
1216
    _fmt = ('Selected merge cannot perform reverse cherrypicks.  Try merge3'
 
1217
            ' or diff3.')
1085
1218
 
1086
1219
 
1087
1220
class NoCommonAncestor(BzrError):
1088
 
    
 
1221
 
1089
1222
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1090
1223
 
1091
1224
    def __init__(self, revision_a, revision_b):
1111
1244
            not_ancestor_id=not_ancestor_id)
1112
1245
 
1113
1246
 
1114
 
class InstallFailed(BzrError):
1115
 
 
1116
 
    def __init__(self, revisions):
1117
 
        revision_str = ", ".join(str(r) for r in revisions)
1118
 
        msg = "Could not install revisions:\n%s" % revision_str
1119
 
        BzrError.__init__(self, msg)
1120
 
        self.revisions = revisions
1121
 
 
1122
 
 
1123
1247
class AmbiguousBase(BzrError):
1124
1248
 
1125
1249
    def __init__(self, bases):
1131
1255
        self.bases = bases
1132
1256
 
1133
1257
 
1134
 
class NoCommits(BzrError):
 
1258
class NoCommits(BranchError):
1135
1259
 
1136
1260
    _fmt = "Branch %(branch)s has no commits."
1137
1261
 
1138
 
    def __init__(self, branch):
1139
 
        BzrError.__init__(self, branch=branch)
1140
 
 
1141
1262
 
1142
1263
class UnlistableStore(BzrError):
1143
1264
 
1162
1283
        self.branch = branch
1163
1284
        self.master = master
1164
1285
 
1165
 
        
 
1286
 
1166
1287
class CommitToDoubleBoundBranch(BzrError):
1167
1288
 
1168
1289
    _fmt = ("Cannot commit to branch %(branch)s."
1198
1319
 
1199
1320
class WeaveError(BzrError):
1200
1321
 
1201
 
    _fmt = "Error in processing weave: %(message)s"
 
1322
    _fmt = "Error in processing weave: %(msg)s"
1202
1323
 
1203
 
    def __init__(self, message=None):
 
1324
    def __init__(self, msg=None):
1204
1325
        BzrError.__init__(self)
1205
 
        self.message = message
 
1326
        self.msg = msg
1206
1327
 
1207
1328
 
1208
1329
class WeaveRevisionAlreadyPresent(WeaveError):
1237
1358
 
1238
1359
class WeaveParentMismatch(WeaveError):
1239
1360
 
1240
 
    _fmt = "Parents are mismatched between two revisions."
1241
 
    
 
1361
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
1362
 
1242
1363
 
1243
1364
class WeaveInvalidChecksum(WeaveError):
1244
1365
 
1270
1391
 
1271
1392
 
1272
1393
class VersionedFileError(BzrError):
1273
 
    
 
1394
 
1274
1395
    _fmt = "Versioned file error"
1275
1396
 
1276
1397
 
1277
1398
class RevisionNotPresent(VersionedFileError):
1278
 
    
 
1399
 
1279
1400
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1280
1401
 
1281
1402
    def __init__(self, revision_id, file_id):
1285
1406
 
1286
1407
 
1287
1408
class RevisionAlreadyPresent(VersionedFileError):
1288
 
    
 
1409
 
1289
1410
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1290
1411
 
1291
1412
    def __init__(self, revision_id, file_id):
1299
1420
    _fmt = "Text did not match its checksum: %(message)s"
1300
1421
 
1301
1422
 
1302
 
class KnitError(BzrError):
1303
 
    
 
1423
class KnitError(InternalBzrError):
 
1424
 
1304
1425
    _fmt = "Knit error"
1305
1426
 
1306
 
    internal_error = True
1307
 
 
1308
1427
 
1309
1428
class KnitCorrupt(KnitError):
1310
1429
 
1316
1435
        self.how = how
1317
1436
 
1318
1437
 
 
1438
class SHA1KnitCorrupt(KnitCorrupt):
 
1439
 
 
1440
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
 
1441
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
 
1442
        "sha %(actual)s")
 
1443
 
 
1444
    def __init__(self, filename, actual, expected, key, content):
 
1445
        KnitError.__init__(self)
 
1446
        self.filename = filename
 
1447
        self.actual = actual
 
1448
        self.expected = expected
 
1449
        self.key = key
 
1450
        self.content = content
 
1451
 
 
1452
 
1319
1453
class KnitDataStreamIncompatible(KnitError):
 
1454
    # Not raised anymore, as we can convert data streams.  In future we may
 
1455
    # need it again for more exotic cases, so we're keeping it around for now.
1320
1456
 
1321
1457
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
1322
1458
 
1323
1459
    def __init__(self, stream_format, target_format):
1324
1460
        self.stream_format = stream_format
1325
1461
        self.target_format = target_format
1326
 
        
 
1462
 
 
1463
 
 
1464
class KnitDataStreamUnknown(KnitError):
 
1465
    # Indicates a data stream we don't know how to handle.
 
1466
 
 
1467
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
 
1468
 
 
1469
    def __init__(self, stream_format):
 
1470
        self.stream_format = stream_format
 
1471
 
1327
1472
 
1328
1473
class KnitHeaderError(KnitError):
1329
1474
 
1334
1479
        self.badline = badline
1335
1480
        self.filename = filename
1336
1481
 
1337
 
 
1338
1482
class KnitIndexUnknownMethod(KnitError):
1339
1483
    """Raised when we don't understand the storage method.
1340
1484
 
1341
1485
    Currently only 'fulltext' and 'line-delta' are supported.
1342
1486
    """
1343
 
    
 
1487
 
1344
1488
    _fmt = ("Knit index %(filename)s does not have a known method"
1345
1489
            " in options: %(options)r")
1346
1490
 
1350
1494
        self.options = options
1351
1495
 
1352
1496
 
 
1497
class RetryWithNewPacks(BzrError):
 
1498
    """Raised when we realize that the packs on disk have changed.
 
1499
 
 
1500
    This is meant as more of a signaling exception, to trap between where a
 
1501
    local error occurred and the code that can actually handle the error and
 
1502
    code that can retry appropriately.
 
1503
    """
 
1504
 
 
1505
    internal_error = True
 
1506
 
 
1507
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
 
1508
            " %(orig_error)s")
 
1509
 
 
1510
    def __init__(self, context, reload_occurred, exc_info):
 
1511
        """create a new RetryWithNewPacks error.
 
1512
 
 
1513
        :param reload_occurred: Set to True if we know that the packs have
 
1514
            already been reloaded, and we are failing because of an in-memory
 
1515
            cache miss. If set to True then we will ignore if a reload says
 
1516
            nothing has changed, because we assume it has already reloaded. If
 
1517
            False, then a reload with nothing changed will force an error.
 
1518
        :param exc_info: The original exception traceback, so if there is a
 
1519
            problem we can raise the original error (value from sys.exc_info())
 
1520
        """
 
1521
        BzrError.__init__(self)
 
1522
        self.reload_occurred = reload_occurred
 
1523
        self.exc_info = exc_info
 
1524
        self.orig_error = exc_info[1]
 
1525
        # TODO: The global error handler should probably treat this by
 
1526
        #       raising/printing the original exception with a bit about
 
1527
        #       RetryWithNewPacks also not being caught
 
1528
 
 
1529
 
 
1530
class RetryAutopack(RetryWithNewPacks):
 
1531
    """Raised when we are autopacking and we find a missing file.
 
1532
 
 
1533
    Meant as a signaling exception, to tell the autopack code it should try
 
1534
    again.
 
1535
    """
 
1536
 
 
1537
    internal_error = True
 
1538
 
 
1539
    _fmt = ("Pack files have changed, reload and try autopack again."
 
1540
            " context: %(context)s %(orig_error)s")
 
1541
 
 
1542
 
1353
1543
class NoSuchExportFormat(BzrError):
1354
 
    
 
1544
 
1355
1545
    _fmt = "Export format %(format)r not supported"
1356
1546
 
1357
1547
    def __init__(self, format):
1360
1550
 
1361
1551
 
1362
1552
class TransportError(BzrError):
1363
 
    
 
1553
 
1364
1554
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1365
1555
 
1366
1556
    def __init__(self, msg=None, orig_error=None):
1375
1565
        BzrError.__init__(self)
1376
1566
 
1377
1567
 
1378
 
class TooManyConcurrentRequests(BzrError):
 
1568
class TooManyConcurrentRequests(InternalBzrError):
1379
1569
 
1380
1570
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
1381
1571
            " Be sure to finish_writing and finish_reading on the"
1382
1572
            " currently open request.")
1383
1573
 
1384
 
    internal_error = True
1385
 
 
1386
1574
    def __init__(self, medium):
1387
1575
        self.medium = medium
1388
1576
 
1395
1583
        self.details = details
1396
1584
 
1397
1585
 
 
1586
class UnexpectedProtocolVersionMarker(TransportError):
 
1587
 
 
1588
    _fmt = "Received bad protocol version marker: %(marker)r"
 
1589
 
 
1590
    def __init__(self, marker):
 
1591
        self.marker = marker
 
1592
 
 
1593
 
 
1594
class UnknownSmartMethod(InternalBzrError):
 
1595
 
 
1596
    _fmt = "The server does not recognise the '%(verb)s' request."
 
1597
 
 
1598
    def __init__(self, verb):
 
1599
        self.verb = verb
 
1600
 
 
1601
 
 
1602
class SmartMessageHandlerError(InternalBzrError):
 
1603
 
 
1604
    _fmt = ("The message handler raised an exception:\n"
 
1605
            "%(traceback_text)s")
 
1606
 
 
1607
    def __init__(self, exc_info):
 
1608
        import traceback
 
1609
        self.exc_type, self.exc_value, self.exc_tb = exc_info
 
1610
        self.exc_info = exc_info
 
1611
        traceback_strings = traceback.format_exception(
 
1612
                self.exc_type, self.exc_value, self.exc_tb)
 
1613
        self.traceback_text = ''.join(traceback_strings)
 
1614
 
 
1615
 
1398
1616
# A set of semi-meaningful errors which can be thrown
1399
1617
class TransportNotPossible(TransportError):
1400
1618
 
1425
1643
            self.port = ':%s' % port
1426
1644
 
1427
1645
 
 
1646
# XXX: This is also used for unexpected end of file, which is different at the
 
1647
# TCP level from "connection reset".
1428
1648
class ConnectionReset(TransportError):
1429
1649
 
1430
1650
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1432
1652
 
1433
1653
class InvalidRange(TransportError):
1434
1654
 
1435
 
    _fmt = "Invalid range access in %(path)s at %(offset)s."
1436
 
    
1437
 
    def __init__(self, path, offset):
1438
 
        TransportError.__init__(self, ("Invalid range access in %s at %d"
1439
 
                                       % (path, offset)))
 
1655
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
 
1656
 
 
1657
    def __init__(self, path, offset, msg=None):
 
1658
        TransportError.__init__(self, msg)
1440
1659
        self.path = path
1441
1660
        self.offset = offset
1442
1661
 
1453
1672
class InvalidHttpRange(InvalidHttpResponse):
1454
1673
 
1455
1674
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1456
 
    
 
1675
 
1457
1676
    def __init__(self, path, range, msg):
1458
1677
        self.range = range
1459
1678
        InvalidHttpResponse.__init__(self, path, msg)
1462
1681
class InvalidHttpContentType(InvalidHttpResponse):
1463
1682
 
1464
1683
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1465
 
    
 
1684
 
1466
1685
    def __init__(self, path, ctype, msg):
1467
1686
        self.ctype = ctype
1468
1687
        InvalidHttpResponse.__init__(self, path, msg)
1472
1691
 
1473
1692
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1474
1693
 
1475
 
    def __init__(self, source, target, is_permament=False, qual_proto=None):
 
1694
    def __init__(self, source, target, is_permanent=False):
1476
1695
        self.source = source
1477
1696
        self.target = target
1478
 
        if is_permament:
 
1697
        if is_permanent:
1479
1698
            self.permanently = ' permanently'
1480
1699
        else:
1481
1700
            self.permanently = ''
1482
 
        self.is_permament = is_permament
1483
 
        self._qualified_proto = qual_proto
1484
1701
        TransportError.__init__(self)
1485
1702
 
1486
 
    def _requalify_url(self, url):
1487
 
        """Restore the qualified proto in front of the url"""
1488
 
        # When this exception is raised, source and target are in
1489
 
        # user readable format. But some transports may use a
1490
 
        # different proto (http+urllib:// will present http:// to
1491
 
        # the user. If a qualified proto is specified, the code
1492
 
        # trapping the exception can get the qualified urls to
1493
 
        # properly handle the redirection themself (creating a
1494
 
        # new transport object from the target url for example).
1495
 
        # But checking that the scheme of the original and
1496
 
        # redirected urls are the same can be tricky. (see the
1497
 
        # FIXME in BzrDir.open_from_transport for the unique use
1498
 
        # case so far).
1499
 
        if self._qualified_proto is None:
1500
 
            return url
1501
 
 
1502
 
        # The TODO related to NotBranchError mention that doing
1503
 
        # that kind of manipulation on the urls may not be the
1504
 
        # exception object job. On the other hand, this object is
1505
 
        # the interface between the code and the user so
1506
 
        # presenting the urls in different ways is indeed its
1507
 
        # job...
1508
 
        import urlparse
1509
 
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1510
 
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1511
 
                                   query, fragment))
1512
 
 
1513
 
    def get_source_url(self):
1514
 
        return self._requalify_url(self.source)
1515
 
 
1516
 
    def get_target_url(self):
1517
 
        return self._requalify_url(self.target)
1518
 
 
1519
1703
 
1520
1704
class TooManyRedirections(TransportError):
1521
1705
 
1522
1706
    _fmt = "Too many redirections"
1523
1707
 
 
1708
 
1524
1709
class ConflictsInTree(BzrError):
1525
1710
 
1526
1711
    _fmt = "Working tree has conflicts."
1532
1717
        if filename is None:
1533
1718
            filename = ""
1534
1719
        message = "Error(s) parsing config file %s:\n%s" % \
1535
 
            (filename, ('\n'.join(e.message for e in errors)))
 
1720
            (filename, ('\n'.join(e.msg for e in errors)))
1536
1721
        BzrError.__init__(self, message)
1537
1722
 
1538
1723
 
1555
1740
 
1556
1741
class WorkingTreeNotRevision(BzrError):
1557
1742
 
1558
 
    _fmt = ("The working tree for %(basedir)s has changed since" 
 
1743
    _fmt = ("The working tree for %(basedir)s has changed since"
1559
1744
            " the last commit, but weave merge requires that it be"
1560
1745
            " unchanged")
1561
1746
 
1578
1763
        self.graph = graph
1579
1764
 
1580
1765
 
1581
 
class WritingCompleted(BzrError):
 
1766
class WritingCompleted(InternalBzrError):
1582
1767
 
1583
1768
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1584
1769
            "called upon it - accept bytes may not be called anymore.")
1585
1770
 
1586
 
    internal_error = True
1587
 
 
1588
1771
    def __init__(self, request):
1589
1772
        self.request = request
1590
1773
 
1591
1774
 
1592
 
class WritingNotComplete(BzrError):
 
1775
class WritingNotComplete(InternalBzrError):
1593
1776
 
1594
1777
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1595
1778
            "called upon it - until the write phase is complete no "
1596
1779
            "data may be read.")
1597
1780
 
1598
 
    internal_error = True
1599
 
 
1600
1781
    def __init__(self, request):
1601
1782
        self.request = request
1602
1783
 
1610
1791
        self.filename = filename
1611
1792
 
1612
1793
 
1613
 
class MediumNotConnected(BzrError):
 
1794
class MediumNotConnected(InternalBzrError):
1614
1795
 
1615
1796
    _fmt = """The medium '%(medium)s' is not connected."""
1616
1797
 
1617
 
    internal_error = True
1618
 
 
1619
1798
    def __init__(self, medium):
1620
1799
        self.medium = medium
1621
1800
 
1697
1876
        self.root_trans_id = transform.root
1698
1877
 
1699
1878
 
1700
 
class BzrBadParameter(BzrError):
 
1879
class BzrBadParameter(InternalBzrError):
1701
1880
 
1702
1881
    _fmt = "Bad parameter: %(param)r"
1703
1882
 
1704
 
    internal_error = True
1705
 
 
1706
1883
    # This exception should never be thrown, but it is a base class for all
1707
1884
    # parameter-to-function errors.
1708
1885
 
1731
1908
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1732
1909
 
1733
1910
    def __init__(self, from_path='', to_path='', extra=None):
 
1911
        from bzrlib.osutils import splitpath
1734
1912
        BzrError.__init__(self)
1735
1913
        if extra:
1736
1914
            self.extra = ': ' + str(extra)
1740
1918
        has_from = len(from_path) > 0
1741
1919
        has_to = len(to_path) > 0
1742
1920
        if has_from:
1743
 
            self.from_path = osutils.splitpath(from_path)[-1]
 
1921
            self.from_path = splitpath(from_path)[-1]
1744
1922
        else:
1745
1923
            self.from_path = ''
1746
1924
 
1747
1925
        if has_to:
1748
 
            self.to_path = osutils.splitpath(to_path)[-1]
 
1926
            self.to_path = splitpath(to_path)[-1]
1749
1927
        else:
1750
1928
            self.to_path = ''
1751
1929
 
1770
1948
class BzrRemoveChangedFilesError(BzrError):
1771
1949
    """Used when user is trying to remove changed files."""
1772
1950
 
1773
 
    _fmt = ("Can't remove changed or unknown files:\n%(changes_as_text)s"
 
1951
    _fmt = ("Can't safely remove modified or unknown files:\n"
 
1952
        "%(changes_as_text)s"
1774
1953
        "Use --keep to not delete them, or --force to delete them regardless.")
1775
1954
 
1776
1955
    def __init__(self, tree_delta):
1833
2012
 
1834
2013
class BadConversionTarget(BzrError):
1835
2014
 
1836
 
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
 
2015
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
 
2016
            "    %(problem)s"
1837
2017
 
1838
 
    def __init__(self, problem, format):
 
2018
    def __init__(self, problem, format, from_format=None):
1839
2019
        BzrError.__init__(self)
1840
2020
        self.problem = problem
1841
2021
        self.format = format
 
2022
        self.from_format = from_format or '(unspecified)'
 
2023
 
 
2024
 
 
2025
class NoDiffFound(BzrError):
 
2026
 
 
2027
    _fmt = 'Could not find an appropriate Differ for file "%(path)s"'
 
2028
 
 
2029
    def __init__(self, path):
 
2030
        BzrError.__init__(self, path)
 
2031
 
 
2032
 
 
2033
class ExecutableMissing(BzrError):
 
2034
 
 
2035
    _fmt = "%(exe_name)s could not be found on this machine"
 
2036
 
 
2037
    def __init__(self, exe_name):
 
2038
        BzrError.__init__(self, exe_name=exe_name)
1842
2039
 
1843
2040
 
1844
2041
class NoDiff(BzrError):
1854
2051
    _fmt = "Diff3 is not installed on this machine."
1855
2052
 
1856
2053
 
 
2054
class ExistingContent(BzrError):
 
2055
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
 
2056
 
 
2057
    _fmt = "The content being inserted is already present."
 
2058
 
 
2059
 
1857
2060
class ExistingLimbo(BzrError):
1858
2061
 
1859
2062
    _fmt = """This tree contains left-over files from a failed operation.
1860
2063
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1861
2064
    keep, and delete it when you are done."""
1862
 
    
 
2065
 
1863
2066
    def __init__(self, limbo_dir):
1864
2067
       BzrError.__init__(self)
1865
2068
       self.limbo_dir = limbo_dir
1877
2080
 
1878
2081
class ImmortalLimbo(BzrError):
1879
2082
 
1880
 
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
 
2083
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
1881
2084
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1882
2085
    keep, and delete it when you are done."""
1883
2086
 
1888
2091
 
1889
2092
class ImmortalPendingDeletion(BzrError):
1890
2093
 
1891
 
    _fmt = """Unable to delete transform temporary directory
1892
 
    %(pending_deletion)s.  Please examine %(pending_deletions)s to see if it
1893
 
    contains any files you wish to keep, and delete it when you are done."""
 
2094
    _fmt = ("Unable to delete transform temporary directory "
 
2095
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
 
2096
    "contains any files you wish to keep, and delete it when you are done.")
1894
2097
 
1895
2098
    def __init__(self, pending_deletion):
1896
2099
       BzrError.__init__(self, pending_deletion=pending_deletion)
1898
2101
 
1899
2102
class OutOfDateTree(BzrError):
1900
2103
 
1901
 
    _fmt = "Working tree is out of date, please run 'bzr update'."
 
2104
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
1902
2105
 
1903
 
    def __init__(self, tree):
 
2106
    def __init__(self, tree, more=None):
 
2107
        if more is None:
 
2108
            more = ''
 
2109
        else:
 
2110
            more = ' ' + more
1904
2111
        BzrError.__init__(self)
1905
2112
        self.tree = tree
 
2113
        self.more = more
1906
2114
 
1907
2115
 
1908
2116
class PublicBranchOutOfDate(BzrError):
1928
2136
    _fmt = "Format error in conflict listings"
1929
2137
 
1930
2138
 
 
2139
class CorruptDirstate(BzrError):
 
2140
 
 
2141
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
 
2142
            "Error: %(description)s")
 
2143
 
 
2144
    def __init__(self, dirstate_path, description):
 
2145
        BzrError.__init__(self)
 
2146
        self.dirstate_path = dirstate_path
 
2147
        self.description = description
 
2148
 
 
2149
 
1931
2150
class CorruptRepository(BzrError):
1932
2151
 
1933
2152
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1938
2157
        self.repo_path = repo.bzrdir.root_transport.base
1939
2158
 
1940
2159
 
 
2160
class InconsistentDelta(BzrError):
 
2161
    """Used when we get a delta that is not valid."""
 
2162
 
 
2163
    _fmt = ("An inconsistent delta was supplied involving %(path)r,"
 
2164
            " %(file_id)r\nreason: %(reason)s")
 
2165
 
 
2166
    def __init__(self, path, file_id, reason):
 
2167
        BzrError.__init__(self)
 
2168
        self.path = path
 
2169
        self.file_id = file_id
 
2170
        self.reason = reason
 
2171
 
 
2172
 
 
2173
class InconsistentDeltaDelta(InconsistentDelta):
 
2174
    """Used when we get a delta that is not valid."""
 
2175
 
 
2176
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
 
2177
            "\nreason: %(reason)s")
 
2178
 
 
2179
    def __init__(self, delta, reason):
 
2180
        BzrError.__init__(self)
 
2181
        self.delta = delta
 
2182
        self.reason = reason
 
2183
 
 
2184
 
1941
2185
class UpgradeRequired(BzrError):
1942
2186
 
1943
2187
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
1947
2191
        self.path = path
1948
2192
 
1949
2193
 
 
2194
class RepositoryUpgradeRequired(UpgradeRequired):
 
2195
 
 
2196
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
 
2197
 
 
2198
 
 
2199
class RichRootUpgradeRequired(UpgradeRequired):
 
2200
 
 
2201
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
 
2202
           " a format which supports rich roots.")
 
2203
 
 
2204
 
1950
2205
class LocalRequiresBoundBranch(BzrError):
1951
2206
 
1952
2207
    _fmt = "Cannot perform local-only commits on unbound branches."
1953
2208
 
1954
2209
 
1955
 
class MissingProgressBarFinish(BzrError):
1956
 
 
1957
 
    _fmt = "A nested progress bar was not 'finished' correctly."
1958
 
 
1959
 
 
1960
 
class InvalidProgressBarType(BzrError):
1961
 
 
1962
 
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
1963
 
            " is not a supported type Select one of: %(valid_types)s")
1964
 
 
1965
 
    def __init__(self, bar_type, valid_types):
1966
 
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1967
 
 
1968
 
 
1969
2210
class UnsupportedOperation(BzrError):
1970
2211
 
1971
2212
    _fmt = ("The method %(mname)s is not supported on"
1988
2229
 
1989
2230
 
1990
2231
class BinaryFile(BzrError):
1991
 
    
 
2232
 
1992
2233
    _fmt = "File is binary but should be text."
1993
2234
 
1994
2235
 
2014
2255
 
2015
2256
 
2016
2257
class NotABundle(BzrError):
2017
 
    
 
2258
 
2018
2259
    _fmt = "Not a bzr revision-bundle: %(text)r"
2019
2260
 
2020
2261
    def __init__(self, text):
2022
2263
        self.text = text
2023
2264
 
2024
2265
 
2025
 
class BadBundle(BzrError): 
2026
 
    
 
2266
class BadBundle(BzrError):
 
2267
 
2027
2268
    _fmt = "Bad bzr revision-bundle: %(text)r"
2028
2269
 
2029
2270
    def __init__(self, text):
2031
2272
        self.text = text
2032
2273
 
2033
2274
 
2034
 
class MalformedHeader(BadBundle): 
2035
 
    
 
2275
class MalformedHeader(BadBundle):
 
2276
 
2036
2277
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2037
2278
 
2038
2279
 
2039
 
class MalformedPatches(BadBundle): 
2040
 
    
 
2280
class MalformedPatches(BadBundle):
 
2281
 
2041
2282
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2042
2283
 
2043
2284
 
2044
 
class MalformedFooter(BadBundle): 
2045
 
    
 
2285
class MalformedFooter(BadBundle):
 
2286
 
2046
2287
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2047
2288
 
2048
2289
 
2049
2290
class UnsupportedEOLMarker(BadBundle):
2050
 
    
2051
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
 
2291
 
 
2292
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
2052
2293
 
2053
2294
    def __init__(self):
2054
 
        # XXX: BadBundle's constructor assumes there's explanatory text, 
 
2295
        # XXX: BadBundle's constructor assumes there's explanatory text,
2055
2296
        # but for this there is not
2056
2297
        BzrError.__init__(self)
2057
2298
 
2058
2299
 
2059
2300
class IncompatibleBundleFormat(BzrError):
2060
 
    
 
2301
 
2061
2302
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2062
2303
 
2063
2304
    def __init__(self, bundle_format, other):
2067
2308
 
2068
2309
 
2069
2310
class BadInventoryFormat(BzrError):
2070
 
    
 
2311
 
2071
2312
    _fmt = "Root class for inventory serialization errors"
2072
2313
 
2073
2314
 
2084
2325
    _fmt = """This operation requires rich root data storage"""
2085
2326
 
2086
2327
 
2087
 
class NoSmartMedium(BzrError):
 
2328
class NoSmartMedium(InternalBzrError):
2088
2329
 
2089
2330
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
2090
2331
 
2091
 
    internal_error = True
2092
 
 
2093
2332
    def __init__(self, transport):
2094
2333
        self.transport = transport
2095
2334
 
2096
2335
 
2097
 
class NoSmartServer(NotBranchError):
2098
 
 
2099
 
    _fmt = "No smart server available at %(url)s"
2100
 
 
2101
 
    def __init__(self, url):
2102
 
        self.url = url
2103
 
 
2104
 
 
2105
2336
class UnknownSSH(BzrError):
2106
2337
 
2107
2338
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2117
2348
            " Please set BZR_SSH environment variable.")
2118
2349
 
2119
2350
 
 
2351
class GhostRevisionsHaveNoRevno(BzrError):
 
2352
    """When searching for revnos, if we encounter a ghost, we are stuck"""
 
2353
 
 
2354
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
 
2355
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
 
2356
 
 
2357
    def __init__(self, revision_id, ghost_revision_id):
 
2358
        self.revision_id = revision_id
 
2359
        self.ghost_revision_id = ghost_revision_id
 
2360
 
 
2361
 
2120
2362
class GhostRevisionUnusableHere(BzrError):
2121
2363
 
2122
2364
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2126
2368
        self.revision_id = revision_id
2127
2369
 
2128
2370
 
2129
 
class IllegalUseOfScopeReplacer(BzrError):
 
2371
class IllegalUseOfScopeReplacer(InternalBzrError):
2130
2372
 
2131
2373
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2132
2374
            " %(msg)s%(extra)s")
2133
2375
 
2134
 
    internal_error = True
2135
 
 
2136
2376
    def __init__(self, name, msg, extra=None):
2137
2377
        BzrError.__init__(self)
2138
2378
        self.name = name
2143
2383
            self.extra = ''
2144
2384
 
2145
2385
 
2146
 
class InvalidImportLine(BzrError):
 
2386
class InvalidImportLine(InternalBzrError):
2147
2387
 
2148
2388
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
2149
2389
 
2150
 
    internal_error = True
2151
 
 
2152
2390
    def __init__(self, text, msg):
2153
2391
        BzrError.__init__(self)
2154
2392
        self.text = text
2155
2393
        self.msg = msg
2156
2394
 
2157
2395
 
2158
 
class ImportNameCollision(BzrError):
 
2396
class ImportNameCollision(InternalBzrError):
2159
2397
 
2160
2398
    _fmt = ("Tried to import an object to the same name as"
2161
2399
            " an existing object. %(name)s")
2162
2400
 
2163
 
    internal_error = True
2164
 
 
2165
2401
    def __init__(self, name):
2166
2402
        BzrError.__init__(self)
2167
2403
        self.name = name
2199
2435
class PatchMissing(BzrError):
2200
2436
    """Raise a patch type was specified but no patch supplied"""
2201
2437
 
2202
 
    _fmt = "patch_type was %(patch_type)s, but no patch was supplied."
 
2438
    _fmt = "Patch_type was %(patch_type)s, but no patch was supplied."
2203
2439
 
2204
2440
    def __init__(self, patch_type):
2205
2441
        BzrError.__init__(self)
2206
2442
        self.patch_type = patch_type
2207
2443
 
2208
2444
 
 
2445
class TargetNotBranch(BzrError):
 
2446
    """A merge directive's target branch is required, but isn't a branch"""
 
2447
 
 
2448
    _fmt = ("Your branch does not have all of the revisions required in "
 
2449
            "order to merge this merge directive and the target "
 
2450
            "location specified in the merge directive is not a branch: "
 
2451
            "%(location)s.")
 
2452
 
 
2453
    def __init__(self, location):
 
2454
        BzrError.__init__(self)
 
2455
        self.location = location
 
2456
 
 
2457
 
2209
2458
class UnsupportedInventoryKind(BzrError):
2210
 
    
 
2459
 
2211
2460
    _fmt = """Unsupported entry kind %(kind)s"""
2212
2461
 
2213
2462
    def __init__(self, kind):
2225
2474
 
2226
2475
 
2227
2476
class SubsumeTargetNeedsUpgrade(BzrError):
2228
 
    
 
2477
 
2229
2478
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2230
2479
 
2231
2480
    def __init__(self, other_tree):
2232
2481
        self.other_tree = other_tree
2233
2482
 
2234
2483
 
2235
 
class BadReferenceTarget(BzrError):
 
2484
class BadReferenceTarget(InternalBzrError):
2236
2485
 
2237
2486
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
2238
2487
           "%(reason)s"
2239
2488
 
2240
 
    internal_error = True
2241
 
 
2242
2489
    def __init__(self, tree, other_tree, reason):
2243
2490
        self.tree = tree
2244
2491
        self.other_tree = other_tree
2256
2503
class TagsNotSupported(BzrError):
2257
2504
 
2258
2505
    _fmt = ("Tags not supported by %(branch)s;"
2259
 
            " you may be able to use bzr upgrade --dirstate-tags.")
 
2506
            " you may be able to use bzr upgrade.")
2260
2507
 
2261
2508
    def __init__(self, branch):
2262
2509
        self.branch = branch
2263
2510
 
2264
 
        
 
2511
 
2265
2512
class TagAlreadyExists(BzrError):
2266
2513
 
2267
2514
    _fmt = "Tag %(tag_name)s already exists."
2272
2519
 
2273
2520
class MalformedBugIdentifier(BzrError):
2274
2521
 
2275
 
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2522
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
2523
            'See "bzr help bugs" for more information on this feature.')
2276
2524
 
2277
2525
    def __init__(self, bug_id, reason):
2278
2526
        self.bug_id = bug_id
2279
2527
        self.reason = reason
2280
2528
 
2281
2529
 
 
2530
class InvalidBugTrackerURL(BzrError):
 
2531
 
 
2532
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
 
2533
            "contain {id}: %(url)s")
 
2534
 
 
2535
    def __init__(self, abbreviation, url):
 
2536
        self.abbreviation = abbreviation
 
2537
        self.url = url
 
2538
 
 
2539
 
2282
2540
class UnknownBugTrackerAbbreviation(BzrError):
2283
2541
 
2284
2542
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
2289
2547
        self.branch = branch
2290
2548
 
2291
2549
 
 
2550
class InvalidLineInBugsProperty(BzrError):
 
2551
 
 
2552
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
2553
 
 
2554
    def __init__(self, line):
 
2555
        self.line = line
 
2556
 
 
2557
 
 
2558
class InvalidBugStatus(BzrError):
 
2559
 
 
2560
    _fmt = ("Invalid bug status: '%(status)s'")
 
2561
 
 
2562
    def __init__(self, status):
 
2563
        self.status = status
 
2564
 
 
2565
 
2292
2566
class UnexpectedSmartServerResponse(BzrError):
2293
2567
 
2294
2568
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2297
2571
        self.response_tuple = response_tuple
2298
2572
 
2299
2573
 
 
2574
class ErrorFromSmartServer(BzrError):
 
2575
    """An error was received from a smart server.
 
2576
 
 
2577
    :seealso: UnknownErrorFromSmartServer
 
2578
    """
 
2579
 
 
2580
    _fmt = "Error received from smart server: %(error_tuple)r"
 
2581
 
 
2582
    internal_error = True
 
2583
 
 
2584
    def __init__(self, error_tuple):
 
2585
        self.error_tuple = error_tuple
 
2586
        try:
 
2587
            self.error_verb = error_tuple[0]
 
2588
        except IndexError:
 
2589
            self.error_verb = None
 
2590
        self.error_args = error_tuple[1:]
 
2591
 
 
2592
 
 
2593
class UnknownErrorFromSmartServer(BzrError):
 
2594
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
 
2595
    error.
 
2596
 
 
2597
    This is distinct from ErrorFromSmartServer so that it is possible to
 
2598
    distinguish between the following two cases:
 
2599
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2600
        and so should provoke a traceback to the user.
 
2601
      - ErrorFromSmartServer was caught but its error_tuple could not be
 
2602
        translated.  This is probably because the server sent us garbage, and
 
2603
        should not provoke a traceback.
 
2604
    """
 
2605
 
 
2606
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
 
2607
 
 
2608
    internal_error = False
 
2609
 
 
2610
    def __init__(self, error_from_smart_server):
 
2611
        """Constructor.
 
2612
 
 
2613
        :param error_from_smart_server: An ErrorFromSmartServer instance.
 
2614
        """
 
2615
        self.error_from_smart_server = error_from_smart_server
 
2616
        self.error_tuple = error_from_smart_server.error_tuple
 
2617
 
 
2618
 
2300
2619
class ContainerError(BzrError):
2301
2620
    """Base class of container errors."""
2302
2621
 
2304
2623
class UnknownContainerFormatError(ContainerError):
2305
2624
 
2306
2625
    _fmt = "Unrecognised container format: %(container_format)r"
2307
 
    
 
2626
 
2308
2627
    def __init__(self, container_format):
2309
2628
        self.container_format = container_format
2310
2629
 
2313
2632
 
2314
2633
    _fmt = "Unexpected end of container stream"
2315
2634
 
2316
 
    internal_error = False
2317
 
 
2318
2635
 
2319
2636
class UnknownRecordTypeError(ContainerError):
2320
2637
 
2348
2665
        self.name = name
2349
2666
 
2350
2667
 
2351
 
class NoDestinationAddress(BzrError):
 
2668
class NoDestinationAddress(InternalBzrError):
2352
2669
 
2353
2670
    _fmt = "Message does not have a destination address."
2354
2671
 
2355
 
    internal_error = True
 
2672
 
 
2673
class RepositoryDataStreamError(BzrError):
 
2674
 
 
2675
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
 
2676
 
 
2677
    def __init__(self, reason):
 
2678
        self.reason = reason
2356
2679
 
2357
2680
 
2358
2681
class SMTPError(BzrError):
2368
2691
    _fmt = "No message supplied."
2369
2692
 
2370
2693
 
 
2694
class NoMailAddressSpecified(BzrError):
 
2695
 
 
2696
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
 
2697
 
 
2698
 
2371
2699
class UnknownMailClient(BzrError):
2372
2700
 
2373
2701
    _fmt = "Unknown mail client: %(mail_client)s"
2398
2726
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2399
2727
 
2400
2728
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
 
2729
 
 
2730
 
 
2731
class BzrDirError(BzrError):
 
2732
 
 
2733
    def __init__(self, bzrdir):
 
2734
        import bzrlib.urlutils as urlutils
 
2735
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2736
                                                    'ascii')
 
2737
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
 
2738
 
 
2739
 
 
2740
class UnsyncedBranches(BzrDirError):
 
2741
 
 
2742
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
 
2743
            " bzr help sync-for-reconfigure.")
 
2744
 
 
2745
    def __init__(self, bzrdir, target_branch):
 
2746
        BzrDirError.__init__(self, bzrdir)
 
2747
        import bzrlib.urlutils as urlutils
 
2748
        self.target_url = urlutils.unescape_for_display(target_branch.base,
 
2749
                                                        'ascii')
 
2750
 
 
2751
 
 
2752
class AlreadyBranch(BzrDirError):
 
2753
 
 
2754
    _fmt = "'%(display_url)s' is already a branch."
 
2755
 
 
2756
 
 
2757
class AlreadyTree(BzrDirError):
 
2758
 
 
2759
    _fmt = "'%(display_url)s' is already a tree."
 
2760
 
 
2761
 
 
2762
class AlreadyCheckout(BzrDirError):
 
2763
 
 
2764
    _fmt = "'%(display_url)s' is already a checkout."
 
2765
 
 
2766
 
 
2767
class AlreadyLightweightCheckout(BzrDirError):
 
2768
 
 
2769
    _fmt = "'%(display_url)s' is already a lightweight checkout."
 
2770
 
 
2771
 
 
2772
class AlreadyUsingShared(BzrDirError):
 
2773
 
 
2774
    _fmt = "'%(display_url)s' is already using a shared repository."
 
2775
 
 
2776
 
 
2777
class AlreadyStandalone(BzrDirError):
 
2778
 
 
2779
    _fmt = "'%(display_url)s' is already standalone."
 
2780
 
 
2781
 
 
2782
class AlreadyWithTrees(BzrDirError):
 
2783
 
 
2784
    _fmt = ("Shared repository '%(display_url)s' already creates "
 
2785
            "working trees.")
 
2786
 
 
2787
 
 
2788
class AlreadyWithNoTrees(BzrDirError):
 
2789
 
 
2790
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
 
2791
            "working trees.")
 
2792
 
 
2793
 
 
2794
class ReconfigurationNotSupported(BzrDirError):
 
2795
 
 
2796
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
 
2797
 
 
2798
 
 
2799
class NoBindLocation(BzrDirError):
 
2800
 
 
2801
    _fmt = "No location could be found to bind to at %(display_url)s."
 
2802
 
 
2803
 
 
2804
class UncommittedChanges(BzrError):
 
2805
 
 
2806
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
 
2807
            ' (See bzr status).%(more)s')
 
2808
 
 
2809
    def __init__(self, tree, more=None):
 
2810
        if more is None:
 
2811
            more = ''
 
2812
        else:
 
2813
            more = ' ' + more
 
2814
        import bzrlib.urlutils as urlutils
 
2815
        display_url = urlutils.unescape_for_display(
 
2816
            tree.bzrdir.root_transport.base, 'ascii')
 
2817
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
 
2818
 
 
2819
 
 
2820
class MissingTemplateVariable(BzrError):
 
2821
 
 
2822
    _fmt = 'Variable {%(name)s} is not available.'
 
2823
 
 
2824
    def __init__(self, name):
 
2825
        self.name = name
 
2826
 
 
2827
 
 
2828
class NoTemplate(BzrError):
 
2829
 
 
2830
    _fmt = 'No template specified.'
 
2831
 
 
2832
 
 
2833
class UnableCreateSymlink(BzrError):
 
2834
 
 
2835
    _fmt = 'Unable to create symlink %(path_str)son this platform'
 
2836
 
 
2837
    def __init__(self, path=None):
 
2838
        path_str = ''
 
2839
        if path:
 
2840
            try:
 
2841
                path_str = repr(str(path))
 
2842
            except UnicodeEncodeError:
 
2843
                path_str = repr(path)
 
2844
            path_str += ' '
 
2845
        self.path_str = path_str
 
2846
 
 
2847
 
 
2848
class UnsupportedTimezoneFormat(BzrError):
 
2849
 
 
2850
    _fmt = ('Unsupported timezone format "%(timezone)s", '
 
2851
            'options are "utc", "original", "local".')
 
2852
 
 
2853
    def __init__(self, timezone):
 
2854
        self.timezone = timezone
 
2855
 
 
2856
 
 
2857
class CommandAvailableInPlugin(StandardError):
 
2858
 
 
2859
    internal_error = False
 
2860
 
 
2861
    def __init__(self, cmd_name, plugin_metadata, provider):
 
2862
 
 
2863
        self.plugin_metadata = plugin_metadata
 
2864
        self.cmd_name = cmd_name
 
2865
        self.provider = provider
 
2866
 
 
2867
    def __str__(self):
 
2868
 
 
2869
        _fmt = ('"%s" is not a standard bzr command. \n'
 
2870
                'However, the following official plugin provides this command: %s\n'
 
2871
                'You can install it by going to: %s'
 
2872
                % (self.cmd_name, self.plugin_metadata['name'],
 
2873
                    self.plugin_metadata['url']))
 
2874
 
 
2875
        return _fmt
 
2876
 
 
2877
 
 
2878
class NoPluginAvailable(BzrError):
 
2879
    pass
 
2880
 
 
2881
 
 
2882
class UnableEncodePath(BzrError):
 
2883
 
 
2884
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
 
2885
            'user encoding %(user_encoding)s')
 
2886
 
 
2887
    def __init__(self, path, kind):
 
2888
        from bzrlib.osutils import get_user_encoding
 
2889
        self.path = path
 
2890
        self.kind = kind
 
2891
        self.user_encoding = osutils.get_user_encoding()
 
2892
 
 
2893
 
 
2894
class NoSuchAlias(BzrError):
 
2895
 
 
2896
    _fmt = ('The alias "%(alias_name)s" does not exist.')
 
2897
 
 
2898
    def __init__(self, alias_name):
 
2899
        BzrError.__init__(self, alias_name=alias_name)
 
2900
 
 
2901
 
 
2902
class DirectoryLookupFailure(BzrError):
 
2903
    """Base type for lookup errors."""
 
2904
 
 
2905
    pass
 
2906
 
 
2907
 
 
2908
class InvalidLocationAlias(DirectoryLookupFailure):
 
2909
 
 
2910
    _fmt = '"%(alias_name)s" is not a valid location alias.'
 
2911
 
 
2912
    def __init__(self, alias_name):
 
2913
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
 
2914
 
 
2915
 
 
2916
class UnsetLocationAlias(DirectoryLookupFailure):
 
2917
 
 
2918
    _fmt = 'No %(alias_name)s location assigned.'
 
2919
 
 
2920
    def __init__(self, alias_name):
 
2921
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
 
2922
 
 
2923
 
 
2924
class CannotBindAddress(BzrError):
 
2925
 
 
2926
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
 
2927
 
 
2928
    def __init__(self, host, port, orig_error):
 
2929
        # nb: in python2.4 socket.error doesn't have a useful repr
 
2930
        BzrError.__init__(self, host=host, port=port,
 
2931
            orig_error=repr(orig_error.args))
 
2932
 
 
2933
 
 
2934
class UnknownRules(BzrError):
 
2935
 
 
2936
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
 
2937
 
 
2938
    def __init__(self, unknowns):
 
2939
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
 
2940
 
 
2941
 
 
2942
class HookFailed(BzrError):
 
2943
    """Raised when a pre_change_branch_tip hook function fails anything other
 
2944
    than TipChangeRejected.
 
2945
    """
 
2946
 
 
2947
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
 
2948
            "%(traceback_text)s%(exc_value)s")
 
2949
 
 
2950
    def __init__(self, hook_stage, hook_name, exc_info):
 
2951
        import traceback
 
2952
        self.hook_stage = hook_stage
 
2953
        self.hook_name = hook_name
 
2954
        self.exc_info = exc_info
 
2955
        self.exc_type = exc_info[0]
 
2956
        self.exc_value = exc_info[1]
 
2957
        self.exc_tb = exc_info[2]
 
2958
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
 
2959
 
 
2960
 
 
2961
class TipChangeRejected(BzrError):
 
2962
    """A pre_change_branch_tip hook function may raise this to cleanly and
 
2963
    explicitly abort a change to a branch tip.
 
2964
    """
 
2965
 
 
2966
    _fmt = u"Tip change rejected: %(msg)s"
 
2967
 
 
2968
    def __init__(self, msg):
 
2969
        self.msg = msg
 
2970
 
 
2971
 
 
2972
class ShelfCorrupt(BzrError):
 
2973
 
 
2974
    _fmt = "Shelf corrupt."
 
2975
 
 
2976
 
 
2977
class NoSuchShelfId(BzrError):
 
2978
 
 
2979
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
 
2980
 
 
2981
    def __init__(self, shelf_id):
 
2982
        BzrError.__init__(self, shelf_id=shelf_id)
 
2983
 
 
2984
 
 
2985
class InvalidShelfId(BzrError):
 
2986
 
 
2987
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
 
2988
 
 
2989
    def __init__(self, invalid_id):
 
2990
        BzrError.__init__(self, invalid_id=invalid_id)
 
2991
 
 
2992
 
 
2993
class JailBreak(BzrError):
 
2994
 
 
2995
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
 
2996
 
 
2997
    def __init__(self, url):
 
2998
        BzrError.__init__(self, url=url)
 
2999
 
 
3000
 
 
3001
class UserAbort(BzrError):
 
3002
 
 
3003
    _fmt = 'The user aborted the operation.'
 
3004
 
 
3005
 
 
3006
class MustHaveWorkingTree(BzrError):
 
3007
 
 
3008
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
 
3009
 
 
3010
    def __init__(self, format, url):
 
3011
        BzrError.__init__(self, format=format, url=url)
 
3012
 
 
3013
 
 
3014
class NoSuchView(BzrError):
 
3015
    """A view does not exist.
 
3016
    """
 
3017
 
 
3018
    _fmt = u"No such view: %(view_name)s."
 
3019
 
 
3020
    def __init__(self, view_name):
 
3021
        self.view_name = view_name
 
3022
 
 
3023
 
 
3024
class ViewsNotSupported(BzrError):
 
3025
    """Views are not supported by a tree format.
 
3026
    """
 
3027
 
 
3028
    _fmt = ("Views are not supported by %(tree)s;"
 
3029
            " use 'bzr upgrade' to change your tree to a later format.")
 
3030
 
 
3031
    def __init__(self, tree):
 
3032
        self.tree = tree
 
3033
 
 
3034
 
 
3035
class FileOutsideView(BzrError):
 
3036
 
 
3037
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
3038
            '%(view_str)s')
 
3039
 
 
3040
    def __init__(self, file_name, view_files):
 
3041
        self.file_name = file_name
 
3042
        self.view_str = ", ".join(view_files)
 
3043
 
 
3044
 
 
3045
class UnresumableWriteGroup(BzrError):
 
3046
 
 
3047
    _fmt = ("Repository %(repository)s cannot resume write group "
 
3048
            "%(write_groups)r: %(reason)s")
 
3049
 
 
3050
    internal_error = True
 
3051
 
 
3052
    def __init__(self, repository, write_groups, reason):
 
3053
        self.repository = repository
 
3054
        self.write_groups = write_groups
 
3055
        self.reason = reason
 
3056
 
 
3057
 
 
3058
class UnsuspendableWriteGroup(BzrError):
 
3059
 
 
3060
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
 
3061
 
 
3062
    internal_error = True
 
3063
 
 
3064
    def __init__(self, repository):
 
3065
        self.repository = repository
 
3066
 
 
3067
 
 
3068
class LossyPushToSameVCS(BzrError):
 
3069
 
 
3070
    _fmt = ("Lossy push not possible between %(source_branch)r and "
 
3071
            "%(target_branch)r that are in the same VCS.")
 
3072
 
 
3073
    internal_error = True
 
3074
 
 
3075
    def __init__(self, source_branch, target_branch):
 
3076
        self.source_branch = source_branch
 
3077
        self.target_branch = target_branch