~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

 * bzr add now lists how many files were ignored per glob.  add --verbose
   lists the specific files.  (Aaron Bentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical
 
1
# (C) 2005 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
34
34
... except:
35
35
...   print sys.exc_type
36
36
...   print sys.exc_value
37
 
...   path = getattr(sys.exc_value, 'path')
38
 
...   if path is not None:
39
 
...     print path
 
37
...   print sys.exc_value.path
40
38
bzrlib.errors.NotBranchError
41
39
Not a branch: /foo/bar
42
40
/foo/bar
105
103
 
106
104
class BzrCheckError(BzrNewError):
107
105
    """Internal check failed: %(message)s"""
108
 
 
109
106
    def __init__(self, message):
110
107
        BzrNewError.__init__(self)
111
108
        self.message = message
141
138
        self.base = base
142
139
 
143
140
 
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
 
 
152
141
class BzrCommandError(BzrError):
153
142
    # Error from malformed user command
154
143
    # This is being misused as a generic exception
189
178
    """File exists: %(path)r%(extra)s"""
190
179
 
191
180
 
192
 
class DirectoryNotEmpty(PathError):
193
 
    """Directory not empty: %(path)r%(extra)s"""
194
 
 
195
 
 
196
181
class PermissionDenied(PathError):
197
182
    """Permission denied: %(path)r%(extra)s"""
198
183
 
216
201
        self.path = path
217
202
 
218
203
 
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
 
 
226
204
class FileInWrongBranch(BzrNewError):
227
205
    """File %(path)s in not in branch %(branch_base)s."""
228
 
 
229
206
    def __init__(self, branch, path):
230
207
        BzrNewError.__init__(self)
231
208
        self.branch = branch
234
211
 
235
212
 
236
213
class UnsupportedFormatError(BzrError):
237
 
    """Specified path is a bzr branch that we recognize but cannot read."""
 
214
    """Specified path is a bzr branch that we cannot read."""
238
215
    def __str__(self):
239
216
        return 'unsupported branch format: %s' % self.args[0]
240
217
 
241
218
 
242
 
class UnknownFormatError(BzrError):
243
 
    """Specified path is a bzr branch whose format we do not recognize."""
244
 
    def __str__(self):
245
 
        return 'unknown branch format: %s' % self.args[0]
246
 
 
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
 
 
257
219
class NotVersionedError(BzrNewError):
258
220
    """%(path)s is not versioned"""
259
221
    def __init__(self, path):
271
233
    """Cannot operate on a file because it is a control file."""
272
234
 
273
235
 
274
 
class LockError(BzrNewError):
275
 
    """Lock error: %(message)s"""
 
236
class LockError(Exception):
 
237
    """Lock error"""
276
238
    # All exceptions from the lock/unlock functions should be from
277
239
    # this exception class.  They will be translated as necessary. The
278
240
    # 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
283
241
 
284
242
 
285
243
class CommitNotPossible(LockError):
286
244
    """A commit was attempted but we do not have a write lock open."""
287
 
    def __init__(self):
288
 
        pass
289
245
 
290
246
 
291
247
class AlreadyCommitted(LockError):
292
248
    """A rollback was requested, but is not able to be accomplished."""
293
 
    def __init__(self):
294
 
        pass
295
249
 
296
250
 
297
251
class ReadOnlyError(LockError):
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 BranchNotLocked(LockError):
304
 
    """Branch %(branch)r is not locked"""
305
 
    def __init__(self, branch):
306
 
        # XXX: sometimes called with a LockableFiles instance not a Branch
307
 
        self.branch = branch
308
 
 
309
 
 
310
 
class ReadOnlyObjectDirtiedError(ReadOnlyError):
311
 
    """Cannot change object %(obj)r in read only transaction"""
312
 
    def __init__(self, obj):
313
 
        self.obj = obj
314
 
 
315
 
 
316
 
class UnlockableTransport(LockError):
317
 
    """Cannot lock: transport is read only: %(transport)s"""
318
 
    def __init__(self, transport):
319
 
        self.transport = transport
320
 
 
321
 
 
322
 
class LockContention(LockError):
323
 
    """Could not acquire lock %(lock)s"""
324
 
    # TODO: show full url for lock, combining the transport and relative bits?
325
 
    def __init__(self, lock):
326
 
        self.lock = lock
327
 
 
328
 
 
329
 
class LockBroken(LockError):
330
 
    """Lock was broken while still open: %(lock)s - check storage consistency!"""
331
 
    def __init__(self, lock):
332
 
        self.lock = lock
333
 
 
334
 
 
335
 
class LockBreakMismatch(LockError):
336
 
    """Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"""
337
 
    def __init__(self, lock, holder, target):
338
 
        self.lock = lock
339
 
        self.holder = holder
340
 
        self.target = target
341
 
 
342
 
 
343
 
class LockNotHeld(LockError):
344
 
    """Lock not held: %(lock)s"""
345
 
    def __init__(self, lock):
346
 
        self.lock = lock
347
 
 
348
 
 
349
 
class BranchNotLocked(LockError):
350
 
    """Branch %(branch)r not locked"""
351
 
    def __init__(self, branch):
352
 
        self.branch = branch
 
252
    """A write attempt was made in a read only transaction."""
353
253
 
354
254
 
355
255
class PointlessCommit(BzrNewError):
356
256
    """No changes to commit"""
357
257
 
358
 
 
359
 
class UpgradeReadonly(BzrNewError):
360
 
    """Upgrade URL cannot work with readonly URL's."""
361
 
 
362
 
 
363
 
class UpToDateFormat(BzrNewError):
364
 
    """The branch format %(format)s is already at the most recent format."""
365
 
 
366
 
    def __init__(self, format):
367
 
        BzrNewError.__init__(self)
368
 
        self.format = format
369
 
 
370
 
 
371
258
class StrictCommitFailed(Exception):
372
259
    """Commit refused because there are unknowns in the tree."""
373
260
 
400
287
            " specified."
401
288
        BzrCommandError.__init__(self, msg)
402
289
 
403
 
 
404
290
class NoCommonAncestor(BzrError):
405
291
    def __init__(self, revision_a, revision_b):
406
292
        msg = "Revisions have no common ancestor: %s %s." \
407
293
            % (revision_a, revision_b) 
408
294
        BzrError.__init__(self, msg)
409
295
 
410
 
 
411
296
class NoCommonRoot(BzrError):
412
297
    def __init__(self, revision_a, revision_b):
413
298
        msg = "Revisions are not derived from the same root: %s %s." \
414
299
            % (revision_a, revision_b) 
415
300
        BzrError.__init__(self, msg)
416
301
 
417
 
 
418
302
class NotAncestor(BzrError):
419
303
    def __init__(self, rev_id, not_ancestor_id):
420
304
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
438
322
        BzrError.__init__(self, msg)
439
323
        self.bases = bases
440
324
 
441
 
 
442
325
class NoCommits(BzrError):
443
326
    def __init__(self, branch):
444
327
        msg = "Branch %s has no commits." % branch
445
328
        BzrError.__init__(self, msg)
446
329
 
447
 
 
448
330
class UnlistableStore(BzrError):
449
331
    def __init__(self, store):
450
332
        BzrError.__init__(self, "Store %s is not listable" % store)
451
333
 
452
 
 
453
334
class UnlistableBranch(BzrError):
454
335
    def __init__(self, br):
455
336
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
489
370
    """Parents are mismatched between two revisions."""
490
371
    
491
372
 
492
 
class WeaveInvalidChecksum(WeaveError):
493
 
    """Text did not match it's checksum: %(message)s"""
494
 
 
495
 
 
496
 
class WeaveTextDiffers(WeaveError):
497
 
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
498
 
 
499
 
    def __init__(self, revision_id, weave_a, weave_b):
500
 
        WeaveError.__init__(self)
501
 
        self.revision_id = revision_id
502
 
        self.weave_a = weave_a
503
 
        self.weave_b = weave_b
504
 
 
505
 
 
506
 
class WeaveTextDiffers(WeaveError):
507
 
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
508
 
 
509
 
    def __init__(self, revision_id, weave_a, weave_b):
510
 
        WeaveError.__init__(self)
511
 
        self.revision_id = revision_id
512
 
        self.weave_a = weave_a
513
 
        self.weave_b = weave_b
514
 
 
515
 
 
516
373
class NoSuchExportFormat(BzrNewError):
517
374
    """Export format %(format)r not supported"""
518
375
    def __init__(self, format):
531
388
        self.msg = msg
532
389
        self.orig_error = orig_error
533
390
 
534
 
 
535
391
# A set of semi-meaningful errors which can be thrown
536
392
class TransportNotPossible(TransportError):
537
393
    """This is for transports where a specific function is explicitly not
553
409
    """The connection has been closed."""
554
410
    pass
555
411
 
556
 
 
557
412
class ConflictsInTree(BzrError):
558
413
    def __init__(self):
559
414
        BzrError.__init__(self, "Working tree has conflicts.")
560
415
 
561
 
 
562
416
class ParseConfigError(BzrError):
563
417
    def __init__(self, errors, filename):
564
418
        if filename is None:
567
421
            (filename, ('\n'.join(e.message for e in errors)))
568
422
        BzrError.__init__(self, message)
569
423
 
570
 
 
571
424
class SigningFailed(BzrError):
572
425
    def __init__(self, command_line):
573
426
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
574
427
                               % command_line)
575
428
 
576
 
 
577
429
class WorkingTreeNotRevision(BzrError):
578
430
    def __init__(self, tree):
579
431
        BzrError.__init__(self, "The working tree for %s has changed since"
580
432
                          " last commit, but weave merge requires that it be"
581
433
                          " unchanged." % tree.basedir)
582
434
 
583
 
 
584
435
class CantReprocessAndShowBase(BzrNewError):
585
436
    """Can't reprocess and show base.
586
437
Reprocessing obscures relationship of conflicting lines to base."""
587
438
 
588
 
 
589
439
class GraphCycleError(BzrNewError):
590
440
    """Cycle in graph %(graph)r"""
591
441
    def __init__(self, graph):
592
442
        BzrNewError.__init__(self)
593
443
        self.graph = graph
594
444
 
595
 
 
596
445
class NotConflicted(BzrNewError):
597
446
    """File %(filename)s is not conflicted."""
598
 
 
599
447
    def __init__(self, filename):
600
448
        BzrNewError.__init__(self)
601
449
        self.filename = filename
602
450
 
603
 
 
604
451
class MustUseDecorated(Exception):
605
452
    """A decorating function has requested its original command be used.
606
453
    
607
454
    This should never escape bzr, so does not need to be printable.
608
455
    """
609
456
 
610
 
 
611
457
class MissingText(BzrNewError):
612
458
    """Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"""
613
 
 
614
459
    def __init__(self, branch, text_revision, file_id):
615
 
        BzrNewError.__init__(self)
616
460
        self.branch = branch
617
461
        self.base = branch.base
618
462
        self.text_revision = text_revision
619
463
        self.file_id = file_id
620
 
 
621
 
class DuplicateKey(BzrNewError):
622
 
    """Key %(key)s is already present in map"""
623
 
 
624
 
class MalformedTransform(BzrNewError):
625
 
    """Tree transform is malformed %(conflicts)r"""
626
 
 
627
 
 
628
 
class BzrBadParameter(BzrNewError):
629
 
    """A bad parameter : %(param)s is not usable.
630
 
    
631
 
    This exception should never be thrown, but it is a base class for all
632
 
    parameter-to-function errors.
633
 
    """
634
 
    def __init__(self, param):
635
 
        BzrNewError.__init__(self)
636
 
        self.param = param
637
 
 
638
 
 
639
 
class BzrBadParameterNotUnicode(BzrBadParameter):
640
 
    """Parameter %(param)s is neither unicode nor utf8."""
641
 
 
642
 
 
643
 
class ReusingTransform(BzrNewError):
644
 
    """Attempt to reuse a transform that has already been applied."""
645
 
 
646
 
 
647
 
class CantMoveRoot(BzrNewError):
648
 
    """Moving the root directory is not supported at this time"""
649
 
 
650
 
 
651
 
class BzrBadParameterNotString(BzrBadParameter):
652
 
    """Parameter %(param)s is not a string or unicode string."""
653
 
 
654
 
 
655
 
class BzrBadParameterMissing(BzrBadParameter):
656
 
    """Parameter $(param)s is required but not present."""
657
 
 
658
 
 
659
 
class DependencyNotPresent(BzrNewError):
660
 
    """Unable to import library: %(library)s, %(error)s"""
661
 
 
662
 
    def __init__(self, library, error):
663
 
        BzrNewError.__init__(self, library=library, error=error)
664
 
 
665
 
 
666
 
class ParamikoNotPresent(DependencyNotPresent):
667
 
    """Unable to import paramiko (required for sftp support): %(error)s"""
668
 
 
669
 
    def __init__(self, error):
670
 
        DependencyNotPresent.__init__(self, 'paramiko', error)
671
 
 
672
 
 
673
 
class UninitializableFormat(BzrNewError):
674
 
    """Format %(format)s cannot be initialised by this version of bzr."""
675
 
 
676
 
    def __init__(self, format):
677
 
        BzrNewError.__init__(self)
678
 
        self.format = format
679
 
 
680
 
 
681
 
class NoDiff3(BzrNewError):
682
 
    """Diff3 is not installed on this machine."""
683
 
 
684
 
 
685
 
class ExistingLimbo(BzrNewError):
686
 
    """This tree contains left-over files from a failed operation.
687
 
    Please examine %(limbo_dir)s to see if it contains any files you wish to
688
 
    keep, and delete it when you are done.
689
 
    """
690
 
    def __init__(self, limbo_dir):
691
 
       BzrNewError.__init__(self)
692
 
       self.limbo_dir = limbo_dir
693
 
 
694
 
 
695
 
class ImmortalLimbo(BzrNewError):
696
 
    """Unable to delete transform temporary directory $(limbo_dir)s.
697
 
    Please examine %(limbo_dir)s to see if it contains any files you wish to
698
 
    keep, and delete it when you are done.
699
 
    """
700
 
    def __init__(self, limbo_dir):
701
 
       BzrNewError.__init__(self)
702
 
       self.limbo_dir = limbo_dir
703
 
 
704
 
 
705
 
class OutOfDateTree(BzrNewError):
706
 
    """Working tree is out of date, please run 'bzr update'."""
707
 
 
708
 
    def __init__(self, tree):
709
 
        BzrNewError.__init__(self)
710
 
        self.tree = tree