~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Robert Collins
  • Date: 2006-02-15 08:11:37 UTC
  • mto: (1534.1.24 integration)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: robertc@robertcollins.net-20060215081137-4c27377517e96dd1
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.

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
103
105
 
104
106
class BzrCheckError(BzrNewError):
105
107
    """Internal check failed: %(message)s"""
 
108
 
106
109
    def __init__(self, message):
107
110
        BzrNewError.__init__(self)
108
111
        self.message = message
138
141
        self.base = base
139
142
 
140
143
 
 
144
class NotLocalUrl(BzrNewError):
 
145
    """%s(url) is not a local path."""
 
146
    
 
147
    def __init__(self, url):
 
148
        BzrNewError.__init__(self)
 
149
        self.url = url
 
150
 
 
151
 
141
152
class BzrCommandError(BzrError):
142
153
    # Error from malformed user command
143
154
    # This is being misused as a generic exception
144
155
    # pleae subclass. RBC 20051030
 
156
    #
 
157
    # I think it's a waste of effort to differentiate between errors that
 
158
    # are not intended to be caught anyway.  UI code need not subclass
 
159
    # BzrCommandError, and non-UI code should not throw a subclass of
 
160
    # BzrCommandError.  ADHB 20051211
145
161
    def __str__(self):
146
162
        return self.args[0]
147
163
 
153
169
class StrictCommitFailed(Exception):
154
170
    """Commit refused because there are unknowns in the tree."""
155
171
 
 
172
 
 
173
class PathError(BzrNewError):
 
174
    """Generic path error: %(path)r%(extra)s)"""
 
175
    def __init__(self, path, extra=None):
 
176
        BzrNewError.__init__(self)
 
177
        self.path = path
 
178
        if extra:
 
179
            self.extra = ': ' + str(extra)
 
180
        else:
 
181
            self.extra = ''
 
182
 
 
183
 
 
184
class NoSuchFile(PathError):
 
185
    """No such file: %(path)r%(extra)s"""
 
186
 
 
187
 
 
188
class FileExists(PathError):
 
189
    """File exists: %(path)r%(extra)s"""
 
190
 
 
191
 
 
192
class PermissionDenied(PathError):
 
193
    """Permission denied: %(path)r%(extra)s"""
 
194
 
 
195
 
 
196
class PathNotChild(BzrNewError):
 
197
    """Path %(path)r is not a child of path %(base)r%(extra)s"""
 
198
    def __init__(self, path, base, extra=None):
 
199
        BzrNewError.__init__(self)
 
200
        self.path = path
 
201
        self.base = base
 
202
        if extra:
 
203
            self.extra = ': ' + str(extra)
 
204
        else:
 
205
            self.extra = ''
 
206
 
 
207
 
156
208
class NotBranchError(BzrNewError):
157
209
    """Not a branch: %(path)s"""
158
210
    def __init__(self, path):
160
212
        self.path = path
161
213
 
162
214
 
 
215
class NoRepositoryPresent(BzrNewError):
 
216
    """Not repository present: %(path)r"""
 
217
    def __init__(self, bzrdir):
 
218
        BzrNewError.__init__(self)
 
219
        self.path = bzrdir.transport.clone('..').base
 
220
 
 
221
 
163
222
class FileInWrongBranch(BzrNewError):
164
223
    """File %(path)s in not in branch %(branch_base)s."""
 
224
 
165
225
    def __init__(self, branch, path):
166
226
        BzrNewError.__init__(self)
167
227
        self.branch = branch
170
230
 
171
231
 
172
232
class UnsupportedFormatError(BzrError):
173
 
    """Specified path is a bzr branch that we cannot read."""
 
233
    """Specified path is a bzr branch that we recognize but cannot read."""
174
234
    def __str__(self):
175
235
        return 'unsupported branch format: %s' % self.args[0]
176
236
 
177
237
 
 
238
class UnknownFormatError(BzrError):
 
239
    """Specified path is a bzr branch whose format we do not recognize."""
 
240
    def __str__(self):
 
241
        return 'unknown branch format: %s' % self.args[0]
 
242
 
 
243
 
 
244
class IncompatibleFormat(BzrNewError):
 
245
    """Format %(format)s is not compatible with .bzr version %(bzrdir)s."""
 
246
 
 
247
    def __init__(self, format, bzrdir_format):
 
248
        BzrNewError.__init__(self)
 
249
        self.format = format
 
250
        self.bzrdir = bzrdir_format
 
251
 
 
252
 
178
253
class NotVersionedError(BzrNewError):
179
254
    """%(path)s is not versioned"""
180
255
    def __init__(self, path):
214
289
class PointlessCommit(BzrNewError):
215
290
    """No changes to commit"""
216
291
 
 
292
 
 
293
class UpgradeReadonly(BzrNewError):
 
294
    """Upgrade URL cannot work with readonly URL's."""
 
295
 
 
296
 
217
297
class StrictCommitFailed(Exception):
218
298
    """Commit refused because there are unknowns in the tree."""
219
299
 
 
300
 
220
301
class NoSuchRevision(BzrError):
221
302
    def __init__(self, branch, revision):
222
303
        self.branch = branch
235
316
 
236
317
class DivergedBranches(BzrError):
237
318
    def __init__(self, branch1, branch2):
238
 
        BzrError.__init__(self, "These branches have diverged.")
 
319
        BzrError.__init__(self, "These branches have diverged.  Try merge.")
239
320
        self.branch1 = branch1
240
321
        self.branch2 = branch2
241
322
 
246
327
            " specified."
247
328
        BzrCommandError.__init__(self, msg)
248
329
 
 
330
 
249
331
class NoCommonAncestor(BzrError):
250
332
    def __init__(self, revision_a, revision_b):
251
333
        msg = "Revisions have no common ancestor: %s %s." \
252
334
            % (revision_a, revision_b) 
253
335
        BzrError.__init__(self, msg)
254
336
 
 
337
 
255
338
class NoCommonRoot(BzrError):
256
339
    def __init__(self, revision_a, revision_b):
257
340
        msg = "Revisions are not derived from the same root: %s %s." \
258
341
            % (revision_a, revision_b) 
259
342
        BzrError.__init__(self, msg)
260
343
 
261
 
class NotAncestor(BzrError):
262
 
    def __init__(self, rev_id, not_ancestor_id):
263
 
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
264
 
                                                        rev_id)
265
 
        BzrError.__init__(self, msg)
266
 
        self.rev_id = rev_id
267
 
        self.not_ancestor_id = not_ancestor_id
268
 
 
269
 
 
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)
 
344
 
 
345
class NotAncestor(BzrError):
 
346
    def __init__(self, rev_id, not_ancestor_id):
 
347
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
 
348
                                                        rev_id)
 
349
        BzrError.__init__(self, msg)
 
350
        self.rev_id = rev_id
 
351
        self.not_ancestor_id = not_ancestor_id
277
352
 
278
353
 
279
354
class InstallFailed(BzrError):
290
365
        BzrError.__init__(self, msg)
291
366
        self.bases = bases
292
367
 
 
368
 
293
369
class NoCommits(BzrError):
294
370
    def __init__(self, branch):
295
371
        msg = "Branch %s has no commits." % branch
296
372
        BzrError.__init__(self, msg)
297
373
 
 
374
 
298
375
class UnlistableStore(BzrError):
299
376
    def __init__(self, store):
300
377
        BzrError.__init__(self, "Store %s is not listable" % store)
301
378
 
 
379
 
302
380
class UnlistableBranch(BzrError):
303
381
    def __init__(self, br):
304
382
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
338
416
    """Parents are mismatched between two revisions."""
339
417
    
340
418
 
 
419
class WeaveInvalidChecksum(WeaveError):
 
420
    """Text did not match it's checksum: %(message)s"""
 
421
 
 
422
 
 
423
class WeaveTextDiffers(WeaveError):
 
424
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
 
425
 
 
426
    def __init__(self, revision_id, weave_a, weave_b):
 
427
        WeaveError.__init__(self)
 
428
        self.revision_id = revision_id
 
429
        self.weave_a = weave_a
 
430
        self.weave_b = weave_b
 
431
 
 
432
 
 
433
class NoSuchExportFormat(BzrNewError):
 
434
    """Export format %(format)r not supported"""
 
435
    def __init__(self, format):
 
436
        BzrNewError.__init__(self)
 
437
        self.format = format
 
438
 
 
439
 
341
440
class TransportError(BzrError):
342
441
    """All errors thrown by Transport implementations should derive
343
442
    from this class.
349
448
        self.msg = msg
350
449
        self.orig_error = orig_error
351
450
 
 
451
 
352
452
# A set of semi-meaningful errors which can be thrown
353
453
class TransportNotPossible(TransportError):
354
454
    """This is for transports where a specific function is explicitly not
356
456
    """
357
457
    pass
358
458
 
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.
 
459
 
 
460
class ConnectionError(TransportError):
 
461
    """A connection problem prevents file retrieval.
381
462
    This does not indicate whether the file exists or not; it indicates that a
382
463
    precondition for requesting the file was not met.
383
464
    """
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
 
465
    def __init__(self, msg=None, orig_error=None):
 
466
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
 
467
 
411
468
 
412
469
class ConnectionReset(TransportError):
413
470
    """The connection has been closed."""
414
471
    pass
415
472
 
 
473
 
416
474
class ConflictsInTree(BzrError):
417
475
    def __init__(self):
418
476
        BzrError.__init__(self, "Working tree has conflicts.")
419
477
 
 
478
 
420
479
class ParseConfigError(BzrError):
421
480
    def __init__(self, errors, filename):
422
481
        if filename is None:
425
484
            (filename, ('\n'.join(e.message for e in errors)))
426
485
        BzrError.__init__(self, message)
427
486
 
 
487
 
428
488
class SigningFailed(BzrError):
429
489
    def __init__(self, command_line):
430
490
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
431
491
                               % command_line)
432
492
 
 
493
 
433
494
class WorkingTreeNotRevision(BzrError):
434
495
    def __init__(self, tree):
435
496
        BzrError.__init__(self, "The working tree for %s has changed since"
436
497
                          " last commit, but weave merge requires that it be"
437
498
                          " unchanged." % tree.basedir)
438
499
 
 
500
 
439
501
class CantReprocessAndShowBase(BzrNewError):
440
502
    """Can't reprocess and show base.
441
503
Reprocessing obscures relationship of conflicting lines to base."""
442
504
 
 
505
 
443
506
class GraphCycleError(BzrNewError):
444
507
    """Cycle in graph %(graph)r"""
445
508
    def __init__(self, graph):
446
509
        BzrNewError.__init__(self)
447
510
        self.graph = graph
448
511
 
 
512
 
449
513
class NotConflicted(BzrNewError):
450
514
    """File %(filename)s is not conflicted."""
 
515
 
451
516
    def __init__(self, filename):
452
517
        BzrNewError.__init__(self)
453
518
        self.filename = filename
454
519
 
 
520
 
455
521
class MustUseDecorated(Exception):
456
522
    """A decorating function has requested its original command be used.
457
523
    
458
524
    This should never escape bzr, so does not need to be printable.
459
525
    """
460
526
 
 
527
 
461
528
class MissingText(BzrNewError):
462
529
    """Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"""
 
530
 
463
531
    def __init__(self, branch, text_revision, file_id):
 
532
        BzrNewError.__init__(self)
464
533
        self.branch = branch
465
534
        self.base = branch.base
466
535
        self.text_revision = text_revision
467
536
        self.file_id = file_id
 
537
 
 
538
 
 
539
class BzrBadParameter(BzrNewError):
 
540
    """A bad parameter : %(param)s is not usable.
 
541
    
 
542
    This exception should never be thrown, but it is a base class for all
 
543
    parameter-to-function errors.
 
544
    """
 
545
    def __init__(self, param):
 
546
        BzrNewError.__init__(self)
 
547
        self.param = param
 
548
 
 
549
 
 
550
class BzrBadParameterNotUnicode(BzrBadParameter):
 
551
    """Parameter %(param)s is neither unicode nor utf8."""
 
552
 
 
553
 
 
554
class BzrBadParameterNotString(BzrBadParameter):
 
555
    """Parameter %(param)s is not a string or unicode string."""
 
556
 
 
557
 
 
558
class BzrBadParameterMissing(BzrBadParameter):
 
559
    """Parameter $(param)s is required but not present."""
 
560
 
 
561
 
 
562
class DependencyNotPresent(BzrNewError):
 
563
    """Unable to import library: %(library)s, %(error)s"""
 
564
 
 
565
    def __init__(self, library, error):
 
566
        BzrNewError.__init__(self, library=library, error=error)
 
567
 
 
568
 
 
569
class ParamikoNotPresent(DependencyNotPresent):
 
570
    """Unable to import paramiko (required for sftp support): %(error)s"""
 
571
 
 
572
    def __init__(self, error):
 
573
        DependencyNotPresent.__init__(self, 'paramiko', error)
 
574
 
 
575
 
 
576
class UninitializableFormat(BzrNewError):
 
577
    """Format %(format)s cannot be initialised by this version of bzr."""
 
578
 
 
579
    def __init__(self, format):
 
580
        BzrNewError.__init__(self)
 
581
        self.format = format
 
582
 
 
583
 
 
584
class OutOfDateTree(BzrNewError):
 
585
    """Working tree is out of date, please run 'bzr update'."""
 
586
 
 
587
    def __init__(self, tree):
 
588
        BzrNewError.__init__(self)
 
589
        self.tree = tree