~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Jelmer Vernooij
  • Date: 2010-12-20 11:57:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5577.
  • Revision ID: jelmer@samba.org-20101220115714-2ru3hfappjweeg7q
Don't use no-plugins.

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
680
680
 
681
681
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
682
682
 
683
 
    internal_error = True
 
683
    internal_error = False
684
684
 
685
685
    def __init__(self, path, base, extra=None):
686
686
        BzrError.__init__(self)
702
702
# TODO: Probably this behavior of should be a common superclass
703
703
class NotBranchError(PathError):
704
704
 
705
 
    _fmt = 'Not a branch: "%(path)s".'
 
705
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
706
706
 
707
 
    def __init__(self, path):
 
707
    def __init__(self, path, detail=None, bzrdir=None):
708
708
       import bzrlib.urlutils as urlutils
709
 
       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 __repr__(self):
 
717
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
 
718
 
 
719
    def _format(self):
 
720
        # XXX: Ideally self.detail would be a property, but Exceptions in
 
721
        # Python 2.4 have to be old-style classes so properties don't work.
 
722
        # Instead we override _format.
 
723
        if self.detail is None:
 
724
            if self.bzrdir is not None:
 
725
                try:
 
726
                    self.bzrdir.open_repository()
 
727
                except NoRepositoryPresent:
 
728
                    self.detail = ''
 
729
                except Exception:
 
730
                    # Just ignore unexpected errors.  Raising arbitrary errors
 
731
                    # during str(err) can provoke strange bugs.  Concretely
 
732
                    # Launchpad's codehosting managed to raise NotBranchError
 
733
                    # here, and then get stuck in an infinite loop/recursion
 
734
                    # trying to str() that error.  All this error really cares
 
735
                    # about that there's no working repository there, and if
 
736
                    # open_repository() fails, there probably isn't.
 
737
                    self.detail = ''
 
738
                else:
 
739
                    self.detail = ': location is a repository'
 
740
            else:
 
741
                self.detail = ''
 
742
        return PathError._format(self)
710
743
 
711
744
 
712
745
class NoSubmitBranch(PathError):
761
794
 
762
795
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
763
796
 
 
797
    # use PathNotChild instead
 
798
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 3, 0)))
764
799
    def __init__(self, branch, path):
765
800
        BzrError.__init__(self)
766
801
        self.branch = branch
926
961
    # original exception is available as e.original_error
927
962
    #
928
963
    # New code should prefer to raise specific subclasses
929
 
    def __init__(self, message):
930
 
        # Python 2.5 uses a slot for StandardError.message,
931
 
        # so use a different variable name.  We now work around this in
932
 
        # BzrError.__str__, but this member name is kept for compatability.
933
 
        self.msg = message
 
964
    def __init__(self, msg):
 
965
        self.msg = msg
934
966
 
935
967
 
936
968
class LockActive(LockError):
1020
1052
class LockContention(LockError):
1021
1053
 
1022
1054
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
1023
 
    # TODO: show full url for lock, combining the transport and relative
1024
 
    # bits?
1025
1055
 
1026
1056
    internal_error = False
1027
1057
 
1054
1084
        self.target = target
1055
1085
 
1056
1086
 
 
1087
class LockCorrupt(LockError):
 
1088
 
 
1089
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
 
1090
            "Use 'bzr break-lock' to clear it")
 
1091
 
 
1092
    internal_error = False
 
1093
 
 
1094
    def __init__(self, corruption_info, file_data=None):
 
1095
        self.corruption_info = corruption_info
 
1096
        self.file_data = file_data
 
1097
 
 
1098
 
1057
1099
class LockNotHeld(LockError):
1058
1100
 
1059
1101
    _fmt = "Lock not held: %(lock)s"
1158
1200
 
1159
1201
class InvalidRevisionSpec(BzrError):
1160
1202
 
1161
 
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
1162
 
            " %(branch)s%(extra)s")
 
1203
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
 
1204
            " %(branch_url)s%(extra)s")
1163
1205
 
1164
1206
    def __init__(self, spec, branch, extra=None):
1165
1207
        BzrError.__init__(self, branch=branch, spec=spec)
 
1208
        self.branch_url = getattr(branch, 'user_url', str(branch))
1166
1209
        if extra:
1167
1210
            self.extra = '\n' + str(extra)
1168
1211
        else:
1247
1290
class AmbiguousBase(BzrError):
1248
1291
 
1249
1292
    def __init__(self, bases):
1250
 
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
1251
 
                DeprecationWarning)
 
1293
        symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
 
1294
            "as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
1252
1295
        msg = ("The correct base is unclear, because %s are all equally close"
1253
1296
                % ", ".join(bases))
1254
1297
        BzrError.__init__(self, msg)
1276
1319
class BoundBranchOutOfDate(BzrError):
1277
1320
 
1278
1321
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1279
 
            " %(master)s.")
 
1322
            " %(master)s.%(extra_help)s")
1280
1323
 
1281
1324
    def __init__(self, branch, master):
1282
1325
        BzrError.__init__(self)
1283
1326
        self.branch = branch
1284
1327
        self.master = master
 
1328
        self.extra_help = ''
1285
1329
 
1286
1330
 
1287
1331
class CommitToDoubleBoundBranch(BzrError):
1358
1402
 
1359
1403
class WeaveParentMismatch(WeaveError):
1360
1404
 
1361
 
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
1405
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
1362
1406
 
1363
1407
 
1364
1408
class WeaveInvalidChecksum(WeaveError):
1365
1409
 
1366
 
    _fmt = "Text did not match it's checksum: %(message)s"
 
1410
    _fmt = "Text did not match its checksum: %(msg)s"
1367
1411
 
1368
1412
 
1369
1413
class WeaveTextDiffers(WeaveError):
1417
1461
 
1418
1462
class VersionedFileInvalidChecksum(VersionedFileError):
1419
1463
 
1420
 
    _fmt = "Text did not match its checksum: %(message)s"
 
1464
    _fmt = "Text did not match its checksum: %(msg)s"
1421
1465
 
1422
1466
 
1423
1467
class KnitError(InternalBzrError):
1903
1947
    _fmt = "Moving the root directory is not supported at this time"
1904
1948
 
1905
1949
 
 
1950
class TransformRenameFailed(BzrError):
 
1951
 
 
1952
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
 
1953
 
 
1954
    def __init__(self, from_path, to_path, why, errno):
 
1955
        self.from_path = from_path
 
1956
        self.to_path = to_path
 
1957
        self.why = why
 
1958
        self.errno = errno
 
1959
 
 
1960
 
1906
1961
class BzrMoveFailedError(BzrError):
1907
1962
 
1908
1963
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1953
2008
        "Use --keep to not delete them, or --force to delete them regardless.")
1954
2009
 
1955
2010
    def __init__(self, tree_delta):
 
2011
        symbol_versioning.warn(symbol_versioning.deprecated_in((2, 3, 0)) %
 
2012
            "BzrRemoveChangedFilesError", DeprecationWarning, stacklevel=2)
1956
2013
        BzrError.__init__(self)
1957
2014
        self.changes_as_text = tree_delta.get_changes_as_text()
1958
2015
        #self.paths_as_string = '\n'.join(changed_files)
2154
2211
 
2155
2212
    def __init__(self, repo):
2156
2213
        BzrError.__init__(self)
2157
 
        self.repo_path = repo.bzrdir.root_transport.base
 
2214
        self.repo_path = repo.user_url
2158
2215
 
2159
2216
 
2160
2217
class InconsistentDelta(BzrError):
2732
2789
 
2733
2790
    def __init__(self, bzrdir):
2734
2791
        import bzrlib.urlutils as urlutils
2735
 
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2792
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
2736
2793
                                                    'ascii')
2737
2794
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2738
2795
 
2812
2869
        else:
2813
2870
            more = ' ' + more
2814
2871
        import bzrlib.urlutils as urlutils
2815
 
        display_url = urlutils.unescape_for_display(
2816
 
            tree.bzrdir.root_transport.base, 'ascii')
 
2872
        user_url = getattr(tree, "user_url", None)
 
2873
        if user_url is None:
 
2874
            display_url = str(tree)
 
2875
        else:
 
2876
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2817
2877
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2818
2878
 
2819
2879
 
 
2880
class ShelvedChanges(UncommittedChanges):
 
2881
 
 
2882
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
 
2883
            ' (See bzr shelve --list).%(more)s')
 
2884
 
 
2885
 
2820
2886
class MissingTemplateVariable(BzrError):
2821
2887
 
2822
2888
    _fmt = 'Variable {%(name)s} is not available.'
2891
2957
        self.user_encoding = osutils.get_user_encoding()
2892
2958
 
2893
2959
 
 
2960
class NoSuchConfig(BzrError):
 
2961
 
 
2962
    _fmt = ('The "%(config_id)s" configuration does not exist.')
 
2963
 
 
2964
    def __init__(self, config_id):
 
2965
        BzrError.__init__(self, config_id=config_id)
 
2966
 
 
2967
 
 
2968
class NoSuchConfigOption(BzrError):
 
2969
 
 
2970
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
 
2971
 
 
2972
    def __init__(self, option_name):
 
2973
        BzrError.__init__(self, option_name=option_name)
 
2974
 
 
2975
 
2894
2976
class NoSuchAlias(BzrError):
2895
2977
 
2896
2978
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2942
3024
class HookFailed(BzrError):
2943
3025
    """Raised when a pre_change_branch_tip hook function fails anything other
2944
3026
    than TipChangeRejected.
 
3027
 
 
3028
    Note that this exception is no longer raised, and the import is only left
 
3029
    to be nice to code which might catch it in a plugin.
2945
3030
    """
2946
3031
 
2947
3032
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2948
3033
            "%(traceback_text)s%(exc_value)s")
2949
3034
 
2950
 
    def __init__(self, hook_stage, hook_name, exc_info):
 
3035
    def __init__(self, hook_stage, hook_name, exc_info, warn=True):
 
3036
        if warn:
 
3037
            symbol_versioning.warn("BzrError HookFailed has been deprecated "
 
3038
                "as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
2951
3039
        import traceback
2952
3040
        self.hook_stage = hook_stage
2953
3041
        self.hook_name = hook_name
3075
3163
    def __init__(self, source_branch, target_branch):
3076
3164
        self.source_branch = source_branch
3077
3165
        self.target_branch = target_branch
 
3166
 
 
3167
 
 
3168
class NoRoundtrippingSupport(BzrError):
 
3169
 
 
3170
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
 
3171
            "%(target_branch)r.")
 
3172
 
 
3173
    internal_error = True
 
3174
 
 
3175
    def __init__(self, source_branch, target_branch):
 
3176
        self.source_branch = source_branch
 
3177
        self.target_branch = target_branch
 
3178
 
 
3179
 
 
3180
class FileTimestampUnavailable(BzrError):
 
3181
 
 
3182
    _fmt = "The filestamp for %(path)s is not available."
 
3183
 
 
3184
    internal_error = True
 
3185
 
 
3186
    def __init__(self, path):
 
3187
        self.path = path
 
3188
 
 
3189
 
 
3190
class NoColocatedBranchSupport(BzrError):
 
3191
 
 
3192
    _fmt = ("%(bzrdir)r does not support co-located branches.")
 
3193
 
 
3194
    def __init__(self, bzrdir):
 
3195
        self.bzrdir = bzrdir
 
3196
 
 
3197
 
 
3198
class NoWhoami(BzrError):
 
3199
 
 
3200
    _fmt = ('Unable to determine your name.\n'
 
3201
        "Please, set your name with the 'whoami' command.\n"
 
3202
        'E.g. bzr whoami "Your Name <name@example.com>"')
 
3203
 
 
3204
 
 
3205
class InvalidPattern(BzrError):
 
3206
 
 
3207
    _fmt = ('Invalid pattern(s) found. %(msg)s')
 
3208
 
 
3209
    def __init__(self, msg):
 
3210
        self.msg = msg
 
3211
 
 
3212
 
 
3213
class RecursiveBind(BzrError):
 
3214
 
 
3215
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
 
3216
        'Please use `bzr unbind` to fix.')
 
3217
 
 
3218
    def __init__(self, branch_url):
 
3219
        self.branch_url = branch_url
 
3220