~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-29 22:03:03 UTC
  • mfrom: (5416.2.6 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100929220303-cr95h8iwtggco721
(mbp) Add 'break-lock --force'

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
636
636
        self.url = url
637
637
 
638
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
 
639
649
class UnstackableRepositoryFormat(BzrError):
640
650
 
641
651
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
670
680
 
671
681
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
672
682
 
673
 
    internal_error = True
 
683
    internal_error = False
674
684
 
675
685
    def __init__(self, path, base, extra=None):
676
686
        BzrError.__init__(self)
692
702
# TODO: Probably this behavior of should be a common superclass
693
703
class NotBranchError(PathError):
694
704
 
695
 
    _fmt = 'Not a branch: "%(path)s".'
 
705
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
696
706
 
697
 
    def __init__(self, path):
 
707
    def __init__(self, path, detail=None, bzrdir=None):
698
708
       import bzrlib.urlutils as urlutils
699
 
       self.path = urlutils.unescape_for_display(path, 'ascii')
 
709
       path = urlutils.unescape_for_display(path, 'ascii')
 
710
       if detail is not None:
 
711
           detail = ': ' + detail
 
712
       self.detail = detail
 
713
       self.bzrdir = bzrdir
 
714
       PathError.__init__(self, path=path)
 
715
 
 
716
    def _format(self):
 
717
        # XXX: Ideally self.detail would be a property, but Exceptions in
 
718
        # Python 2.4 have to be old-style classes so properties don't work.
 
719
        # Instead we override _format.
 
720
        if self.detail is None:
 
721
            if self.bzrdir is not None:
 
722
                try:
 
723
                    self.bzrdir.open_repository()
 
724
                except NoRepositoryPresent:
 
725
                    self.detail = ''
 
726
                else:
 
727
                    self.detail = ': location is a repository'
 
728
            else:
 
729
                self.detail = ''
 
730
        return PathError._format(self)
700
731
 
701
732
 
702
733
class NoSubmitBranch(PathError):
751
782
 
752
783
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
753
784
 
 
785
    # use PathNotChild instead
 
786
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 3, 0)))
754
787
    def __init__(self, branch, path):
755
788
        BzrError.__init__(self)
756
789
        self.branch = branch
783
816
 
784
817
 
785
818
class IncompatibleRepositories(BzrError):
 
819
    """Report an error that two repositories are not compatible.
 
820
 
 
821
    Note that the source and target repositories are permitted to be strings:
 
822
    this exception is thrown from the smart server and may refer to a
 
823
    repository the client hasn't opened.
 
824
    """
786
825
 
787
826
    _fmt = "%(target)s\n" \
788
827
            "is not compatible with\n" \
910
949
    # original exception is available as e.original_error
911
950
    #
912
951
    # New code should prefer to raise specific subclasses
913
 
    def __init__(self, message):
914
 
        # Python 2.5 uses a slot for StandardError.message,
915
 
        # so use a different variable name.  We now work around this in
916
 
        # BzrError.__str__, but this member name is kept for compatability.
917
 
        self.msg = message
 
952
    def __init__(self, msg):
 
953
        self.msg = msg
918
954
 
919
955
 
920
956
class LockActive(LockError):
1004
1040
class LockContention(LockError):
1005
1041
 
1006
1042
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
1007
 
    # TODO: show full url for lock, combining the transport and relative
1008
 
    # bits?
1009
1043
 
1010
1044
    internal_error = False
1011
1045
 
1038
1072
        self.target = target
1039
1073
 
1040
1074
 
 
1075
class LockCorrupt(LockError):
 
1076
 
 
1077
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
 
1078
            "Use 'bzr break-lock' to clear it")
 
1079
 
 
1080
    internal_error = False
 
1081
 
 
1082
    def __init__(self, corruption_info, file_data=None):
 
1083
        self.corruption_info = corruption_info
 
1084
        self.file_data = file_data
 
1085
 
 
1086
 
1041
1087
class LockNotHeld(LockError):
1042
1088
 
1043
1089
    _fmt = "Lock not held: %(lock)s"
1142
1188
 
1143
1189
class InvalidRevisionSpec(BzrError):
1144
1190
 
1145
 
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
1146
 
            " %(branch)s%(extra)s")
 
1191
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
 
1192
            " %(branch_url)s%(extra)s")
1147
1193
 
1148
1194
    def __init__(self, spec, branch, extra=None):
1149
1195
        BzrError.__init__(self, branch=branch, spec=spec)
 
1196
        self.branch_url = getattr(branch, 'user_url', str(branch))
1150
1197
        if extra:
1151
1198
            self.extra = '\n' + str(extra)
1152
1199
        else:
1231
1278
class AmbiguousBase(BzrError):
1232
1279
 
1233
1280
    def __init__(self, bases):
1234
 
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
1235
 
                DeprecationWarning)
 
1281
        symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
 
1282
            "as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
1236
1283
        msg = ("The correct base is unclear, because %s are all equally close"
1237
1284
                % ", ".join(bases))
1238
1285
        BzrError.__init__(self, msg)
1260
1307
class BoundBranchOutOfDate(BzrError):
1261
1308
 
1262
1309
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1263
 
            " %(master)s.")
 
1310
            " %(master)s.%(extra_help)s")
1264
1311
 
1265
1312
    def __init__(self, branch, master):
1266
1313
        BzrError.__init__(self)
1267
1314
        self.branch = branch
1268
1315
        self.master = master
 
1316
        self.extra_help = ''
1269
1317
 
1270
1318
 
1271
1319
class CommitToDoubleBoundBranch(BzrError):
1342
1390
 
1343
1391
class WeaveParentMismatch(WeaveError):
1344
1392
 
1345
 
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
1393
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
1346
1394
 
1347
1395
 
1348
1396
class WeaveInvalidChecksum(WeaveError):
1349
1397
 
1350
 
    _fmt = "Text did not match it's checksum: %(message)s"
 
1398
    _fmt = "Text did not match its checksum: %(msg)s"
1351
1399
 
1352
1400
 
1353
1401
class WeaveTextDiffers(WeaveError):
1401
1449
 
1402
1450
class VersionedFileInvalidChecksum(VersionedFileError):
1403
1451
 
1404
 
    _fmt = "Text did not match its checksum: %(message)s"
 
1452
    _fmt = "Text did not match its checksum: %(msg)s"
1405
1453
 
1406
1454
 
1407
1455
class KnitError(InternalBzrError):
1887
1935
    _fmt = "Moving the root directory is not supported at this time"
1888
1936
 
1889
1937
 
 
1938
class TransformRenameFailed(BzrError):
 
1939
 
 
1940
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
 
1941
 
 
1942
    def __init__(self, from_path, to_path, why, errno):
 
1943
        self.from_path = from_path
 
1944
        self.to_path = to_path
 
1945
        self.why = why
 
1946
        self.errno = errno
 
1947
 
 
1948
 
1890
1949
class BzrMoveFailedError(BzrError):
1891
1950
 
1892
1951
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1937
1996
        "Use --keep to not delete them, or --force to delete them regardless.")
1938
1997
 
1939
1998
    def __init__(self, tree_delta):
 
1999
        symbol_versioning.warn(symbol_versioning.deprecated_in((2, 3, 0)) %
 
2000
            "BzrRemoveChangedFilesError", DeprecationWarning, stacklevel=2)
1940
2001
        BzrError.__init__(self)
1941
2002
        self.changes_as_text = tree_delta.get_changes_as_text()
1942
2003
        #self.paths_as_string = '\n'.join(changed_files)
1996
2057
 
1997
2058
class BadConversionTarget(BzrError):
1998
2059
 
1999
 
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
 
2060
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
 
2061
            "    %(problem)s"
2000
2062
 
2001
 
    def __init__(self, problem, format):
 
2063
    def __init__(self, problem, format, from_format=None):
2002
2064
        BzrError.__init__(self)
2003
2065
        self.problem = problem
2004
2066
        self.format = format
 
2067
        self.from_format = from_format or '(unspecified)'
2005
2068
 
2006
2069
 
2007
2070
class NoDiffFound(BzrError):
2083
2146
 
2084
2147
class OutOfDateTree(BzrError):
2085
2148
 
2086
 
    _fmt = "Working tree is out of date, please run 'bzr update'."
 
2149
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
2087
2150
 
2088
 
    def __init__(self, tree):
 
2151
    def __init__(self, tree, more=None):
 
2152
        if more is None:
 
2153
            more = ''
 
2154
        else:
 
2155
            more = ' ' + more
2089
2156
        BzrError.__init__(self)
2090
2157
        self.tree = tree
 
2158
        self.more = more
2091
2159
 
2092
2160
 
2093
2161
class PublicBranchOutOfDate(BzrError):
2131
2199
 
2132
2200
    def __init__(self, repo):
2133
2201
        BzrError.__init__(self)
2134
 
        self.repo_path = repo.bzrdir.root_transport.base
 
2202
        self.repo_path = repo.user_url
2135
2203
 
2136
2204
 
2137
2205
class InconsistentDelta(BzrError):
2147
2215
        self.reason = reason
2148
2216
 
2149
2217
 
 
2218
class InconsistentDeltaDelta(InconsistentDelta):
 
2219
    """Used when we get a delta that is not valid."""
 
2220
 
 
2221
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
 
2222
            "\nreason: %(reason)s")
 
2223
 
 
2224
    def __init__(self, delta, reason):
 
2225
        BzrError.__init__(self)
 
2226
        self.delta = delta
 
2227
        self.reason = reason
 
2228
 
 
2229
 
2150
2230
class UpgradeRequired(BzrError):
2151
2231
 
2152
2232
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2697
2777
 
2698
2778
    def __init__(self, bzrdir):
2699
2779
        import bzrlib.urlutils as urlutils
2700
 
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2780
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
2701
2781
                                                    'ascii')
2702
2782
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2703
2783
 
2768
2848
 
2769
2849
class UncommittedChanges(BzrError):
2770
2850
 
2771
 
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
 
2851
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
 
2852
            ' (See bzr status).%(more)s')
2772
2853
 
2773
 
    def __init__(self, tree):
 
2854
    def __init__(self, tree, more=None):
 
2855
        if more is None:
 
2856
            more = ''
 
2857
        else:
 
2858
            more = ' ' + more
2774
2859
        import bzrlib.urlutils as urlutils
2775
 
        display_url = urlutils.unescape_for_display(
2776
 
            tree.bzrdir.root_transport.base, 'ascii')
2777
 
        BzrError.__init__(self, tree=tree, display_url=display_url)
 
2860
        user_url = getattr(tree, "user_url", None)
 
2861
        if user_url is None:
 
2862
            display_url = str(tree)
 
2863
        else:
 
2864
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
 
2865
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
 
2866
 
 
2867
 
 
2868
class ShelvedChanges(UncommittedChanges):
 
2869
 
 
2870
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
 
2871
            ' (See bzr shelve --list).%(more)s')
2778
2872
 
2779
2873
 
2780
2874
class MissingTemplateVariable(BzrError):
2886
2980
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2887
2981
 
2888
2982
    def __init__(self, host, port, orig_error):
 
2983
        # nb: in python2.4 socket.error doesn't have a useful repr
2889
2984
        BzrError.__init__(self, host=host, port=port,
2890
 
            orig_error=orig_error[1])
 
2985
            orig_error=repr(orig_error.args))
2891
2986
 
2892
2987
 
2893
2988
class UnknownRules(BzrError):
2901
2996
class HookFailed(BzrError):
2902
2997
    """Raised when a pre_change_branch_tip hook function fails anything other
2903
2998
    than TipChangeRejected.
 
2999
 
 
3000
    Note that this exception is no longer raised, and the import is only left
 
3001
    to be nice to code which might catch it in a plugin.
2904
3002
    """
2905
3003
 
2906
3004
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2907
3005
            "%(traceback_text)s%(exc_value)s")
2908
3006
 
2909
 
    def __init__(self, hook_stage, hook_name, exc_info):
 
3007
    def __init__(self, hook_stage, hook_name, exc_info, warn=True):
 
3008
        if warn:
 
3009
            symbol_versioning.warn("BzrError HookFailed has been deprecated "
 
3010
                "as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
2910
3011
        import traceback
2911
3012
        self.hook_stage = hook_stage
2912
3013
        self.hook_name = hook_name
3034
3135
    def __init__(self, source_branch, target_branch):
3035
3136
        self.source_branch = source_branch
3036
3137
        self.target_branch = target_branch
 
3138
 
 
3139
 
 
3140
class NoRoundtrippingSupport(BzrError):
 
3141
 
 
3142
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
 
3143
            "%(target_branch)r.")
 
3144
 
 
3145
    internal_error = True
 
3146
 
 
3147
    def __init__(self, source_branch, target_branch):
 
3148
        self.source_branch = source_branch
 
3149
        self.target_branch = target_branch
 
3150
 
 
3151
 
 
3152
class FileTimestampUnavailable(BzrError):
 
3153
 
 
3154
    _fmt = "The filestamp for %(path)s is not available."
 
3155
 
 
3156
    internal_error = True
 
3157
 
 
3158
    def __init__(self, path):
 
3159
        self.path = path
 
3160
 
 
3161
 
 
3162
class NoColocatedBranchSupport(BzrError):
 
3163
 
 
3164
    _fmt = ("%(bzrdir)r does not support co-located branches.")
 
3165
 
 
3166
    def __init__(self, bzrdir):
 
3167
        self.bzrdir = bzrdir
 
3168
 
 
3169
 
 
3170
class NoWhoami(BzrError):
 
3171
 
 
3172
    _fmt = ('Unable to determine your name.\n'
 
3173
        "Please, set your name with the 'whoami' command.\n"
 
3174
        'E.g. bzr whoami "Your Name <name@example.com>"')
 
3175
 
 
3176
 
 
3177
class InvalidPattern(BzrError):
 
3178
 
 
3179
    _fmt = ('Invalid pattern(s) found. %(msg)s')
 
3180
 
 
3181
    def __init__(self, msg):
 
3182
        self.msg = msg
 
3183
 
 
3184
 
 
3185
class RecursiveBind(BzrError):
 
3186
 
 
3187
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
 
3188
        'Please use `bzr unbind` to fix.')
 
3189
 
 
3190
    def __init__(self, branch_url):
 
3191
        self.branch_url = branch_url
 
3192