/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

  • Committer: Patch Queue Manager
  • Date: 2011-11-29 18:31:53 UTC
  • mfrom: (6318.2.5 errors_cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20111129183153-u0gz7nl7s0j208kt
(gz) Remove deprecated parts of bzrlib.errors and other cleanups (Martin
 Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
20
 
from bzrlib import (
21
 
    osutils,
22
 
    symbol_versioning,
23
 
    i18n,
24
 
    trace,
25
 
    )
26
 
from bzrlib.i18n import gettext
27
 
 
28
 
 
29
20
# TODO: is there any value in providing the .args field used by standard
30
21
# python exceptions?   A list of values with no names seems less useful
31
22
# to me.
102
93
                # __str__() should always return a 'str' object
103
94
                # never a 'unicode' object.
104
95
                return s
105
 
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
106
 
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
107
 
                % (self.__class__.__name__,
108
 
                   self.__dict__,
109
 
                   getattr(self, '_fmt', None),
110
 
                   e)
 
96
        except Exception, e:
 
97
            pass # just bind to 'e' for formatting below
 
98
        else:
 
99
            e = None
 
100
        return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
101
            % (self.__class__.__name__,
 
102
               self.__dict__,
 
103
               getattr(self, '_fmt', None),
 
104
               e)
111
105
 
112
106
    def __unicode__(self):
113
107
        u = self._format()
136
130
        """Return format string for this exception or None"""
137
131
        fmt = getattr(self, '_fmt', None)
138
132
        if fmt is not None:
139
 
            i18n.install()
140
 
            unicode_fmt = unicode(fmt) #_fmt strings should be ascii
141
 
            if type(fmt) == unicode:
142
 
                trace.mutter("Unicode strings in error.fmt are deprecated")
143
 
            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
 
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
151
 
            % (self.__class__.__name__,
152
 
               self.__dict__,
153
 
               getattr(self, '_fmt', None),
154
 
               )
 
133
            from bzrlib.i18n import gettext
 
134
            return gettext(unicode(fmt)) # _fmt strings should be ascii
155
135
 
156
136
    def __eq__(self, other):
157
137
        if self.__class__ is not other.__class__:
170
150
    internal_error = True
171
151
 
172
152
 
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
153
class AlreadyBuilding(BzrError):
207
154
 
208
155
    _fmt = "The tree builder is already building a tree."
790
737
        self.path = bzrdir.transport.clone('..').base
791
738
 
792
739
 
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
740
class UnsupportedFormatError(BzrError):
807
741
 
808
742
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
1296
1230
            not_ancestor_id=not_ancestor_id)
1297
1231
 
1298
1232
 
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
1233
class NoCommits(BranchError):
1311
1234
 
1312
1235
    _fmt = "Branch %(branch)s has no commits."
2079
2002
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
2080
2003
 
2081
2004
 
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
2005
class BzrBadParameterNotString(BzrBadParameter):
2099
2006
 
2100
2007
    _fmt = "Parameter %(param)s is not a string or unicode string."
3034
2941
        from bzrlib.osutils import get_user_encoding
3035
2942
        self.path = path
3036
2943
        self.kind = kind
3037
 
        self.user_encoding = osutils.get_user_encoding()
 
2944
        self.user_encoding = get_user_encoding()
3038
2945
 
3039
2946
 
3040
2947
class NoSuchConfig(BzrError):
3101
3008
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
3102
3009
 
3103
3010
 
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
3011
class TipChangeRejected(BzrError):
3130
3012
    """A pre_change_branch_tip hook function may raise this to cleanly and
3131
3013
    explicitly abort a change to a branch tip.