/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

Merge bzr.dev

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):
799
831
        BzrNewError.__init__(self)
800
832
 
801
833
 
 
834
class SmartProtocolError(TransportError):
 
835
    """Generic bzr smart protocol error: %(details)s"""
 
836
 
 
837
    def __init__(self, details):
 
838
        self.details = details
 
839
 
 
840
 
802
841
# A set of semi-meaningful errors which can be thrown
803
842
class TransportNotPossible(TransportError):
804
 
    """Transport operation not possible: %(msg)s %(orig_error)%"""
 
843
    """Transport operation not possible: %(msg)s %(orig_error)s"""
805
844
 
806
845
 
807
846
class ConnectionError(TransportError):
999
1038
        self.format = format
1000
1039
 
1001
1040
 
 
1041
class BadConversionTarget(BzrNewError):
 
1042
    """Cannot convert to format %(format)s.  %(problem)s"""
 
1043
 
 
1044
    def __init__(self, problem, format):
 
1045
        BzrNewError.__init__(self)
 
1046
        self.problem = problem
 
1047
        self.format = format
 
1048
 
 
1049
 
1002
1050
class NoDiff(BzrNewError):
1003
1051
    """Diff is not installed on this machine: %(msg)s"""
1004
1052
 
1157
1205
        BzrNewError.__init__(self)
1158
1206
 
1159
1207
 
 
1208
class IncompatibleFormat(BzrNewError):
 
1209
    """Bundle format %(bundle_format)s is incompatible with %(other)s"""
 
1210
 
 
1211
    def __init__(self, bundle_format, other):
 
1212
        BzrNewError.__init__(self)
 
1213
        self.bundle_format = bundle_format
 
1214
        self.other = other
 
1215
 
 
1216
 
 
1217
class BadInventoryFormat(BzrNewError):
 
1218
    """Root class for inventory serialization errors"""
 
1219
 
 
1220
 
 
1221
class UnexpectedInventoryFormat(BadInventoryFormat):
 
1222
    """The inventory was not in the expected format:\n %(msg)s"""
 
1223
 
 
1224
    def __init__(self, msg):
 
1225
        BadInventoryFormat.__init__(self, msg=msg)
 
1226
 
 
1227
 
 
1228
class NoSmartServer(NotBranchError):
 
1229
    """No smart server available at %(url)s"""
 
1230
 
 
1231
    def __init__(self, url):
 
1232
        self.url = url
 
1233
 
 
1234
 
1160
1235
class UnknownSSH(BzrNewError):
1161
1236
    """Unrecognised value for BZR_SSH environment variable: %(vendor)s"""
1162
1237
 
1171
1246
    def __init__(self, revision_id):
1172
1247
        BzrNewError.__init__(self)
1173
1248
        self.revision_id = revision_id
 
1249
 
 
1250
 
 
1251
class IllegalUseOfScopeReplacer(BzrNewError):
 
1252
    """ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"""
 
1253
 
 
1254
    is_user_error = False
 
1255
 
 
1256
    def __init__(self, name, msg, extra=None):
 
1257
        BzrNewError.__init__(self)
 
1258
        self.name = name
 
1259
        self.msg = msg
 
1260
        if extra:
 
1261
            self.extra = ': ' + str(extra)
 
1262
        else:
 
1263
            self.extra = ''
 
1264
 
 
1265
 
 
1266
class InvalidImportLine(BzrNewError):
 
1267
    """Not a valid import statement: %(msg)\n%(text)s"""
 
1268
 
 
1269
    is_user_error = False
 
1270
 
 
1271
    def __init__(self, text, msg):
 
1272
        BzrNewError.__init__(self)
 
1273
        self.text = text
 
1274
        self.msg = msg
 
1275
 
 
1276
 
 
1277
class ImportNameCollision(BzrNewError):
 
1278
    """Tried to import an object to the same name as an existing object. %(name)s"""
 
1279
 
 
1280
    is_user_error = False
 
1281
 
 
1282
    def __init__(self, name):
 
1283
        BzrNewError.__init__(self)
 
1284
        self.name = name