~bzr-pqm/bzr/bzr.dev

« 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 InventoryModified(BzrNewError):
 
187
    """The current inventory for the tree %(tree)r has been modified, so a clean inventory cannot be read without data loss."""
 
188
 
 
189
    def __init__(self, tree):
 
190
        BzrNewError.__init__(self)
 
191
        self.tree = tree
 
192
 
 
193
 
 
194
class NoSuchId(BzrNewError):
 
195
    """The file id %(file_id)s is not present in the tree %(tree)s."""
 
196
    
 
197
    def __init__(self, tree, file_id):
 
198
        BzrNewError.__init__(self)
 
199
        self.file_id = file_id
 
200
        self.tree = tree
 
201
 
 
202
 
177
203
class NoWorkingTree(BzrNewError):
178
204
    """No WorkingTree exists for %(base)s."""
179
205
    
182
208
        self.base = base
183
209
 
184
210
 
 
211
class NotBuilding(BzrNewError):
 
212
    """Not currently building a tree."""
 
213
 
 
214
 
185
215
class NotLocalUrl(BzrNewError):
186
216
    """%(url)s is not a local path."""
187
217
    
190
220
        self.url = url
191
221
 
192
222
 
 
223
class NotWriteLocked(BzrNewError):
 
224
    """%(not_locked)r is not write locked but needs to be."""
 
225
 
 
226
    def __init__(self, not_locked):
 
227
        BzrNewError.__init__(self)
 
228
        self.not_locked = not_locked
 
229
 
 
230
 
193
231
class BzrCommandError(BzrNewError):
194
232
    """Error from user command"""
195
233
 
248
286
    """Directory not empty: %(path)r%(extra)s"""
249
287
 
250
288
 
 
289
class ReadingCompleted(BzrNewError):
 
290
    """The MediumRequest '%(request)s' has already had finish_reading called upon it - the request has been completed and no more data may be read."""
 
291
 
 
292
    is_user_error = False
 
293
 
 
294
    def __init__(self, request):
 
295
        BzrNewError.__init__(self)
 
296
        self.request = request
 
297
 
 
298
 
251
299
class ResourceBusy(PathError):
252
300
    """Device or resource busy: %(path)r%(extra)s"""
253
301
 
265
313
 
266
314
    def __init__(self, msg, base, args):
267
315
        PathError.__init__(self, base, msg)
268
 
        self.args = [base]
269
 
        self.args.extend(args)
 
316
        self.args = [base] + list(args)
270
317
 
271
318
 
272
319
class UnsupportedProtocol(PathError):
276
323
        PathError.__init__(self, url, extra=extra)
277
324
 
278
325
 
 
326
class ShortReadvError(PathError):
 
327
    """readv() read %(actual)s bytes rather than %(length)s bytes at %(offset)s for %(path)s%(extra)s"""
 
328
 
 
329
    is_user_error = False
 
330
 
 
331
    def __init__(self, path, offset, length, actual, extra=None):
 
332
        PathError.__init__(self, path, extra=extra)
 
333
        self.offset = offset
 
334
        self.length = length
 
335
        self.actual = actual
 
336
 
 
337
 
279
338
class PathNotChild(BzrNewError):
280
339
    """Path %(path)r is not a child of path %(base)r%(extra)s"""
281
340
 
365
424
        self.bzrdir = bzrdir_format
366
425
 
367
426
 
 
427
class IncompatibleRevision(BzrNewError):
 
428
    """Revision is not compatible with %(repo_format)s"""
 
429
 
 
430
    def __init__(self, repo_format):
 
431
        BzrNewError.__init__(self)
 
432
        self.repo_format = repo_format
 
433
 
 
434
 
368
435
class NotVersionedError(BzrNewError):
369
436
    """%(path)s is not versioned"""
370
437
    def __init__(self, path):
761
828
 
762
829
class NoSuchExportFormat(BzrNewError):
763
830
    """Export format %(format)r not supported"""
 
831
 
764
832
    def __init__(self, format):
765
833
        BzrNewError.__init__(self)
766
834
        self.format = format
767
835
 
768
836
 
 
837
 
 
838
class TooManyConcurrentRequests(BzrNewError):
 
839
    """The medium '%(medium)s' has reached its concurrent request limit. Be sure to finish_writing and finish_reading on the current request that is open."""
 
840
 
 
841
    def __init__(self, medium):
 
842
        BzrNewError.__init__(self)
 
843
        self.medium = medium
 
844
 
 
845
 
769
846
class TransportError(BzrNewError):
770
847
    """Transport error: %(msg)s %(orig_error)s"""
771
848
 
781
858
        BzrNewError.__init__(self)
782
859
 
783
860
 
 
861
class SmartProtocolError(TransportError):
 
862
    """Generic bzr smart protocol error: %(details)s"""
 
863
 
 
864
    def __init__(self, details):
 
865
        self.details = details
 
866
 
 
867
 
784
868
# A set of semi-meaningful errors which can be thrown
785
869
class TransportNotPossible(TransportError):
786
 
    """Transport operation not possible: %(msg)s %(orig_error)%"""
 
870
    """Transport operation not possible: %(msg)s %(orig_error)s"""
787
871
 
788
872
 
789
873
class ConnectionError(TransportError):
842
926
        BzrError.__init__(self, message)
843
927
 
844
928
 
 
929
class NoEmailInUsername(BzrNewError):
 
930
    """%(username)r does not seem to contain a reasonable email address"""
 
931
 
 
932
    def __init__(self, username):
 
933
        BzrNewError.__init__(self)
 
934
        self.username = username
 
935
 
 
936
 
845
937
class SigningFailed(BzrError):
846
938
    def __init__(self, command_line):
847
939
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
855
947
                          " unchanged." % tree.basedir)
856
948
 
857
949
 
 
950
class WritingCompleted(BzrNewError):
 
951
    """The MediumRequest '%(request)s' has already had finish_writing called upon it - accept bytes may not be called anymore."""
 
952
 
 
953
    is_user_error = False
 
954
 
 
955
    def __init__(self, request):
 
956
        BzrNewError.__init__(self)
 
957
        self.request = request
 
958
 
 
959
 
 
960
class WritingNotComplete(BzrNewError):
 
961
    """The MediumRequest '%(request)s' has not has finish_writing called upon it - until the write phase is complete no data may be read."""
 
962
 
 
963
    is_user_error = False
 
964
 
 
965
    def __init__(self, request):
 
966
        BzrNewError.__init__(self)
 
967
        self.request = request
 
968
 
 
969
 
858
970
class CantReprocessAndShowBase(BzrNewError):
859
971
    """Can't reprocess and show base.
860
972
Reprocessing obscures relationship of conflicting lines to base."""
875
987
        self.filename = filename
876
988
 
877
989
 
 
990
class MediumNotConnected(BzrNewError):
 
991
    """The medium '%(medium)s' is not connected."""
 
992
 
 
993
    def __init__(self, medium):
 
994
        BzrNewError.__init__(self)
 
995
        self.medium = medium
 
996
 
 
997
 
878
998
class MustUseDecorated(Exception):
879
999
    """A decorating function has requested its original command be used.
880
1000
    
916
1036
    """Tree transform is malformed %(conflicts)r"""
917
1037
 
918
1038
 
 
1039
class NoFinalPath(BzrNewError):
 
1040
    """No final name for trans_id %(trans_id)r
 
1041
    file-id: %(file_id)r"
 
1042
    root trans-id: %(root_trans_id)r 
 
1043
    """
 
1044
 
 
1045
    def __init__(self, trans_id, transform):
 
1046
        self.trans_id = trans_id
 
1047
        self.file_id = transform.final_file_id(trans_id)
 
1048
        self.root_trans_id = transform.root
 
1049
 
 
1050
 
919
1051
class BzrBadParameter(BzrNewError):
920
1052
    """A bad parameter : %(param)s is not usable.
921
1053
    
981
1113
        self.format = format
982
1114
 
983
1115
 
 
1116
class BadConversionTarget(BzrNewError):
 
1117
    """Cannot convert to format %(format)s.  %(problem)s"""
 
1118
 
 
1119
    def __init__(self, problem, format):
 
1120
        BzrNewError.__init__(self)
 
1121
        self.problem = problem
 
1122
        self.format = format
 
1123
 
 
1124
 
984
1125
class NoDiff(BzrNewError):
985
1126
    """Diff is not installed on this machine: %(msg)s"""
986
1127
 
1139
1280
        BzrNewError.__init__(self)
1140
1281
 
1141
1282
 
 
1283
class IncompatibleFormat(BzrNewError):
 
1284
    """Bundle format %(bundle_format)s is incompatible with %(other)s"""
 
1285
 
 
1286
    def __init__(self, bundle_format, other):
 
1287
        BzrNewError.__init__(self)
 
1288
        self.bundle_format = bundle_format
 
1289
        self.other = other
 
1290
 
 
1291
 
 
1292
class BadInventoryFormat(BzrNewError):
 
1293
    """Root class for inventory serialization errors"""
 
1294
 
 
1295
 
 
1296
class UnexpectedInventoryFormat(BadInventoryFormat):
 
1297
    """The inventory was not in the expected format:\n %(msg)s"""
 
1298
 
 
1299
    def __init__(self, msg):
 
1300
        BadInventoryFormat.__init__(self, msg=msg)
 
1301
 
 
1302
 
 
1303
class NoSmartMedium(BzrNewError):
 
1304
    """The transport '%(transport)s' cannot tunnel the smart protocol."""
 
1305
 
 
1306
    def __init__(self, transport):
 
1307
        BzrNewError.__init__(self)
 
1308
        self.transport = transport
 
1309
 
 
1310
 
 
1311
class NoSmartServer(NotBranchError):
 
1312
    """No smart server available at %(url)s"""
 
1313
 
 
1314
    def __init__(self, url):
 
1315
        self.url = url
 
1316
 
 
1317
 
1142
1318
class UnknownSSH(BzrNewError):
1143
1319
    """Unrecognised value for BZR_SSH environment variable: %(vendor)s"""
1144
1320
 
1153
1329
    def __init__(self, revision_id):
1154
1330
        BzrNewError.__init__(self)
1155
1331
        self.revision_id = revision_id
 
1332
 
 
1333
 
 
1334
class IllegalUseOfScopeReplacer(BzrNewError):
 
1335
    """ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"""
 
1336
 
 
1337
    is_user_error = False
 
1338
 
 
1339
    def __init__(self, name, msg, extra=None):
 
1340
        BzrNewError.__init__(self)
 
1341
        self.name = name
 
1342
        self.msg = msg
 
1343
        if extra:
 
1344
            self.extra = ': ' + str(extra)
 
1345
        else:
 
1346
            self.extra = ''
 
1347
 
 
1348
 
 
1349
class InvalidImportLine(BzrNewError):
 
1350
    """Not a valid import statement: %(msg)\n%(text)s"""
 
1351
 
 
1352
    is_user_error = False
 
1353
 
 
1354
    def __init__(self, text, msg):
 
1355
        BzrNewError.__init__(self)
 
1356
        self.text = text
 
1357
        self.msg = msg
 
1358
 
 
1359
 
 
1360
class ImportNameCollision(BzrNewError):
 
1361
    """Tried to import an object to the same name as an existing object. %(name)s"""
 
1362
 
 
1363
    is_user_error = False
 
1364
 
 
1365
    def __init__(self, name):
 
1366
        BzrNewError.__init__(self)
 
1367
        self.name = name