~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Martin Packman
  • Date: 2011-11-28 17:15:29 UTC
  • mto: This revision was merged to the branch mainline in revision 6328.
  • Revision ID: martin.packman@canonical.com-20111128171529-21crn1k8g8kulk2w
Remove deprecated classes and practices from bzrlib.errors

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from bzrlib import (
21
21
    osutils,
22
 
    symbol_versioning,
23
22
    i18n,
24
23
    trace,
25
24
    )
141
140
            if type(fmt) == unicode:
142
141
                trace.mutter("Unicode strings in error.fmt are deprecated")
143
142
            return gettext(unicode_fmt)
144
 
        fmt = getattr(self, '__doc__', None)
145
 
        if fmt is not None:
146
 
            symbol_versioning.warn("%s uses its docstring as a format, "
147
 
                    "it should use _fmt instead" % self.__class__.__name__,
148
 
                    DeprecationWarning)
149
 
            return fmt
150
143
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
151
144
            % (self.__class__.__name__,
152
145
               self.__dict__,
170
163
    internal_error = True
171
164
 
172
165
 
173
 
class BzrNewError(BzrError):
174
 
    """Deprecated error base class."""
175
 
    # base classes should override the docstring with their human-
176
 
    # readable explanation
177
 
 
178
 
    def __init__(self, *args, **kwds):
179
 
        # XXX: Use the underlying BzrError to always generate the args
180
 
        # attribute if it doesn't exist.  We can't use super here, because
181
 
        # exceptions are old-style classes in python2.4 (but new in 2.5).
182
 
        # --bmc, 20060426
183
 
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
184
 
             'please convert %s to use BzrError instead'
185
 
             % self.__class__.__name__,
186
 
             DeprecationWarning,
187
 
             stacklevel=2)
188
 
        BzrError.__init__(self, *args)
189
 
        for key, value in kwds.items():
190
 
            setattr(self, key, value)
191
 
 
192
 
    def __str__(self):
193
 
        try:
194
 
            # __str__() should always return a 'str' object
195
 
            # never a 'unicode' object.
196
 
            s = self.__doc__ % self.__dict__
197
 
            if isinstance(s, unicode):
198
 
                return s.encode('utf8')
199
 
            return s
200
 
        except (TypeError, NameError, ValueError, KeyError), e:
201
 
            return 'Unprintable exception %s(%r): %r' \
202
 
                % (self.__class__.__name__,
203
 
                   self.__dict__, e)
204
 
 
205
 
 
206
166
class AlreadyBuilding(BzrError):
207
167
 
208
168
    _fmt = "The tree builder is already building a tree."
790
750
        self.path = bzrdir.transport.clone('..').base
791
751
 
792
752
 
793
 
class FileInWrongBranch(BzrError):
794
 
 
795
 
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
796
 
 
797
 
    # use PathNotChild instead
798
 
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 3, 0)))
799
 
    def __init__(self, branch, path):
800
 
        BzrError.__init__(self)
801
 
        self.branch = branch
802
 
        self.branch_base = branch.base
803
 
        self.path = path
804
 
 
805
 
 
806
753
class UnsupportedFormatError(BzrError):
807
754
 
808
755
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
1296
1243
            not_ancestor_id=not_ancestor_id)
1297
1244
 
1298
1245
 
1299
 
class AmbiguousBase(BzrError):
1300
 
 
1301
 
    def __init__(self, bases):
1302
 
        symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
1303
 
            "as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
1304
 
        msg = ("The correct base is unclear, because %s are all equally close"
1305
 
                % ", ".join(bases))
1306
 
        BzrError.__init__(self, msg)
1307
 
        self.bases = bases
1308
 
 
1309
 
 
1310
1246
class NoCommits(BranchError):
1311
1247
 
1312
1248
    _fmt = "Branch %(branch)s has no commits."
2079
2015
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
2080
2016
 
2081
2017
 
2082
 
class BzrRemoveChangedFilesError(BzrError):
2083
 
    """Used when user is trying to remove changed files."""
2084
 
 
2085
 
    _fmt = ("Can't safely remove modified or unknown files:\n"
2086
 
        "%(changes_as_text)s"
2087
 
        "Use --keep to not delete them, or --force to delete them regardless.")
2088
 
 
2089
 
    def __init__(self, tree_delta):
2090
 
        symbol_versioning.warn(symbol_versioning.deprecated_in((2, 3, 0)) %
2091
 
            "BzrRemoveChangedFilesError", DeprecationWarning, stacklevel=2)
2092
 
        BzrError.__init__(self)
2093
 
        self.changes_as_text = tree_delta.get_changes_as_text()
2094
 
        #self.paths_as_string = '\n'.join(changed_files)
2095
 
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
2096
 
 
2097
 
 
2098
2018
class BzrBadParameterNotString(BzrBadParameter):
2099
2019
 
2100
2020
    _fmt = "Parameter %(param)s is not a string or unicode string."
3101
3021
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
3102
3022
 
3103
3023
 
3104
 
class HookFailed(BzrError):
3105
 
    """Raised when a pre_change_branch_tip hook function fails anything other
3106
 
    than TipChangeRejected.
3107
 
 
3108
 
    Note that this exception is no longer raised, and the import is only left
3109
 
    to be nice to code which might catch it in a plugin.
3110
 
    """
3111
 
 
3112
 
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
3113
 
            "%(traceback_text)s%(exc_value)s")
3114
 
 
3115
 
    def __init__(self, hook_stage, hook_name, exc_info, warn=True):
3116
 
        if warn:
3117
 
            symbol_versioning.warn("BzrError HookFailed has been deprecated "
3118
 
                "as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
3119
 
        import traceback
3120
 
        self.hook_stage = hook_stage
3121
 
        self.hook_name = hook_name
3122
 
        self.exc_info = exc_info
3123
 
        self.exc_type = exc_info[0]
3124
 
        self.exc_value = exc_info[1]
3125
 
        self.exc_tb = exc_info[2]
3126
 
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
3127
 
 
3128
 
 
3129
3024
class TipChangeRejected(BzrError):
3130
3025
    """A pre_change_branch_tip hook function may raise this to cleanly and
3131
3026
    explicitly abort a change to a branch tip.