/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: John Arbash Meinel
  • Date: 2006-10-06 05:53:44 UTC
  • mfrom: (2063 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061006055344-e73b97b7c6ca6e72
[merge] bzr.dev 2063

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
>>> try:
45
45
...   raise NotBranchError(path='/foo/bar')
46
46
... except:
47
 
...   print sys.exc_type
 
47
...   print '%s.%s' % (sys.exc_type.__module__, sys.exc_type.__name__)
48
48
...   print sys.exc_value
49
49
...   path = getattr(sys.exc_value, 'path', None)
50
50
...   if path is not None:
96
96
class BzrError(StandardError):
97
97
    
98
98
    is_user_error = True
99
 
    
 
99
 
100
100
    def __str__(self):
101
101
        # XXX: Should we show the exception class in 
102
102
        # exceptions that don't provide their own message?  
120
120
    # base classes should override the docstring with their human-
121
121
    # readable explanation
122
122
 
123
 
    def __init__(self, **kwds):
 
123
    def __init__(self, *args, **kwds):
 
124
        # XXX: Use the underlying BzrError to always generate the args attribute
 
125
        # if it doesn't exist.  We can't use super here, because exceptions are
 
126
        # old-style classes in python2.4 (but new in 2.5).  --bmc, 20060426
 
127
        BzrError.__init__(self, *args)
124
128
        for key, value in kwds.items():
125
129
            setattr(self, key, value)
126
130
 
132
136
            if isinstance(s, unicode):
133
137
                return s.encode('utf8')
134
138
            return s
135
 
        except (NameError, ValueError, KeyError), e:
136
 
            return 'Unprintable exception %s: %s' \
137
 
                % (self.__class__.__name__, str(e))
 
139
        except (TypeError, NameError, ValueError, KeyError), e:
 
140
            return 'Unprintable exception %s(%r): %s' \
 
141
                % (self.__class__.__name__,
 
142
                   self.__dict__, str(e))
 
143
 
 
144
 
 
145
class AlreadyBuilding(BzrNewError):
 
146
    """The tree builder is already building a tree."""
138
147
 
139
148
 
140
149
class BzrCheckError(BzrNewError):
191
200
        self.base = base
192
201
 
193
202
 
 
203
class NotBuilding(BzrNewError):
 
204
    """Not currently building a tree."""
 
205
 
 
206
 
194
207
class NotLocalUrl(BzrNewError):
195
208
    """%(url)s is not a local path."""
196
209
    
274
287
 
275
288
    def __init__(self, msg, base, args):
276
289
        PathError.__init__(self, base, msg)
277
 
        self.args = [base]
278
 
        self.args.extend(args)
 
290
        self.args = [base] + list(args)
279
291
 
280
292
 
281
293
class UnsupportedProtocol(PathError):
285
297
        PathError.__init__(self, url, extra=extra)
286
298
 
287
299
 
 
300
class ShortReadvError(PathError):
 
301
    """readv() read %(actual)s bytes rather than %(length)s bytes at %(offset)s for %(path)s%(extra)s"""
 
302
 
 
303
    is_user_error = False
 
304
 
 
305
    def __init__(self, path, offset, length, actual, extra=None):
 
306
        PathError.__init__(self, path, extra=extra)
 
307
        self.offset = offset
 
308
        self.length = length
 
309
        self.actual = actual
 
310
 
 
311
 
288
312
class PathNotChild(BzrNewError):
289
313
    """Path %(path)r is not a child of path %(base)r%(extra)s"""
290
314
 
374
398
        self.bzrdir = bzrdir_format
375
399
 
376
400
 
 
401
class IncompatibleRevision(BzrNewError):
 
402
    """Revision is not compatible with %(repo_format)s"""
 
403
 
 
404
    def __init__(self, repo_format):
 
405
        BzrNewError.__init__(self)
 
406
        self.repo_format = repo_format
 
407
 
 
408
 
377
409
class NotVersionedError(BzrNewError):
378
410
    """%(path)s is not versioned"""
379
411
    def __init__(self, path):
790
822
        BzrNewError.__init__(self)
791
823
 
792
824
 
 
825
class SmartProtocolError(TransportError):
 
826
    """Generic bzr smart protocol error: %(details)s"""
 
827
 
 
828
    def __init__(self, details):
 
829
        self.details = details
 
830
 
 
831
 
793
832
# A set of semi-meaningful errors which can be thrown
794
833
class TransportNotPossible(TransportError):
795
 
    """Transport operation not possible: %(msg)s %(orig_error)%"""
 
834
    """Transport operation not possible: %(msg)s %(orig_error)s"""
796
835
 
797
836
 
798
837
class ConnectionError(TransportError):
851
890
        BzrError.__init__(self, message)
852
891
 
853
892
 
 
893
class NoEmailInUsername(BzrNewError):
 
894
    """%(username)r does not seem to contain a reasonable email address"""
 
895
 
 
896
    def __init__(self, username):
 
897
        BzrNewError.__init__(self)
 
898
        self.username = username
 
899
 
 
900
 
854
901
class SigningFailed(BzrError):
855
902
    def __init__(self, command_line):
856
903
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
990
1037
        self.format = format
991
1038
 
992
1039
 
 
1040
class BadConversionTarget(BzrNewError):
 
1041
    """Cannot convert to format %(format)s.  %(problem)s"""
 
1042
 
 
1043
    def __init__(self, problem, format):
 
1044
        BzrNewError.__init__(self)
 
1045
        self.problem = problem
 
1046
        self.format = format
 
1047
 
 
1048
 
993
1049
class NoDiff(BzrNewError):
994
1050
    """Diff is not installed on this machine: %(msg)s"""
995
1051
 
1148
1204
        BzrNewError.__init__(self)
1149
1205
 
1150
1206
 
 
1207
class IncompatibleFormat(BzrNewError):
 
1208
    """Bundle format %(bundle_format)s is incompatible with %(other)s"""
 
1209
 
 
1210
    def __init__(self, bundle_format, other):
 
1211
        BzrNewError.__init__(self)
 
1212
        self.bundle_format = bundle_format
 
1213
        self.other = other
 
1214
 
 
1215
 
 
1216
class BadInventoryFormat(BzrNewError):
 
1217
    """Root class for inventory serialization errors"""
 
1218
 
 
1219
 
 
1220
class UnexpectedInventoryFormat(BadInventoryFormat):
 
1221
    """The inventory was not in the expected format:\n %(msg)s"""
 
1222
 
 
1223
    def __init__(self, msg):
 
1224
        BadInventoryFormat.__init__(self, msg=msg)
 
1225
 
 
1226
 
 
1227
class NoSmartServer(NotBranchError):
 
1228
    """No smart server available at %(url)s"""
 
1229
 
 
1230
    def __init__(self, url):
 
1231
        self.url = url
 
1232
 
 
1233
 
1151
1234
class UnknownSSH(BzrNewError):
1152
1235
    """Unrecognised value for BZR_SSH environment variable: %(vendor)s"""
1153
1236