~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-31 16:12:57 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060731161257-91a231523255332c
new official bzr.ico

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 '%s.%s' % (sys.exc_type.__module__, sys.exc_type.__name__)
 
47
...   print sys.exc_type
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, *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)
 
123
    def __init__(self, **kwds):
128
124
        for key, value in kwds.items():
129
125
            setattr(self, key, value)
130
126
 
131
127
    def __str__(self):
132
128
        try:
133
 
            # __str__() should always return a 'str' object
134
 
            # never a 'unicode' object.
135
 
            s = self.__doc__ % self.__dict__
136
 
            if isinstance(s, unicode):
137
 
                return s.encode('utf8')
138
 
            return s
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."""
 
129
            return self.__doc__ % self.__dict__
 
130
        except (NameError, ValueError, KeyError), e:
 
131
            return 'Unprintable exception %s: %s' \
 
132
                % (self.__class__.__name__, str(e))
147
133
 
148
134
 
149
135
class BzrCheckError(BzrNewError):
175
161
 
176
162
class InvalidRevisionId(BzrNewError):
177
163
    """Invalid revision-id {%(revision_id)s} in %(branch)s"""
178
 
 
179
164
    def __init__(self, revision_id, branch):
180
165
        # branch can be any string or object with __str__ defined
181
166
        BzrNewError.__init__(self)
183
168
        self.branch = branch
184
169
 
185
170
 
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
 
 
195
171
class NoWorkingTree(BzrNewError):
196
172
    """No WorkingTree exists for %(base)s."""
197
173
    
200
176
        self.base = base
201
177
 
202
178
 
203
 
class NotBuilding(BzrNewError):
204
 
    """Not currently building a tree."""
205
 
 
206
 
 
207
179
class NotLocalUrl(BzrNewError):
208
180
    """%(url)s is not a local path."""
209
181
    
225
197
    # BzrCommandError, and non-UI code should not throw a subclass of
226
198
    # BzrCommandError.  ADHB 20051211
227
199
    def __init__(self, msg):
228
 
        # Object.__str__() must return a real string
229
 
        # returning a Unicode string is a python error.
230
 
        if isinstance(msg, unicode):
231
 
            self.msg = msg.encode('utf8')
232
 
        else:
233
 
            self.msg = msg
 
200
        self.msg = msg
234
201
 
235
202
    def __str__(self):
236
203
        return self.msg
287
254
 
288
255
    def __init__(self, msg, base, args):
289
256
        PathError.__init__(self, base, msg)
290
 
        self.args = [base] + list(args)
 
257
        self.args = [base]
 
258
        self.args.extend(args)
291
259
 
292
260
 
293
261
class UnsupportedProtocol(PathError):
297
265
        PathError.__init__(self, url, extra=extra)
298
266
 
299
267
 
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
 
 
312
268
class PathNotChild(BzrNewError):
313
269
    """Path %(path)r is not a child of path %(base)r%(extra)s"""
314
270
 
348
304
(use bzr checkout if you wish to build a working tree): %(path)s"""
349
305
 
350
306
 
351
 
class AtomicFileAlreadyClosed(PathError):
352
 
    """'%(function)s' called on an AtomicFile after it was closed: %(path)s"""
353
 
 
354
 
    def __init__(self, path, function):
355
 
        PathError.__init__(self, path=path, extra=None)
356
 
        self.function = function
357
 
 
358
 
 
359
 
class InaccessibleParent(PathError):
360
 
    """Parent not accessible given base %(base)s and relative path %(path)s"""
361
 
 
362
 
    def __init__(self, path, base):
363
 
        PathError.__init__(self, path)
364
 
        self.base = base
365
 
 
366
 
 
367
307
class NoRepositoryPresent(BzrNewError):
368
308
    """No repository present: %(path)r"""
369
309
    def __init__(self, bzrdir):
398
338
        self.bzrdir = bzrdir_format
399
339
 
400
340
 
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
 
 
409
341
class NotVersionedError(BzrNewError):
410
342
    """%(path)s is not versioned"""
411
343
    def __init__(self, path):
546
478
        self.format = format
547
479
 
548
480
 
 
481
 
549
482
class StrictCommitFailed(Exception):
550
483
    """Commit refused because there are unknowns in the tree."""
551
484
 
556
489
    is_user_error = False
557
490
 
558
491
    def __init__(self, branch, revision):
559
 
        BzrNewError.__init__(self, branch=branch, revision=revision)
560
 
 
561
 
 
562
 
class NoSuchRevisionSpec(BzrNewError):
563
 
    """No namespace registered for string: %(spec)r"""
564
 
 
565
 
    def __init__(self, spec):
566
 
        BzrNewError.__init__(self, spec=spec)
567
 
 
568
 
 
569
 
class InvalidRevisionSpec(BzrNewError):
570
 
    """Requested revision: '%(spec)s' does not exist in branch:
571
 
%(branch)s%(extra)s"""
572
 
 
573
 
    def __init__(self, spec, branch, extra=None):
574
 
        BzrNewError.__init__(self, branch=branch, spec=spec)
575
 
        if extra:
576
 
            self.extra = '\n' + str(extra)
577
 
        else:
578
 
            self.extra = ''
 
492
        self.branch = branch
 
493
        self.revision = revision
579
494
 
580
495
 
581
496
class HistoryMissing(BzrError):
644
559
        self.bases = bases
645
560
 
646
561
 
647
 
class NoCommits(BzrNewError):
648
 
    """Branch %(branch)s has no commits."""
649
 
 
 
562
class NoCommits(BzrError):
650
563
    def __init__(self, branch):
651
 
        BzrNewError.__init__(self, branch=branch)
 
564
        msg = "Branch %s has no commits." % branch
 
565
        BzrError.__init__(self, msg)
652
566
 
653
567
 
654
568
class UnlistableStore(BzrError):
822
736
        BzrNewError.__init__(self)
823
737
 
824
738
 
825
 
class SmartProtocolError(TransportError):
826
 
    """Generic bzr smart protocol error: %(details)s"""
827
 
 
828
 
    def __init__(self, details):
829
 
        self.details = details
830
 
 
831
 
 
832
739
# A set of semi-meaningful errors which can be thrown
833
740
class TransportNotPossible(TransportError):
834
 
    """Transport operation not possible: %(msg)s %(orig_error)s"""
 
741
    """Transport operation not possible: %(msg)s %(orig_error)%"""
835
742
 
836
743
 
837
744
class ConnectionError(TransportError):
843
750
 
844
751
 
845
752
class InvalidRange(TransportError):
846
 
    """Invalid range access in %(path)s at %(offset)s."""
 
753
    """Invalid range access."""
847
754
    
848
755
    def __init__(self, path, offset):
849
756
        TransportError.__init__(self, ("Invalid range access in %s at %d"
850
757
                                       % (path, offset)))
851
 
        self.path = path
852
 
        self.offset = offset
853
758
 
854
759
 
855
760
class InvalidHttpResponse(TransportError):
1017
922
        DependencyNotPresent.__init__(self, 'paramiko', error)
1018
923
 
1019
924
 
1020
 
class PointlessMerge(BzrNewError):
1021
 
    """Nothing to merge."""
1022
 
 
1023
 
 
1024
925
class UninitializableFormat(BzrNewError):
1025
926
    """Format %(format)s cannot be initialised by this version of bzr."""
1026
927
 
1029
930
        self.format = format
1030
931
 
1031
932
 
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
 
 
1041
933
class NoDiff(BzrNewError):
1042
934
    """Diff is not installed on this machine: %(msg)s"""
1043
935
 
1044
936
    def __init__(self, msg):
1045
 
        BzrNewError.__init__(self, msg=msg)
 
937
        super(NoDiff, self).__init__(msg=msg)
1046
938
 
1047
939
 
1048
940
class NoDiff3(BzrNewError):
1153
1045
    """Not a bzr revision-bundle: %(text)r"""
1154
1046
 
1155
1047
    def __init__(self, text):
1156
 
        BzrNewError.__init__(self)
1157
 
        self.text = text
1158
 
 
1159
 
 
1160
 
class BadBundle(BzrNewError): 
1161
 
    """Bad bzr revision-bundle: %(text)r"""
1162
 
 
1163
 
    def __init__(self, text):
1164
 
        BzrNewError.__init__(self)
1165
 
        self.text = text
1166
 
 
1167
 
 
1168
 
class MalformedHeader(BadBundle): 
1169
 
    """Malformed bzr revision-bundle header: %(text)r"""
1170
 
 
1171
 
    def __init__(self, text):
1172
 
        BzrNewError.__init__(self)
1173
 
        self.text = text
1174
 
 
1175
 
 
1176
 
class MalformedPatches(BadBundle): 
1177
 
    """Malformed patches in bzr revision-bundle: %(text)r"""
1178
 
 
1179
 
    def __init__(self, text):
1180
 
        BzrNewError.__init__(self)
1181
 
        self.text = text
1182
 
 
1183
 
 
1184
 
class MalformedFooter(BadBundle): 
1185
 
    """Malformed footer in bzr revision-bundle: %(text)r"""
1186
 
 
1187
 
    def __init__(self, text):
1188
 
        BzrNewError.__init__(self)
1189
 
        self.text = text
1190
 
 
1191
 
 
1192
 
class UnsupportedEOLMarker(BadBundle):
1193
 
    """End of line marker was not \\n in bzr revision-bundle"""    
1194
 
 
1195
 
    def __init__(self):
1196
 
        BzrNewError.__init__(self)
1197
 
 
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
 
 
1226
 
class UnknownSSH(BzrNewError):
1227
 
    """Unrecognised value for BZR_SSH environment variable: %(vendor)s"""
1228
 
 
1229
 
    def __init__(self, vendor):
1230
 
        BzrNewError.__init__(self)
1231
 
        self.vendor = vendor
1232
 
 
1233
 
 
1234
 
class GhostRevisionUnusableHere(BzrNewError):
1235
 
    """Ghost revision {%(revision_id)s} cannot be used here."""
1236
 
 
1237
 
    def __init__(self, revision_id):
1238
 
        BzrNewError.__init__(self)
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
 
1048
        self.text = text
 
1049
 
 
1050
 
 
1051
class BadBundle(Exception): pass
 
1052
 
 
1053
 
 
1054
class MalformedHeader(BadBundle): pass
 
1055
 
 
1056
 
 
1057
class MalformedPatches(BadBundle): pass
 
1058
 
 
1059
 
 
1060
class MalformedFooter(BadBundle): pass