~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

Merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
... except:
35
35
...   print sys.exc_type
36
36
...   print sys.exc_value
37
 
...   print sys.exc_value.path
 
37
...   path = getattr(sys.exc_value, 'path')
 
38
...   if path is not None:
 
39
...     print path
38
40
bzrlib.errors.NotBranchError
39
41
Not a branch: /foo/bar
40
42
/foo/bar
142
144
    # Error from malformed user command
143
145
    # This is being misused as a generic exception
144
146
    # pleae subclass. RBC 20051030
 
147
    #
 
148
    # I think it's a waste of effort to differentiate between errors that
 
149
    # are not intended to be caught anyway.  UI code need not subclass
 
150
    # BzrCommandError, and non-UI code should not throw a subclass of
 
151
    # BzrCommandError.  ADHB 20051211
145
152
    def __str__(self):
146
153
        return self.args[0]
147
154
 
153
160
class StrictCommitFailed(Exception):
154
161
    """Commit refused because there are unknowns in the tree."""
155
162
 
 
163
 
 
164
class PathError(BzrNewError):
 
165
    """Generic path error: %(path)r%(extra)s)"""
 
166
    def __init__(self, path, extra=None):
 
167
        BzrNewError.__init__(self)
 
168
        self.path = path
 
169
        if extra:
 
170
            self.extra = ': ' + str(extra)
 
171
        else:
 
172
            self.extra = ''
 
173
 
 
174
 
 
175
class NoSuchFile(PathError):
 
176
    """No such file: %(path)r%(extra)s"""
 
177
 
 
178
 
 
179
class FileExists(PathError):
 
180
    """File exists: %(path)r%(extra)s"""
 
181
 
 
182
 
 
183
class PermissionDenied(PathError):
 
184
    """Permission denied: %(path)r%(extra)s"""
 
185
 
 
186
 
 
187
class PathNotChild(BzrNewError):
 
188
    """Path %(path)r is not a child of path %(base)r%(extra)s"""
 
189
    def __init__(self, path, base, extra=None):
 
190
        BzrNewError.__init__(self)
 
191
        self.path = path
 
192
        self.base = base
 
193
        if extra:
 
194
            self.extra = ': ' + str(extra)
 
195
        else:
 
196
            self.extra = ''
 
197
 
 
198
 
156
199
class NotBranchError(BzrNewError):
157
200
    """Not a branch: %(path)s"""
158
201
    def __init__(self, path):
235
278
 
236
279
class DivergedBranches(BzrError):
237
280
    def __init__(self, branch1, branch2):
238
 
        BzrError.__init__(self, "These branches have diverged.")
 
281
        BzrError.__init__(self, "These branches have diverged.  Try merge.")
239
282
        self.branch1 = branch1
240
283
        self.branch2 = branch2
241
284
 
267
310
        self.not_ancestor_id = not_ancestor_id
268
311
 
269
312
 
270
 
class NotAncestor(BzrError):
271
 
    def __init__(self, rev_id, not_ancestor_id):
272
 
        self.rev_id = rev_id
273
 
        self.not_ancestor_id = not_ancestor_id
274
 
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
275
 
                                                        rev_id)
276
 
        BzrError.__init__(self, msg)
277
 
 
278
 
 
279
313
class InstallFailed(BzrError):
280
314
    def __init__(self, revisions):
281
315
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
338
372
    """Parents are mismatched between two revisions."""
339
373
    
340
374
 
 
375
class WeaveInvalidChecksum(WeaveError):
 
376
    """Text did not match it's checksum: %(message)s"""
 
377
 
 
378
 
 
379
class NoSuchExportFormat(BzrNewError):
 
380
    """Export format %(format)r not supported"""
 
381
    def __init__(self, format):
 
382
        BzrNewError.__init__(self)
 
383
        self.format = format
 
384
 
 
385
 
341
386
class TransportError(BzrError):
342
387
    """All errors thrown by Transport implementations should derive
343
388
    from this class.
356
401
    """
357
402
    pass
358
403
 
359
 
class NonRelativePath(TransportError):
360
 
    """An absolute path was supplied, that could not be decoded into
361
 
    a relative path.
362
 
    """
363
 
    pass
364
 
 
365
 
class NoSuchFile(TransportError, IOError):
366
 
    """A get() was issued for a file that doesn't exist."""
367
 
 
368
 
    # XXX: Is multiple inheritance for exceptions really needed?
369
 
 
370
 
    def __str__(self):
371
 
        return 'no such file: ' + self.msg
372
 
 
373
 
    def __init__(self, msg=None, orig_error=None):
374
 
        import errno
375
 
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
376
 
        IOError.__init__(self, errno.ENOENT, self.msg)
377
 
 
378
 
class ConnectionError(TransportError, IOError):
379
 
    """
380
 
    A connection problem prevents file retrieval.
 
404
 
 
405
class ConnectionError(TransportError):
 
406
    """A connection problem prevents file retrieval.
381
407
    This does not indicate whether the file exists or not; it indicates that a
382
408
    precondition for requesting the file was not met.
383
409
    """
384
 
 
385
 
    # XXX: Is multiple inheritance for exceptions really needed?
386
 
 
387
 
    def __str__(self):
388
 
        return 'connection error: ' + self.msg
389
 
 
390
 
    def __init__(self, msg=None, orig_error=None):
391
 
        import errno
392
 
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
393
 
        IOError.__init__(self, errno.ENOENT, self.msg)
394
 
 
395
 
 
396
 
class FileExists(TransportError, OSError):
397
 
    """An operation was attempted, which would overwrite an entry,
398
 
    but overwritting is not supported.
399
 
 
400
 
    mkdir() can throw this, but put() just overwites existing files.
401
 
    """
402
 
    # XXX: Is multiple inheritance for exceptions really needed?
403
 
    def __init__(self, msg=None, orig_error=None):
404
 
        import errno
405
 
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
406
 
        OSError.__init__(self, errno.EEXIST, self.msg)
407
 
 
408
 
class PermissionDenied(TransportError):
409
 
    """An operation cannot succeed because of a lack of permissions."""
410
 
    pass
 
410
    def __init__(self, msg=None, orig_error=None):
 
411
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
 
412
 
411
413
 
412
414
class ConnectionReset(TransportError):
413
415
    """The connection has been closed."""
446
448
        BzrNewError.__init__(self)
447
449
        self.graph = graph
448
450
 
 
451
 
449
452
class NotConflicted(BzrNewError):
450
453
    """File %(filename)s is not conflicted."""
 
454
 
451
455
    def __init__(self, filename):
452
456
        BzrNewError.__init__(self)
453
457
        self.filename = filename
454
458
 
 
459
 
455
460
class MustUseDecorated(Exception):
456
461
    """A decorating function has requested its original command be used.
457
462
    
460
465
 
461
466
class MissingText(BzrNewError):
462
467
    """Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"""
 
468
 
463
469
    def __init__(self, branch, text_revision, file_id):
 
470
        BzrNewError.__init__(self)
464
471
        self.branch = branch
465
472
        self.base = branch.base
466
473
        self.text_revision = text_revision
467
474
        self.file_id = file_id
 
475
 
 
476
 
 
477
class BzrBadParameter(BzrNewError):
 
478
    """Parameter %(param)s is neither unicode nor utf8."""
 
479
    
 
480
    def __init__(self, param):
 
481
        BzrNewError.__init__(self)
 
482
        self.param = param