/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 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
18
18
"""
19
19
 
20
20
 
21
 
from bzrlib import symbol_versioning
22
 
from bzrlib.patches import (PatchSyntax, 
23
 
                            PatchConflict, 
24
 
                            MalformedPatchHeader,
25
 
                            MalformedHunkHeader,
26
 
                            MalformedLine,)
 
21
from bzrlib import (
 
22
    osutils,
 
23
    symbol_versioning,
 
24
    )
 
25
from bzrlib.patches import (
 
26
    MalformedHunkHeader,
 
27
    MalformedLine,
 
28
    MalformedPatchHeader,
 
29
    PatchConflict,
 
30
    PatchSyntax,
 
31
    )
27
32
 
28
33
 
29
34
# TODO: is there any value in providing the .args field used by standard
97
102
                    return s.encode('utf8')
98
103
                return s
99
104
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
100
 
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
 
105
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
101
106
                % (self.__class__.__name__,
102
107
                   self.__dict__,
103
108
                   getattr(self, '_fmt', None),
104
 
                   str(e))
 
109
                   e)
105
110
 
106
111
    def _get_format_string(self):
107
112
        """Return format string for this exception or None"""
127
132
    # readable explanation
128
133
 
129
134
    def __init__(self, *args, **kwds):
130
 
        # XXX: Use the underlying BzrError to always generate the args attribute
131
 
        # if it doesn't exist.  We can't use super here, because exceptions are
132
 
        # old-style classes in python2.4 (but new in 2.5).  --bmc, 20060426
 
135
        # XXX: Use the underlying BzrError to always generate the args
 
136
        # attribute if it doesn't exist.  We can't use super here, because
 
137
        # exceptions are old-style classes in python2.4 (but new in 2.5).
 
138
        # --bmc, 20060426
133
139
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
134
 
             'please convert %s to use BzrError instead' 
 
140
             'please convert %s to use BzrError instead'
135
141
             % self.__class__.__name__,
136
142
             DeprecationWarning,
137
143
             stacklevel=2)
148
154
                return s.encode('utf8')
149
155
            return s
150
156
        except (TypeError, NameError, ValueError, KeyError), e:
151
 
            return 'Unprintable exception %s(%r): %s' \
 
157
            return 'Unprintable exception %s(%r): %r' \
152
158
                % (self.__class__.__name__,
153
 
                   self.__dict__, str(e))
 
159
                   self.__dict__, e)
154
160
 
155
161
 
156
162
class AlreadyBuilding(BzrError):
169
175
        self.message = message
170
176
 
171
177
 
 
178
class DisabledMethod(BzrError):
 
179
 
 
180
    _fmt = "The smart server method '%(class_name)s' is disabled."
 
181
 
 
182
    internal_error = True
 
183
 
 
184
    def __init__(self, class_name):
 
185
        BzrError.__init__(self)
 
186
        self.class_name = class_name
 
187
 
 
188
 
172
189
class InvalidEntryName(BzrError):
173
190
    
174
191
    _fmt = "Invalid entry name: %(name)s"
199
216
        self.revision_id = revision_id
200
217
        self.branch = branch
201
218
 
 
219
class ReservedId(BzrError):
 
220
 
 
221
    _fmt = "Reserved revision-id {%(revision_id)s}"
 
222
 
 
223
    def __init__(self, revision_id):
 
224
        self.revision_id = revision_id
 
225
 
 
226
 
 
227
class NoHelpTopic(BzrError):
 
228
 
 
229
    _fmt = ("No help could be found for '%(topic)s'. "
 
230
        "Please use 'bzr help topics' to obtain a list of topics.")
 
231
 
 
232
    def __init__(self, topic):
 
233
        self.topic = topic
 
234
 
202
235
 
203
236
class NoSuchId(BzrError):
204
237
 
212
245
 
213
246
class InventoryModified(BzrError):
214
247
 
215
 
    _fmt = ("The current inventory for the tree %(tree)r has been modified, "
216
 
            "so a clean inventory cannot be read without data loss.")
 
248
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
 
249
            " so a clean inventory cannot be read without data loss.")
217
250
 
218
251
    internal_error = True
219
252
 
288
321
 
289
322
    _fmt = "Error in command line options"
290
323
 
 
324
 
 
325
class BadOptionValue(BzrError):
 
326
 
 
327
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
328
 
 
329
    def __init__(self, name, value):
 
330
        BzrError.__init__(self, name=name, value=value)
 
331
 
291
332
    
292
333
class StrictCommitFailed(BzrError):
293
334
 
319
360
    _fmt = "File exists: %(path)r%(extra)s"
320
361
 
321
362
 
 
363
class RenameFailedFilesExist(BzrError):
 
364
    """Used when renaming and both source and dest exist."""
 
365
 
 
366
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
 
367
            "%(extra)s")
 
368
 
 
369
    def __init__(self, source, dest, extra=None):
 
370
        BzrError.__init__(self)
 
371
        self.source = str(source)
 
372
        self.dest = str(dest)
 
373
        if extra:
 
374
            self.extra = ' ' + str(extra)
 
375
        else:
 
376
            self.extra = ''
 
377
 
 
378
 
 
379
class NotADirectory(PathError):
 
380
 
 
381
    _fmt = "%(path)r is not a directory %(extra)s"
 
382
 
 
383
 
 
384
class NotInWorkingDirectory(PathError):
 
385
 
 
386
    _fmt = "%(path)r is not in the working directory %(extra)s"
 
387
 
 
388
 
322
389
class DirectoryNotEmpty(PathError):
323
390
 
324
391
    _fmt = "Directory not empty: %(path)r%(extra)s"
360
427
        self.args = [base] + list(args)
361
428
 
362
429
 
 
430
class UnknownHook(BzrError):
 
431
 
 
432
    _fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
 
433
 
 
434
    def __init__(self, hook_type, hook_name):
 
435
        BzrError.__init__(self)
 
436
        self.type = hook_type
 
437
        self.hook = hook_name
 
438
 
 
439
 
363
440
class UnsupportedProtocol(PathError):
364
441
 
365
442
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
370
447
 
371
448
class ShortReadvError(PathError):
372
449
 
373
 
    _fmt = "readv() read %(actual)s bytes rather than %(length)s bytes at %(offset)s for %(path)s%(extra)s"
 
450
    _fmt = ("readv() read %(actual)s bytes rather than %(length)s bytes"
 
451
            " at %(offset)s for %(path)s%(extra)s")
374
452
 
375
453
    internal_error = True
376
454
 
414
492
       self.path = urlutils.unescape_for_display(path, 'ascii')
415
493
 
416
494
 
 
495
class NoSubmitBranch(PathError):
 
496
 
 
497
    _fmt = 'No submit branch available for branch "%(path)s"'
 
498
 
 
499
    def __init__(self, branch):
 
500
       import bzrlib.urlutils as urlutils
 
501
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
 
502
 
 
503
 
417
504
class AlreadyBranchError(PathError):
418
505
 
419
506
    _fmt = "Already a branch: %(path)s."
427
514
 
428
515
class AtomicFileAlreadyClosed(PathError):
429
516
 
430
 
    _fmt = "'%(function)s' called on an AtomicFile after it was closed: %(path)s"
 
517
    _fmt = ("'%(function)s' called on an AtomicFile after it was closed:"
 
518
            " %(path)s")
431
519
 
432
520
    def __init__(self, path, function):
433
521
        PathError.__init__(self, path=path, extra=None)
436
524
 
437
525
class InaccessibleParent(PathError):
438
526
 
439
 
    _fmt = "Parent not accessible given base %(base)s and relative path %(path)s"
 
527
    _fmt = ("Parent not accessible given base %(base)s and"
 
528
            " relative path %(path)s")
440
529
 
441
530
    def __init__(self, path, base):
442
531
        PathError.__init__(self, path)
463
552
 
464
553
 
465
554
class UnsupportedFormatError(BzrError):
466
 
    
467
 
    _fmt = "Unsupported branch format: %(format)s"
 
555
 
 
556
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
468
557
 
469
558
 
470
559
class UnknownFormatError(BzrError):
482
571
        self.bzrdir = bzrdir_format
483
572
 
484
573
 
 
574
class IncompatibleRepositories(BzrError):
 
575
 
 
576
    _fmt = "Repository %(target)s is not compatible with repository"\
 
577
        " %(source)s"
 
578
 
 
579
    def __init__(self, source, target):
 
580
        BzrError.__init__(self, target=target, source=source)
 
581
 
 
582
 
485
583
class IncompatibleRevision(BzrError):
486
584
    
487
585
    _fmt = "Revision is not compatible with %(repo_format)s"
491
589
        self.repo_format = repo_format
492
590
 
493
591
 
 
592
class AlreadyVersionedError(BzrError):
 
593
    """Used when a path is expected not to be versioned, but it is."""
 
594
 
 
595
    _fmt = "%(context_info)s%(path)s is already versioned"
 
596
 
 
597
    def __init__(self, path, context_info=None):
 
598
        """Construct a new AlreadyVersionedError.
 
599
 
 
600
        :param path: This is the path which is versioned,
 
601
        which should be in a user friendly form.
 
602
        :param context_info: If given, this is information about the context,
 
603
        which could explain why this is expected to not be versioned.
 
604
        """
 
605
        BzrError.__init__(self)
 
606
        self.path = path
 
607
        if context_info is None:
 
608
            self.context_info = ''
 
609
        else:
 
610
            self.context_info = context_info + ". "
 
611
 
 
612
 
494
613
class NotVersionedError(BzrError):
495
 
 
496
 
    _fmt = "%(path)s is not versioned"
497
 
 
498
 
    def __init__(self, path):
 
614
    """Used when a path is expected to be versioned, but it is not."""
 
615
 
 
616
    _fmt = "%(context_info)s%(path)s is not versioned"
 
617
 
 
618
    def __init__(self, path, context_info=None):
 
619
        """Construct a new NotVersionedError.
 
620
 
 
621
        :param path: This is the path which is not versioned,
 
622
        which should be in a user friendly form.
 
623
        :param context_info: If given, this is information about the context,
 
624
        which could explain why this is expected to be versioned.
 
625
        """
499
626
        BzrError.__init__(self)
500
627
        self.path = path
 
628
        if context_info is None:
 
629
            self.context_info = ''
 
630
        else:
 
631
            self.context_info = context_info + ". "
501
632
 
502
633
 
503
634
class PathsNotVersionedError(BzrError):
504
 
    # used when reporting several paths are not versioned
 
635
    """Used when reporting several paths which are not versioned"""
505
636
 
506
637
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
507
638
 
514
645
 
515
646
class PathsDoNotExist(BzrError):
516
647
 
517
 
    _fmt = "Path(s) do not exist: %(paths_as_string)s"
 
648
    _fmt = "Path(s) do not exist: %(paths_as_string)s%(extra)s"
518
649
 
519
650
    # used when reporting that paths are neither versioned nor in the working
520
651
    # tree
521
652
 
522
 
    def __init__(self, paths):
 
653
    def __init__(self, paths, extra=None):
523
654
        # circular import
524
655
        from bzrlib.osutils import quotefn
525
656
        BzrError.__init__(self)
526
657
        self.paths = paths
527
658
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
 
659
        if extra:
 
660
            self.extra = ': ' + str(extra)
 
661
        else:
 
662
            self.extra = ''
528
663
 
529
664
 
530
665
class BadFileKindError(BzrError):
531
666
 
532
 
    _fmt = "Cannot operate on %(filename)s of unsupported kind %(kind)s"
 
667
    _fmt = 'Cannot operate on "%(filename)s" of unsupported kind "%(kind)s"'
 
668
 
 
669
    def __init__(self, filename, kind):
 
670
        BzrError.__init__(self, filename=filename, kind=kind)
533
671
 
534
672
 
535
673
class ForbiddenControlFileError(BzrError):
539
677
 
540
678
class LockError(BzrError):
541
679
 
542
 
    _fmt = "Lock error: %(message)s"
 
680
    _fmt = "Lock error: %(msg)s"
 
681
 
 
682
    internal_error = True
543
683
 
544
684
    # All exceptions from the lock/unlock functions should be from
545
685
    # this exception class.  They will be translated as necessary. The
547
687
    #
548
688
    # New code should prefer to raise specific subclasses
549
689
    def __init__(self, message):
550
 
        self.message = message
 
690
        # Python 2.5 uses a slot for StandardError.message,
 
691
        # so use a different variable name
 
692
        # so it is exposed in self.__dict__
 
693
        self.msg = message
 
694
 
 
695
 
 
696
class LockActive(LockError):
 
697
 
 
698
    _fmt = "The lock for '%(lock_description)s' is in use and cannot be broken."
 
699
 
 
700
    internal_error = False
 
701
 
 
702
    def __init__(self, lock_description):
 
703
        self.lock_description = lock_description
551
704
 
552
705
 
553
706
class CommitNotPossible(LockError):
570
723
 
571
724
    _fmt = "A write attempt was made in a read only transaction on %(obj)s"
572
725
 
 
726
    # TODO: There should also be an error indicating that you need a write
 
727
    # lock and don't have any lock at all... mbp 20070226
 
728
 
573
729
    def __init__(self, obj):
574
730
        self.obj = obj
575
731
 
576
732
 
 
733
class ReadOnlyLockError(LockError):
 
734
 
 
735
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
 
736
 
 
737
    def __init__(self, fname, msg):
 
738
        LockError.__init__(self, '')
 
739
        self.fname = fname
 
740
        self.msg = msg
 
741
 
 
742
 
577
743
class OutSideTransaction(BzrError):
578
744
 
579
 
    _fmt = "A transaction related operation was attempted after the transaction finished."
 
745
    _fmt = ("A transaction related operation was attempted after"
 
746
            " the transaction finished.")
580
747
 
581
748
 
582
749
class ObjectNotLocked(LockError):
583
750
 
584
751
    _fmt = "%(obj)r is not locked"
585
752
 
586
 
    internal_error = True
587
 
 
588
753
    # this can indicate that any particular object is not locked; see also
589
754
    # LockNotHeld which means that a particular *lock* object is not held by
590
755
    # the caller -- perhaps they should be unified.
611
776
class LockContention(LockError):
612
777
 
613
778
    _fmt = "Could not acquire lock %(lock)s"
614
 
    # TODO: show full url for lock, combining the transport and relative bits?
615
 
    
 
779
    # TODO: show full url for lock, combining the transport and relative
 
780
    # bits?
 
781
 
 
782
    internal_error = False
 
783
 
616
784
    def __init__(self, lock):
617
785
        self.lock = lock
618
786
 
619
787
 
620
788
class LockBroken(LockError):
621
789
 
622
 
    _fmt = "Lock was broken while still open: %(lock)s - check storage consistency!"
 
790
    _fmt = ("Lock was broken while still open: %(lock)s"
 
791
            " - check storage consistency!")
 
792
 
 
793
    internal_error = False
623
794
 
624
795
    def __init__(self, lock):
625
796
        self.lock = lock
627
798
 
628
799
class LockBreakMismatch(LockError):
629
800
 
630
 
    _fmt = "Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"
 
801
    _fmt = ("Lock was released and re-acquired before being broken:"
 
802
            " %(lock)s: held by %(holder)r, wanted to break %(target)r")
 
803
 
 
804
    internal_error = False
631
805
 
632
806
    def __init__(self, lock, holder, target):
633
807
        self.lock = lock
639
813
 
640
814
    _fmt = "Lock not held: %(lock)s"
641
815
 
 
816
    internal_error = False
 
817
 
642
818
    def __init__(self, lock):
643
819
        self.lock = lock
644
820
 
645
821
 
 
822
class TokenLockingNotSupported(LockError):
 
823
 
 
824
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
 
825
 
 
826
    internal_error = True
 
827
 
 
828
    def __init__(self, obj):
 
829
        self.obj = obj
 
830
 
 
831
 
 
832
class TokenMismatch(LockBroken):
 
833
 
 
834
    _fmt = "The lock token %(given_token)r does not match lock token %(lock_token)r."
 
835
 
 
836
    internal_error = True
 
837
 
 
838
    def __init__(self, given_token, lock_token):
 
839
        self.given_token = given_token
 
840
        self.lock_token = lock_token
 
841
 
 
842
 
646
843
class PointlessCommit(BzrError):
647
844
 
648
845
    _fmt = "No changes to commit"
677
874
        BzrError.__init__(self, branch=branch, revision=revision)
678
875
 
679
876
 
 
877
class NotLeftParentDescendant(BzrError):
 
878
 
 
879
    _fmt = ("Revision %(old_revision)s is not the left parent of"
 
880
            " %(new_revision)s, but branch %(branch_location)s expects this")
 
881
 
 
882
    internal_error = True
 
883
 
 
884
    def __init__(self, branch, old_revision, new_revision):
 
885
        BzrError.__init__(self, branch_location=branch.base,
 
886
                          old_revision=old_revision,
 
887
                          new_revision=new_revision)
 
888
 
 
889
 
680
890
class NoSuchRevisionSpec(BzrError):
681
891
 
682
892
    _fmt = "No namespace registered for string: %(spec)r"
685
895
        BzrError.__init__(self, spec=spec)
686
896
 
687
897
 
 
898
class NoSuchRevisionInTree(NoSuchRevision):
 
899
    """When using Tree.revision_tree, and the revision is not accessible."""
 
900
    
 
901
    _fmt = "The revision id %(revision_id)s is not present in the tree %(tree)s."
 
902
 
 
903
    def __init__(self, tree, revision_id):
 
904
        BzrError.__init__(self)
 
905
        self.tree = tree
 
906
        self.revision_id = revision_id
 
907
 
 
908
 
688
909
class InvalidRevisionSpec(BzrError):
689
910
 
690
 
    _fmt = "Requested revision: %(spec)r does not exist in branch: %(branch)s%(extra)s"
 
911
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
 
912
            " %(branch)s%(extra)s")
691
913
 
692
914
    def __init__(self, spec, branch, extra=None):
693
915
        BzrError.__init__(self, branch=branch, spec=spec)
702
924
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
703
925
 
704
926
 
 
927
class AppendRevisionsOnlyViolation(BzrError):
 
928
 
 
929
    _fmt = ('Operation denied because it would change the main history,'
 
930
           ' which is not permitted by the append_revisions_only setting on'
 
931
           ' branch "%(location)s".')
 
932
 
 
933
    def __init__(self, location):
 
934
       import bzrlib.urlutils as urlutils
 
935
       location = urlutils.unescape_for_display(location, 'ascii')
 
936
       BzrError.__init__(self, location=location)
 
937
 
 
938
 
705
939
class DivergedBranches(BzrError):
706
 
    
707
 
    _fmt = "These branches have diverged.  Use the merge command to reconcile them."""
 
940
 
 
941
    _fmt = ("These branches have diverged."
 
942
            " Use the merge command to reconcile them.")
708
943
 
709
944
    internal_error = False
710
945
 
713
948
        self.branch2 = branch2
714
949
 
715
950
 
 
951
class NotLefthandHistory(BzrError):
 
952
 
 
953
    _fmt = "Supplied history does not follow left-hand parents"
 
954
 
 
955
    internal_error = True
 
956
 
 
957
    def __init__(self, history):
 
958
        BzrError.__init__(self, history=history)
 
959
 
 
960
 
716
961
class UnrelatedBranches(BzrError):
717
962
 
718
 
    _fmt = "Branches have no common ancestor, and no merge base revision was specified."
 
963
    _fmt = ("Branches have no common ancestor, and"
 
964
            " no merge base revision was specified.")
719
965
 
720
966
    internal_error = False
721
967
 
731
977
 
732
978
class NoCommonRoot(BzrError):
733
979
 
734
 
    _fmt = "Revisions are not derived from the same root: " \
735
 
           "%(revision_a)s %(revision_b)s."
 
980
    _fmt = ("Revisions are not derived from the same root: "
 
981
           "%(revision_a)s %(revision_b)s.")
736
982
 
737
983
    def __init__(self, revision_a, revision_b):
738
984
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
761
1007
    def __init__(self, bases):
762
1008
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
763
1009
                DeprecationWarning)
764
 
        msg = "The correct base is unclear, because %s are all equally close" %\
765
 
            ", ".join(bases)
 
1010
        msg = ("The correct base is unclear, because %s are all equally close"
 
1011
                % ", ".join(bases))
766
1012
        BzrError.__init__(self, msg)
767
1013
        self.bases = bases
768
1014
 
790
1036
 
791
1037
class BoundBranchOutOfDate(BzrError):
792
1038
 
793
 
    _fmt = "Bound branch %(branch)s is out of date with master branch %(master)s."
 
1039
    _fmt = ("Bound branch %(branch)s is out of date"
 
1040
            " with master branch %(master)s.")
794
1041
 
795
1042
    def __init__(self, branch, master):
796
1043
        BzrError.__init__(self)
800
1047
        
801
1048
class CommitToDoubleBoundBranch(BzrError):
802
1049
 
803
 
    _fmt = "Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."
 
1050
    _fmt = ("Cannot commit to branch %(branch)s."
 
1051
            " It is bound to %(master)s, which is bound to %(remote)s.")
804
1052
 
805
1053
    def __init__(self, branch, master, remote):
806
1054
        BzrError.__init__(self)
820
1068
 
821
1069
class BoundBranchConnectionFailure(BzrError):
822
1070
 
823
 
    _fmt = "Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"
 
1071
    _fmt = ("Unable to connect to target of bound branch %(branch)s"
 
1072
            " => %(target)s: %(error)s")
824
1073
 
825
1074
    def __init__(self, branch, target, error):
826
1075
        BzrError.__init__(self)
880
1129
 
881
1130
class WeaveTextDiffers(WeaveError):
882
1131
 
883
 
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
 
1132
    _fmt = ("Weaves differ on text content. Revision:"
 
1133
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
884
1134
 
885
1135
    def __init__(self, revision_id, weave_a, weave_b):
886
1136
        WeaveError.__init__(self)
891
1141
 
892
1142
class WeaveTextDiffers(WeaveError):
893
1143
 
894
 
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
 
1144
    _fmt = ("Weaves differ on text content. Revision:"
 
1145
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
895
1146
 
896
1147
    def __init__(self, revision_id, weave_a, weave_b):
897
1148
        WeaveError.__init__(self)
929
1180
    
930
1181
    _fmt = "Knit error"
931
1182
 
 
1183
    internal_error = True
 
1184
 
932
1185
 
933
1186
class KnitHeaderError(KnitError):
934
1187
 
950
1203
        self.how = how
951
1204
 
952
1205
 
 
1206
class KnitIndexUnknownMethod(KnitError):
 
1207
    """Raised when we don't understand the storage method.
 
1208
 
 
1209
    Currently only 'fulltext' and 'line-delta' are supported.
 
1210
    """
 
1211
    
 
1212
    _fmt = ("Knit index %(filename)s does not have a known method"
 
1213
            " in options: %(options)r")
 
1214
 
 
1215
    def __init__(self, filename, options):
 
1216
        KnitError.__init__(self)
 
1217
        self.filename = filename
 
1218
        self.options = options
 
1219
 
 
1220
 
953
1221
class NoSuchExportFormat(BzrError):
954
1222
    
955
1223
    _fmt = "Export format %(format)r not supported"
977
1245
 
978
1246
class TooManyConcurrentRequests(BzrError):
979
1247
 
980
 
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit. "
981
 
            "Be sure to finish_writing and finish_reading on the "
982
 
            "current request that is open.")
 
1248
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
 
1249
            " Be sure to finish_writing and finish_reading on the"
 
1250
            " currently open request.")
983
1251
 
984
1252
    internal_error = True
985
1253
 
1068
1336
        InvalidHttpResponse.__init__(self, path, msg)
1069
1337
 
1070
1338
 
 
1339
class RedirectRequested(TransportError):
 
1340
 
 
1341
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
 
1342
 
 
1343
    def __init__(self, source, target, is_permament=False, qual_proto=None):
 
1344
        self.source = source
 
1345
        self.target = target
 
1346
        if is_permament:
 
1347
            self.permanently = ' permanently'
 
1348
        else:
 
1349
            self.permanently = ''
 
1350
        self.is_permament = is_permament
 
1351
        self._qualified_proto = qual_proto
 
1352
        TransportError.__init__(self)
 
1353
 
 
1354
    def _requalify_url(self, url):
 
1355
        """Restore the qualified proto in front of the url"""
 
1356
        # When this exception is raised, source and target are in
 
1357
        # user readable format. But some transports may use a
 
1358
        # different proto (http+urllib:// will present http:// to
 
1359
        # the user. If a qualified proto is specified, the code
 
1360
        # trapping the exception can get the qualified urls to
 
1361
        # properly handle the redirection themself (creating a
 
1362
        # new transport object from the target url for example).
 
1363
        # But checking that the scheme of the original and
 
1364
        # redirected urls are the same can be tricky. (see the
 
1365
        # FIXME in BzrDir.open_from_transport for the unique use
 
1366
        # case so far).
 
1367
        if self._qualified_proto is None:
 
1368
            return url
 
1369
 
 
1370
        # The TODO related to NotBranchError mention that doing
 
1371
        # that kind of manipulation on the urls may not be the
 
1372
        # exception object job. On the other hand, this object is
 
1373
        # the interface between the code and the user so
 
1374
        # presenting the urls in different ways is indeed its
 
1375
        # job...
 
1376
        import urlparse
 
1377
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1378
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1379
                                   query, fragment))
 
1380
 
 
1381
    def get_source_url(self):
 
1382
        return self._requalify_url(self.source)
 
1383
 
 
1384
    def get_target_url(self):
 
1385
        return self._requalify_url(self.target)
 
1386
 
 
1387
 
 
1388
class TooManyRedirections(TransportError):
 
1389
 
 
1390
    _fmt = "Too many redirections"
 
1391
 
1071
1392
class ConflictsInTree(BzrError):
1072
1393
 
1073
1394
    _fmt = "Working tree has conflicts."
1112
1433
 
1113
1434
class CantReprocessAndShowBase(BzrError):
1114
1435
 
1115
 
    _fmt = "Can't reprocess and show base, because reprocessing obscures " \
1116
 
           "the relationship of conflicting lines to the base"
 
1436
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
 
1437
           "the relationship of conflicting lines to the base")
1117
1438
 
1118
1439
 
1119
1440
class GraphCycleError(BzrError):
1168
1489
 
1169
1490
 
1170
1491
class MustUseDecorated(Exception):
1171
 
    
1172
 
    _fmt = """A decorating function has requested its original command be used."""
1173
 
    
 
1492
 
 
1493
    _fmt = "A decorating function has requested its original command be used."
 
1494
 
1174
1495
 
1175
1496
class NoBundleFound(BzrError):
1176
1497
 
1193
1514
 
1194
1515
class MissingText(BzrError):
1195
1516
 
1196
 
    _fmt = "Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"
 
1517
    _fmt = ("Branch %(base)s is missing revision"
 
1518
            " %(text_revision)s of %(file_id)s")
1197
1519
 
1198
1520
    def __init__(self, branch, text_revision, file_id):
1199
1521
        BzrError.__init__(self)
1203
1525
        self.file_id = file_id
1204
1526
 
1205
1527
 
 
1528
class DuplicateFileId(BzrError):
 
1529
 
 
1530
    _fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
 
1531
 
 
1532
    def __init__(self, file_id, entry):
 
1533
        BzrError.__init__(self)
 
1534
        self.file_id = file_id
 
1535
        self.entry = entry
 
1536
 
 
1537
 
1206
1538
class DuplicateKey(BzrError):
1207
1539
 
1208
1540
    _fmt = "Key %(key)s is already present in map"
1209
1541
 
1210
1542
 
 
1543
class DuplicateHelpPrefix(BzrError):
 
1544
 
 
1545
    _fmt = "The prefix %(prefix)s is in the help search path twice."
 
1546
 
 
1547
    def __init__(self, prefix):
 
1548
        self.prefix = prefix
 
1549
 
 
1550
 
1211
1551
class MalformedTransform(BzrError):
1212
1552
 
1213
1553
    _fmt = "Tree transform is malformed %(conflicts)r"
1252
1592
    _fmt = "Moving the root directory is not supported at this time"
1253
1593
 
1254
1594
 
 
1595
class BzrMoveFailedError(BzrError):
 
1596
 
 
1597
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1598
 
 
1599
    def __init__(self, from_path='', to_path='', extra=None):
 
1600
        BzrError.__init__(self)
 
1601
        if extra:
 
1602
            self.extra = ': ' + str(extra)
 
1603
        else:
 
1604
            self.extra = ''
 
1605
 
 
1606
        has_from = len(from_path) > 0
 
1607
        has_to = len(to_path) > 0
 
1608
        if has_from:
 
1609
            self.from_path = osutils.splitpath(from_path)[-1]
 
1610
        else:
 
1611
            self.from_path = ''
 
1612
 
 
1613
        if has_to:
 
1614
            self.to_path = osutils.splitpath(to_path)[-1]
 
1615
        else:
 
1616
            self.to_path = ''
 
1617
 
 
1618
        self.operator = ""
 
1619
        if has_from and has_to:
 
1620
            self.operator = " =>"
 
1621
        elif has_from:
 
1622
            self.from_path = "from " + from_path
 
1623
        elif has_to:
 
1624
            self.operator = "to"
 
1625
        else:
 
1626
            self.operator = "file"
 
1627
 
 
1628
 
 
1629
class BzrRenameFailedError(BzrMoveFailedError):
 
1630
 
 
1631
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1632
 
 
1633
    def __init__(self, from_path, to_path, extra=None):
 
1634
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
 
1635
 
 
1636
class BzrRemoveChangedFilesError(BzrError):
 
1637
    """Used when user is trying to remove changed files."""
 
1638
 
 
1639
    _fmt = ("Can't remove changed or unknown files:\n%(changes_as_text)s"
 
1640
        "Use --keep to not delete them, or --force to delete them regardless.")
 
1641
 
 
1642
    def __init__(self, tree_delta):
 
1643
        BzrError.__init__(self)
 
1644
        self.changes_as_text = tree_delta.get_changes_as_text()
 
1645
        #self.paths_as_string = '\n'.join(changed_files)
 
1646
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
 
1647
 
 
1648
 
1255
1649
class BzrBadParameterNotString(BzrBadParameter):
1256
1650
 
1257
1651
    _fmt = "Parameter %(param)s is not a string or unicode string."
1264
1658
 
1265
1659
class BzrBadParameterUnicode(BzrBadParameter):
1266
1660
 
1267
 
    _fmt = "Parameter %(param)s is unicode but only byte-strings are permitted."
 
1661
    _fmt = ("Parameter %(param)s is unicode but"
 
1662
            " only byte-strings are permitted.")
1268
1663
 
1269
1664
 
1270
1665
class BzrBadParameterContainsNewline(BzrBadParameter):
1356
1751
        self.tree = tree
1357
1752
 
1358
1753
 
 
1754
class PublicBranchOutOfDate(BzrError):
 
1755
 
 
1756
    _fmt = 'Public branch "%(public_location)s" lacks revision '\
 
1757
        '"%(revstring)s".'
 
1758
 
 
1759
    def __init__(self, public_location, revstring):
 
1760
        import bzrlib.urlutils as urlutils
 
1761
        public_location = urlutils.unescape_for_display(public_location,
 
1762
                                                        'ascii')
 
1763
        BzrError.__init__(self, public_location=public_location,
 
1764
                          revstring=revstring)
 
1765
 
 
1766
 
1359
1767
class MergeModifiedFormatError(BzrError):
1360
1768
 
1361
1769
    _fmt = "Error in merge modified format"
1368
1776
 
1369
1777
class CorruptRepository(BzrError):
1370
1778
 
1371
 
    _fmt = """An error has been detected in the repository %(repo_path)s.
1372
 
Please run bzr reconcile on this repository."""
 
1779
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
 
1780
            "Please run bzr reconcile on this repository.")
1373
1781
 
1374
1782
    def __init__(self, repo):
1375
1783
        BzrError.__init__(self)
1397
1805
 
1398
1806
class InvalidProgressBarType(BzrError):
1399
1807
 
1400
 
    _fmt = """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
1401
 
Select one of: %(valid_types)s"""
 
1808
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
 
1809
            " is not a supported type Select one of: %(valid_types)s")
1402
1810
 
1403
1811
    def __init__(self, bar_type, valid_types):
1404
1812
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1406
1814
 
1407
1815
class UnsupportedOperation(BzrError):
1408
1816
 
1409
 
    _fmt = "The method %(mname)s is not supported on objects of type %(tname)s."
 
1817
    _fmt = ("The method %(mname)s is not supported on"
 
1818
            " objects of type %(tname)s.")
1410
1819
 
1411
1820
    def __init__(self, method, method_self):
1412
1821
        self.method = method
1419
1828
 
1420
1829
 
1421
1830
class NonAsciiRevisionId(UnsupportedOperation):
1422
 
    """Raised when a commit is attempting to set a non-ascii revision id but cant."""
 
1831
    """Raised when a commit is attempting to set a non-ascii revision id
 
1832
       but cant.
 
1833
    """
1423
1834
 
1424
1835
 
1425
1836
class BinaryFile(BzrError):
1438
1849
 
1439
1850
class TestamentMismatch(BzrError):
1440
1851
 
1441
 
    _fmt = """Testament did not match expected value.  
1442
 
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured 
 
1852
    _fmt = """Testament did not match expected value.
 
1853
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
1443
1854
       {%(measured)s}"""
1444
1855
 
1445
1856
    def __init__(self, revision_id, expected, measured):
1514
1925
        BadInventoryFormat.__init__(self, msg=msg)
1515
1926
 
1516
1927
 
 
1928
class RootNotRich(BzrError):
 
1929
 
 
1930
    _fmt = """This operation requires rich root data storage"""
 
1931
 
 
1932
 
1517
1933
class NoSmartMedium(BzrError):
1518
1934
 
1519
1935
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
1520
1936
 
 
1937
    internal_error = True
 
1938
 
1521
1939
    def __init__(self, transport):
1522
1940
        self.transport = transport
1523
1941
 
1539
1957
        self.vendor = vendor
1540
1958
 
1541
1959
 
 
1960
class SSHVendorNotFound(BzrError):
 
1961
 
 
1962
    _fmt = ("Don't know how to handle SSH connections."
 
1963
            " Please set BZR_SSH environment variable.")
 
1964
 
 
1965
 
1542
1966
class GhostRevisionUnusableHere(BzrError):
1543
1967
 
1544
1968
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
1550
1974
 
1551
1975
class IllegalUseOfScopeReplacer(BzrError):
1552
1976
 
1553
 
    _fmt = "ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"
 
1977
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
 
1978
            " %(msg)s%(extra)s")
1554
1979
 
1555
1980
    internal_error = True
1556
1981
 
1578
2003
 
1579
2004
class ImportNameCollision(BzrError):
1580
2005
 
1581
 
    _fmt = "Tried to import an object to the same name as an existing object. %(name)s"
 
2006
    _fmt = ("Tried to import an object to the same name as"
 
2007
            " an existing object. %(name)s")
1582
2008
 
1583
2009
    internal_error = True
1584
2010
 
1585
2011
    def __init__(self, name):
1586
2012
        BzrError.__init__(self)
1587
2013
        self.name = name
 
2014
 
 
2015
 
 
2016
class NotAMergeDirective(BzrError):
 
2017
    """File starting with %(firstline)r is not a merge directive"""
 
2018
    def __init__(self, firstline):
 
2019
        BzrError.__init__(self, firstline=firstline)
 
2020
 
 
2021
 
 
2022
class NoMergeSource(BzrError):
 
2023
    """Raise if no merge source was specified for a merge directive"""
 
2024
 
 
2025
    _fmt = "A merge directive must provide either a bundle or a public"\
 
2026
        " branch location."
 
2027
 
 
2028
 
 
2029
class PatchMissing(BzrError):
 
2030
    """Raise a patch type was specified but no patch supplied"""
 
2031
 
 
2032
    _fmt = "patch_type was %(patch_type)s, but no patch was supplied."
 
2033
 
 
2034
    def __init__(self, patch_type):
 
2035
        BzrError.__init__(self)
 
2036
        self.patch_type = patch_type
 
2037
 
 
2038
 
 
2039
class UnsupportedInventoryKind(BzrError):
 
2040
    
 
2041
    _fmt = """Unsupported entry kind %(kind)s"""
 
2042
 
 
2043
    def __init__(self, kind):
 
2044
        self.kind = kind
 
2045
 
 
2046
 
 
2047
class BadSubsumeSource(BzrError):
 
2048
 
 
2049
    _fmt = """Can't subsume %(other_tree)s into %(tree)s.  %(reason)s"""
 
2050
 
 
2051
    def __init__(self, tree, other_tree, reason):
 
2052
        self.tree = tree
 
2053
        self.other_tree = other_tree
 
2054
        self.reason = reason
 
2055
 
 
2056
 
 
2057
class SubsumeTargetNeedsUpgrade(BzrError):
 
2058
    
 
2059
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
 
2060
 
 
2061
    def __init__(self, other_tree):
 
2062
        self.other_tree = other_tree
 
2063
 
 
2064
 
 
2065
class BadReferenceTarget(BzrError):
 
2066
 
 
2067
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s.  %(reason)s"
 
2068
 
 
2069
    internal_error = True
 
2070
 
 
2071
    def __init__(self, tree, other_tree, reason):
 
2072
        self.tree = tree
 
2073
        self.other_tree = other_tree
 
2074
        self.reason = reason
 
2075
 
 
2076
 
 
2077
class NoSuchTag(BzrError):
 
2078
 
 
2079
    _fmt = "No such tag: %(tag_name)s"
 
2080
 
 
2081
    def __init__(self, tag_name):
 
2082
        self.tag_name = tag_name
 
2083
 
 
2084
 
 
2085
class TagsNotSupported(BzrError):
 
2086
 
 
2087
    _fmt = ("Tags not supported by %(branch)s;"
 
2088
            " you may be able to use bzr upgrade --dirstate-tags.")
 
2089
 
 
2090
    def __init__(self, branch):
 
2091
        self.branch = branch
 
2092
 
 
2093
        
 
2094
class TagAlreadyExists(BzrError):
 
2095
 
 
2096
    _fmt = "Tag %(tag_name)s already exists."
 
2097
 
 
2098
    def __init__(self, tag_name):
 
2099
        self.tag_name = tag_name
 
2100
 
 
2101
 
 
2102
class MalformedBugIdentifier(BzrError):
 
2103
 
 
2104
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2105
 
 
2106
    def __init__(self, bug_id, reason):
 
2107
        self.bug_id = bug_id
 
2108
        self.reason = reason
 
2109
 
 
2110
 
 
2111
class UnknownBugTrackerAbbreviation(BzrError):
 
2112
 
 
2113
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
 
2114
            "on %(branch)s")
 
2115
 
 
2116
    def __init__(self, abbreviation, branch):
 
2117
        self.abbreviation = abbreviation
 
2118
        self.branch = branch
 
2119
 
 
2120
 
 
2121
class UnexpectedSmartServerResponse(BzrError):
 
2122
 
 
2123
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
 
2124
 
 
2125
    def __init__(self, response_tuple):
 
2126
        self.response_tuple = response_tuple