/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):
174
183
        self.branch = branch
175
184
 
176
185
 
 
186
class NoSuchId(BzrNewError):
 
187
    """The file id %(file_id)s is not present in the tree %(tree)s."""
 
188
    
 
189
    def __init__(self, tree, file_id):
 
190
        BzrNewError.__init__(self)
 
191
        self.file_id = file_id
 
192
        self.tree = tree
 
193
 
 
194
 
177
195
class NoWorkingTree(BzrNewError):
178
196
    """No WorkingTree exists for %(base)s."""
179
197
    
182
200
        self.base = base
183
201
 
184
202
 
 
203
class NotBuilding(BzrNewError):
 
204
    """Not currently building a tree."""
 
205
 
 
206
 
185
207
class NotLocalUrl(BzrNewError):
186
208
    """%(url)s is not a local path."""
187
209
    
265
287
 
266
288
    def __init__(self, msg, base, args):
267
289
        PathError.__init__(self, base, msg)
268
 
        self.args = [base]
269
 
        self.args.extend(args)
 
290
        self.args = [base] + list(args)
270
291
 
271
292
 
272
293
class UnsupportedProtocol(PathError):
276
297
        PathError.__init__(self, url, extra=extra)
277
298
 
278
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
 
279
312
class PathNotChild(BzrNewError):
280
313
    """Path %(path)r is not a child of path %(base)r%(extra)s"""
281
314
 
365
398
        self.bzrdir = bzrdir_format
366
399
 
367
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
 
368
409
class NotVersionedError(BzrNewError):
369
410
    """%(path)s is not versioned"""
370
411
    def __init__(self, path):
781
822
        BzrNewError.__init__(self)
782
823
 
783
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
 
784
832
# A set of semi-meaningful errors which can be thrown
785
833
class TransportNotPossible(TransportError):
786
 
    """Transport operation not possible: %(msg)s %(orig_error)%"""
 
834
    """Transport operation not possible: %(msg)s %(orig_error)s"""
787
835
 
788
836
 
789
837
class ConnectionError(TransportError):
981
1029
        self.format = format
982
1030
 
983
1031
 
 
1032
class BadConversionTarget(BzrNewError):
 
1033
    """Cannot convert to format %(format)s.  %(problem)s"""
 
1034
 
 
1035
    def __init__(self, problem, format):
 
1036
        BzrNewError.__init__(self)
 
1037
        self.problem = problem
 
1038
        self.format = format
 
1039
 
 
1040
 
984
1041
class NoDiff(BzrNewError):
985
1042
    """Diff is not installed on this machine: %(msg)s"""
986
1043
 
1139
1196
        BzrNewError.__init__(self)
1140
1197
 
1141
1198
 
 
1199
class IncompatibleFormat(BzrNewError):
 
1200
    """Bundle format %(bundle_format)s is incompatible with %(other)s"""
 
1201
 
 
1202
    def __init__(self, bundle_format, other):
 
1203
        BzrNewError.__init__(self)
 
1204
        self.bundle_format = bundle_format
 
1205
        self.other = other
 
1206
 
 
1207
 
 
1208
class BadInventoryFormat(BzrNewError):
 
1209
    """Root class for inventory serialization errors"""
 
1210
 
 
1211
 
 
1212
class UnexpectedInventoryFormat(BadInventoryFormat):
 
1213
    """The inventory was not in the expected format:\n %(msg)s"""
 
1214
 
 
1215
    def __init__(self, msg):
 
1216
        BadInventoryFormat.__init__(self, msg=msg)
 
1217
 
 
1218
 
 
1219
class NoSmartServer(NotBranchError):
 
1220
    """No smart server available at %(url)s"""
 
1221
 
 
1222
    def __init__(self, url):
 
1223
        self.url = url
 
1224
 
 
1225
 
1142
1226
class UnknownSSH(BzrNewError):
1143
1227
    """Unrecognised value for BZR_SSH environment variable: %(vendor)s"""
1144
1228
 
1153
1237
    def __init__(self, revision_id):
1154
1238
        BzrNewError.__init__(self)
1155
1239
        self.revision_id = revision_id
 
1240
 
 
1241
 
 
1242
class IllegalUseOfScopeReplacer(BzrNewError):
 
1243
    """ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"""
 
1244
 
 
1245
    is_user_error = False
 
1246
 
 
1247
    def __init__(self, name, msg, extra=None):
 
1248
        BzrNewError.__init__(self)
 
1249
        self.name = name
 
1250
        self.msg = msg
 
1251
        if extra:
 
1252
            self.extra = ': ' + str(extra)
 
1253
        else:
 
1254
            self.extra = ''
 
1255
 
 
1256
 
 
1257
class InvalidImportLine(BzrNewError):
 
1258
    """Not a valid import statement: %(msg)\n%(text)s"""
 
1259
 
 
1260
    is_user_error = False
 
1261
 
 
1262
    def __init__(self, text, msg):
 
1263
        BzrNewError.__init__(self)
 
1264
        self.text = text
 
1265
        self.msg = msg
 
1266
 
 
1267
 
 
1268
class ImportNameCollision(BzrNewError):
 
1269
    """Tried to import an object to the same name as an existing object. %(name)s"""
 
1270
 
 
1271
    is_user_error = False
 
1272
 
 
1273
    def __init__(self, name):
 
1274
        BzrNewError.__init__(self)
 
1275
        self.name = name