~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Martin Pool
  • Date: 2006-03-06 11:20:10 UTC
  • mfrom: (1593 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060306112010-17c0170dde5d1eea
[merge] large merge to sync with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# (C) 2005 Canonical
 
1
# Copyright (C) 2005, 2006 Canonical
2
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
105
105
 
106
106
class BzrCheckError(BzrNewError):
107
107
    """Internal check failed: %(message)s"""
 
108
 
108
109
    def __init__(self, message):
109
110
        BzrNewError.__init__(self)
110
111
        self.message = message
140
141
        self.base = base
141
142
 
142
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
 
143
152
class BzrCommandError(BzrError):
144
153
    # Error from malformed user command
145
154
    # This is being misused as a generic exception
180
189
    """File exists: %(path)r%(extra)s"""
181
190
 
182
191
 
 
192
class DirectoryNotEmpty(PathError):
 
193
    """Directory not empty: %(path)r%(extra)s"""
 
194
 
 
195
 
183
196
class PermissionDenied(PathError):
184
197
    """Permission denied: %(path)r%(extra)s"""
185
198
 
203
216
        self.path = path
204
217
 
205
218
 
 
219
class NoRepositoryPresent(BzrNewError):
 
220
    """Not repository present: %(path)r"""
 
221
    def __init__(self, bzrdir):
 
222
        BzrNewError.__init__(self)
 
223
        self.path = bzrdir.transport.clone('..').base
 
224
 
 
225
 
206
226
class FileInWrongBranch(BzrNewError):
207
227
    """File %(path)s in not in branch %(branch_base)s."""
 
228
 
208
229
    def __init__(self, branch, path):
209
230
        BzrNewError.__init__(self)
210
231
        self.branch = branch
224
245
        return 'unknown branch format: %s' % self.args[0]
225
246
 
226
247
 
 
248
class IncompatibleFormat(BzrNewError):
 
249
    """Format %(format)s is not compatible with .bzr version %(bzrdir)s."""
 
250
 
 
251
    def __init__(self, format, bzrdir_format):
 
252
        BzrNewError.__init__(self)
 
253
        self.format = format
 
254
        self.bzrdir = bzrdir_format
 
255
 
 
256
 
227
257
class NotVersionedError(BzrNewError):
228
258
    """%(path)s is not versioned"""
229
259
    def __init__(self, path):
241
271
    """Cannot operate on a file because it is a control file."""
242
272
 
243
273
 
244
 
class LockError(Exception):
245
 
    """Lock error"""
 
274
class LockError(BzrNewError):
 
275
    """Lock error: %(message)s"""
246
276
    # All exceptions from the lock/unlock functions should be from
247
277
    # this exception class.  They will be translated as necessary. The
248
278
    # original exception is available as e.original_error
 
279
    #
 
280
    # New code should prefer to raise specific subclasses
 
281
    def __init__(self, message):
 
282
        self.message = message
249
283
 
250
284
 
251
285
class CommitNotPossible(LockError):
252
286
    """A commit was attempted but we do not have a write lock open."""
 
287
    def __init__(self):
 
288
        pass
253
289
 
254
290
 
255
291
class AlreadyCommitted(LockError):
256
292
    """A rollback was requested, but is not able to be accomplished."""
 
293
    def __init__(self):
 
294
        pass
257
295
 
258
296
 
259
297
class ReadOnlyError(LockError):
260
 
    """A write attempt was made in a read only transaction."""
 
298
    """A write attempt was made in a read only transaction on %(obj)s"""
 
299
    def __init__(self, obj):
 
300
        self.obj = obj
 
301
 
 
302
 
 
303
class ObjectNotLocked(LockError):
 
304
    """%(obj)r is not locked"""
 
305
    # this can indicate that any particular object is not locked; see also
 
306
    # LockNotHeld which means that a particular *lock* object is not held by
 
307
    # the caller -- perhaps they should be unified.
 
308
    def __init__(self, obj):
 
309
        self.obj = obj
 
310
 
 
311
 
 
312
class ReadOnlyObjectDirtiedError(ReadOnlyError):
 
313
    """Cannot change object %(obj)r in read only transaction"""
 
314
    def __init__(self, obj):
 
315
        self.obj = obj
 
316
 
 
317
 
 
318
class UnlockableTransport(LockError):
 
319
    """Cannot lock: transport is read only: %(transport)s"""
 
320
    def __init__(self, transport):
 
321
        self.transport = transport
 
322
 
 
323
 
 
324
class LockContention(LockError):
 
325
    """Could not acquire lock %(lock)s"""
 
326
    # TODO: show full url for lock, combining the transport and relative bits?
 
327
    def __init__(self, lock):
 
328
        self.lock = lock
 
329
 
 
330
 
 
331
class LockBroken(LockError):
 
332
    """Lock was broken while still open: %(lock)s - check storage consistency!"""
 
333
    def __init__(self, lock):
 
334
        self.lock = lock
 
335
 
 
336
 
 
337
class LockBreakMismatch(LockError):
 
338
    """Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"""
 
339
    def __init__(self, lock, holder, target):
 
340
        self.lock = lock
 
341
        self.holder = holder
 
342
        self.target = target
 
343
 
 
344
 
 
345
class LockNotHeld(LockError):
 
346
    """Lock not held: %(lock)s"""
 
347
    def __init__(self, lock):
 
348
        self.lock = lock
261
349
 
262
350
 
263
351
class PointlessCommit(BzrNewError):
268
356
    """Upgrade URL cannot work with readonly URL's."""
269
357
 
270
358
 
 
359
class UpToDateFormat(BzrNewError):
 
360
    """The branch format %(format)s is already at the most recent format."""
 
361
 
 
362
    def __init__(self, format):
 
363
        BzrNewError.__init__(self)
 
364
        self.format = format
 
365
 
 
366
 
 
367
 
271
368
class StrictCommitFailed(Exception):
272
369
    """Commit refused because there are unknowns in the tree."""
273
370
 
301
398
            " specified."
302
399
        BzrCommandError.__init__(self, msg)
303
400
 
 
401
 
304
402
class NoCommonAncestor(BzrError):
305
403
    def __init__(self, revision_a, revision_b):
306
404
        msg = "Revisions have no common ancestor: %s %s." \
307
405
            % (revision_a, revision_b) 
308
406
        BzrError.__init__(self, msg)
309
407
 
 
408
 
310
409
class NoCommonRoot(BzrError):
311
410
    def __init__(self, revision_a, revision_b):
312
411
        msg = "Revisions are not derived from the same root: %s %s." \
313
412
            % (revision_a, revision_b) 
314
413
        BzrError.__init__(self, msg)
315
414
 
 
415
 
 
416
 
316
417
class NotAncestor(BzrError):
317
418
    def __init__(self, rev_id, not_ancestor_id):
318
419
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
336
437
        BzrError.__init__(self, msg)
337
438
        self.bases = bases
338
439
 
 
440
 
339
441
class NoCommits(BzrError):
340
442
    def __init__(self, branch):
341
443
        msg = "Branch %s has no commits." % branch
342
444
        BzrError.__init__(self, msg)
343
445
 
 
446
 
344
447
class UnlistableStore(BzrError):
345
448
    def __init__(self, store):
346
449
        BzrError.__init__(self, "Store %s is not listable" % store)
347
450
 
 
451
 
 
452
 
348
453
class UnlistableBranch(BzrError):
349
454
    def __init__(self, br):
350
455
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
351
456
 
352
457
 
 
458
class BoundBranchOutOfDate(BzrNewError):
 
459
    """Bound branch %(branch)s is out of date with master branch %(master)s."""
 
460
    def __init__(self, branch, master):
 
461
        BzrNewError.__init__(self)
 
462
        self.branch = branch
 
463
        self.master = master
 
464
 
 
465
        
 
466
class CommitToDoubleBoundBranch(BzrNewError):
 
467
    """Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."""
 
468
    def __init__(self, branch, master, remote):
 
469
        BzrNewError.__init__(self)
 
470
        self.branch = branch
 
471
        self.master = master
 
472
        self.remote = remote
 
473
 
 
474
 
 
475
class OverwriteBoundBranch(BzrNewError):
 
476
    """Cannot pull --overwrite to a branch which is bound %(branch)s"""
 
477
    def __init__(self, branch):
 
478
        BzrNewError.__init__(self)
 
479
        self.branch = branch
 
480
 
 
481
 
 
482
class BoundBranchConnectionFailure(BzrNewError):
 
483
    """Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"""
 
484
    def __init__(self, branch, target, error):
 
485
        BzrNewError.__init__(self)
 
486
        self.branch = branch
 
487
        self.target = target
 
488
        self.error = error
 
489
 
 
490
 
353
491
class WeaveError(BzrNewError):
354
492
    """Error in processing weave: %(message)s"""
355
493
    def __init__(self, message=None):
398
536
        self.weave_b = weave_b
399
537
 
400
538
 
 
539
class WeaveTextDiffers(WeaveError):
 
540
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
 
541
 
 
542
    def __init__(self, revision_id, weave_a, weave_b):
 
543
        WeaveError.__init__(self)
 
544
        self.revision_id = revision_id
 
545
        self.weave_a = weave_a
 
546
        self.weave_b = weave_b
 
547
 
 
548
 
401
549
class NoSuchExportFormat(BzrNewError):
402
550
    """Export format %(format)r not supported"""
403
551
    def __init__(self, format):
416
564
        self.msg = msg
417
565
        self.orig_error = orig_error
418
566
 
 
567
 
419
568
# A set of semi-meaningful errors which can be thrown
420
569
class TransportNotPossible(TransportError):
421
570
    """This is for transports where a specific function is explicitly not
437
586
    """The connection has been closed."""
438
587
    pass
439
588
 
 
589
 
440
590
class ConflictsInTree(BzrError):
441
591
    def __init__(self):
442
592
        BzrError.__init__(self, "Working tree has conflicts.")
443
593
 
 
594
 
444
595
class ParseConfigError(BzrError):
445
596
    def __init__(self, errors, filename):
446
597
        if filename is None:
449
600
            (filename, ('\n'.join(e.message for e in errors)))
450
601
        BzrError.__init__(self, message)
451
602
 
 
603
 
452
604
class SigningFailed(BzrError):
453
605
    def __init__(self, command_line):
454
606
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
455
607
                               % command_line)
456
608
 
 
609
 
457
610
class WorkingTreeNotRevision(BzrError):
458
611
    def __init__(self, tree):
459
612
        BzrError.__init__(self, "The working tree for %s has changed since"
460
613
                          " last commit, but weave merge requires that it be"
461
614
                          " unchanged." % tree.basedir)
462
615
 
 
616
 
463
617
class CantReprocessAndShowBase(BzrNewError):
464
618
    """Can't reprocess and show base.
465
619
Reprocessing obscures relationship of conflicting lines to base."""
466
620
 
 
621
 
467
622
class GraphCycleError(BzrNewError):
468
623
    """Cycle in graph %(graph)r"""
469
624
    def __init__(self, graph):
497
652
        self.file_id = file_id
498
653
 
499
654
 
 
655
class DuplicateKey(BzrNewError):
 
656
    """Key %(key)s is already present in map"""
 
657
 
 
658
 
 
659
class MalformedTransform(BzrNewError):
 
660
    """Tree transform is malformed %(conflicts)r"""
 
661
 
 
662
 
500
663
class BzrBadParameter(BzrNewError):
501
664
    """A bad parameter : %(param)s is not usable.
502
665
    
512
675
    """Parameter %(param)s is neither unicode nor utf8."""
513
676
 
514
677
 
 
678
class ReusingTransform(BzrNewError):
 
679
    """Attempt to reuse a transform that has already been applied."""
 
680
 
 
681
 
 
682
class CantMoveRoot(BzrNewError):
 
683
    """Moving the root directory is not supported at this time"""
 
684
 
 
685
 
515
686
class BzrBadParameterNotString(BzrBadParameter):
516
687
    """Parameter %(param)s is not a string or unicode string."""
517
688
 
518
689
 
 
690
class BzrBadParameterMissing(BzrBadParameter):
 
691
    """Parameter $(param)s is required but not present."""
 
692
 
 
693
 
519
694
class DependencyNotPresent(BzrNewError):
520
695
    """Unable to import library "%(library)s": %(error)s"""
521
696
 
536
711
    def __init__(self, format):
537
712
        BzrNewError.__init__(self)
538
713
        self.format = format
 
714
 
 
715
 
 
716
class NoDiff3(BzrNewError):
 
717
    """Diff3 is not installed on this machine."""
 
718
 
 
719
 
 
720
class ExistingLimbo(BzrNewError):
 
721
    """This tree contains left-over files from a failed operation.
 
722
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
723
    keep, and delete it when you are done.
 
724
    """
 
725
    def __init__(self, limbo_dir):
 
726
       BzrNewError.__init__(self)
 
727
       self.limbo_dir = limbo_dir
 
728
 
 
729
 
 
730
class ImmortalLimbo(BzrNewError):
 
731
    """Unable to delete transform temporary directory $(limbo_dir)s.
 
732
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
733
    keep, and delete it when you are done.
 
734
    """
 
735
    def __init__(self, limbo_dir):
 
736
       BzrNewError.__init__(self)
 
737
       self.limbo_dir = limbo_dir
 
738
 
 
739
 
 
740
class OutOfDateTree(BzrNewError):
 
741
    """Working tree is out of date, please run 'bzr update'."""
 
742
 
 
743
    def __init__(self, tree):
 
744
        BzrNewError.__init__(self)
 
745
        self.tree = tree
 
746
 
 
747
 
 
748
class CorruptRepository(BzrNewError):
 
749
    """An error has been detected in the repository %(repo_path)s.
 
750
Please run bzr reconcile on this repository."""
 
751
 
 
752
    def __init__(self, repo):
 
753
        BzrNewError.__init__(self)
 
754
        self.repo_path = repo.bzrdir.root_transport.base
 
755
 
 
756
 
 
757
class UpgradeRequired(BzrNewError):
 
758
    """To use this feature you must upgrade your branch at %(path)s."""
 
759
 
 
760
    def __init__(self, path):
 
761
        BzrNewError.__init__(self)
 
762
        self.path = path
 
763
 
 
764
 
 
765
class LocalRequiresBoundBranch(BzrNewError):
 
766
    """Cannot perform local-only commits on unbound branches."""