1
# Copyright (C) 2005, 2006 Canonical
 
 
3
# This program is free software; you can redistribute it and/or modify
 
 
4
# it under the terms of the GNU General Public License as published by
 
 
5
# the Free Software Foundation; either version 2 of the License, or
 
 
6
# (at your option) any later version.
 
 
8
# This program is distributed in the hope that it will be useful,
 
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 
11
# GNU General Public License for more details.
 
 
13
# You should have received a copy of the GNU General Public License
 
 
14
# along with this program; if not, write to the Free Software
 
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
17
"""Exceptions for bzr, and reporting of them.
 
 
19
There are 3 different classes of error:
 
 
21
 * KeyboardInterrupt, and OSError with EPIPE - the program terminates 
 
 
22
   with an appropriate short message
 
 
24
 * User errors, indicating a problem caused by the user such as a bad URL.
 
 
25
   These are printed in a short form.
 
 
27
 * Internal unexpected errors, including most Python builtin errors
 
 
28
   and some raised from inside bzr.  These are printed with a full 
 
 
29
   traceback and an invitation to report the bug.
 
 
31
Exceptions are caught at a high level to report errors to the user, and
 
 
32
might also be caught inside the program.  Therefore it needs to be
 
 
33
possible to convert them to a meaningful string, and also for them to be
 
 
34
interrogated by the program.
 
 
36
Exceptions are defined such that the arguments given to the constructor
 
 
37
are stored in the object as properties of the same name.  When the
 
 
38
object is printed as a string, the doc string of the class is used as
 
 
39
a format string with the property dictionary available to it.
 
 
41
This means that exceptions can used like this:
 
 
45
...   raise NotBranchError(path='/foo/bar')
 
 
47
...   print sys.exc_type
 
 
48
...   print sys.exc_value
 
 
49
...   path = getattr(sys.exc_value, 'path', None)
 
 
50
...   if path is not None:
 
 
52
bzrlib.errors.NotBranchError
 
 
53
Not a branch: /foo/bar
 
 
58
 * create a new exception class for any class of error that can be
 
 
59
   usefully distinguished.  If no callers are likely to want to catch
 
 
60
   one but not another, don't worry about them.
 
 
62
 * the __str__ method should generate something useful; BzrError provides
 
 
63
   a good default implementation
 
 
65
Exception strings should start with a capital letter and should not have a
 
 
69
from warnings import warn
 
 
71
from bzrlib.patches import (PatchSyntax, 
 
 
78
# based on Scott James Remnant's hct error classes
 
 
80
# TODO: is there any value in providing the .args field used by standard
 
 
81
# python exceptions?   A list of values with no names seems less useful 
 
 
84
# TODO: Perhaps convert the exception to a string at the moment it's 
 
 
85
# constructed to make sure it will succeed.  But that says nothing about
 
 
86
# exceptions that are never raised.
 
 
88
# TODO: Convert all the other error classes here to BzrNewError, and eliminate
 
 
91
# TODO: The pattern (from hct) of using classes docstrings as message
 
 
92
# templates is cute but maybe not such a great idea - perhaps should have a
 
 
93
# separate static message_template.
 
 
96
class BzrError(StandardError):
 
 
101
        # XXX: Should we show the exception class in 
 
 
102
        # exceptions that don't provide their own message?  
 
 
103
        # maybe it should be done at a higher level
 
 
104
        ## n = self.__class__.__name__ + ': '
 
 
106
        if len(self.args) == 1:
 
 
107
            return str(self.args[0])
 
 
108
        elif len(self.args) == 2:
 
 
109
            # further explanation or suggestions
 
 
111
                return n + '\n  '.join([self.args[0]] + self.args[1])
 
 
113
                return n + "%r" % self
 
 
115
            return n + `self.args`
 
 
118
class BzrNewError(BzrError):
 
 
120
    # base classes should override the docstring with their human-
 
 
121
    # readable explanation
 
 
123
    def __init__(self, **kwds):
 
 
124
        for key, value in kwds.items():
 
 
125
            setattr(self, key, value)
 
 
129
            # __str__() should always return a 'str' object
 
 
130
            # never a 'unicode' object.
 
 
131
            s = self.__doc__ % self.__dict__
 
 
132
            if isinstance(s, unicode):
 
 
133
                return s.encode('utf8')
 
 
135
        except (NameError, ValueError, KeyError), e:
 
 
136
            return 'Unprintable exception %s: %s' \
 
 
137
                % (self.__class__.__name__, str(e))
 
 
140
class BzrCheckError(BzrNewError):
 
 
141
    """Internal check failed: %(message)s"""
 
 
143
    is_user_error = False
 
 
145
    def __init__(self, message):
 
 
146
        BzrNewError.__init__(self)
 
 
147
        self.message = message
 
 
150
class InvalidEntryName(BzrNewError):
 
 
151
    """Invalid entry name: %(name)s"""
 
 
153
    is_user_error = False
 
 
155
    def __init__(self, name):
 
 
156
        BzrNewError.__init__(self)
 
 
160
class InvalidRevisionNumber(BzrNewError):
 
 
161
    """Invalid revision number %(revno)d"""
 
 
162
    def __init__(self, revno):
 
 
163
        BzrNewError.__init__(self)
 
 
167
class InvalidRevisionId(BzrNewError):
 
 
168
    """Invalid revision-id {%(revision_id)s} in %(branch)s"""
 
 
170
    def __init__(self, revision_id, branch):
 
 
171
        # branch can be any string or object with __str__ defined
 
 
172
        BzrNewError.__init__(self)
 
 
173
        self.revision_id = revision_id
 
 
177
class NoWorkingTree(BzrNewError):
 
 
178
    """No WorkingTree exists for %(base)s."""
 
 
180
    def __init__(self, base):
 
 
181
        BzrNewError.__init__(self)
 
 
185
class NotLocalUrl(BzrNewError):
 
 
186
    """%(url)s is not a local path."""
 
 
188
    def __init__(self, url):
 
 
189
        BzrNewError.__init__(self)
 
 
193
class BzrCommandError(BzrNewError):
 
 
194
    """Error from user command"""
 
 
198
    # Error from malformed user command; please avoid raising this as a
 
 
199
    # generic exception not caused by user input.
 
 
201
    # I think it's a waste of effort to differentiate between errors that
 
 
202
    # are not intended to be caught anyway.  UI code need not subclass
 
 
203
    # BzrCommandError, and non-UI code should not throw a subclass of
 
 
204
    # BzrCommandError.  ADHB 20051211
 
 
205
    def __init__(self, msg):
 
 
206
        # Object.__str__() must return a real string
 
 
207
        # returning a Unicode string is a python error.
 
 
208
        if isinstance(msg, unicode):
 
 
209
            self.msg = msg.encode('utf8')
 
 
217
class BzrOptionError(BzrCommandError):
 
 
218
    """Error in command line options"""
 
 
221
class StrictCommitFailed(BzrNewError):
 
 
222
    """Commit refused because there are unknown files in the tree"""
 
 
225
# XXX: Should be unified with TransportError; they seem to represent the
 
 
227
class PathError(BzrNewError):
 
 
228
    """Generic path error: %(path)r%(extra)s)"""
 
 
230
    def __init__(self, path, extra=None):
 
 
231
        BzrNewError.__init__(self)
 
 
234
            self.extra = ': ' + str(extra)
 
 
239
class NoSuchFile(PathError):
 
 
240
    """No such file: %(path)r%(extra)s"""
 
 
243
class FileExists(PathError):
 
 
244
    """File exists: %(path)r%(extra)s"""
 
 
247
class DirectoryNotEmpty(PathError):
 
 
248
    """Directory not empty: %(path)r%(extra)s"""
 
 
251
class ResourceBusy(PathError):
 
 
252
    """Device or resource busy: %(path)r%(extra)s"""
 
 
255
class PermissionDenied(PathError):
 
 
256
    """Permission denied: %(path)r%(extra)s"""
 
 
259
class InvalidURL(PathError):
 
 
260
    """Invalid url supplied to transport: %(path)r%(extra)s"""
 
 
263
class InvalidURLJoin(PathError):
 
 
264
    """Invalid URL join request: %(args)s%(extra)s"""
 
 
266
    def __init__(self, msg, base, args):
 
 
267
        PathError.__init__(self, base, msg)
 
 
269
        self.args.extend(args)
 
 
272
class UnsupportedProtocol(PathError):
 
 
273
    """Unsupported protocol for url "%(path)s"%(extra)s"""
 
 
275
    def __init__(self, url, extra):
 
 
276
        PathError.__init__(self, url, extra=extra)
 
 
279
class PathNotChild(BzrNewError):
 
 
280
    """Path %(path)r is not a child of path %(base)r%(extra)s"""
 
 
282
    is_user_error = False
 
 
284
    def __init__(self, path, base, extra=None):
 
 
285
        BzrNewError.__init__(self)
 
 
289
            self.extra = ': ' + str(extra)
 
 
294
class InvalidNormalization(PathError):
 
 
295
    """Path %(path)r is not unicode normalized"""
 
 
298
# TODO: This is given a URL; we try to unescape it but doing that from inside
 
 
299
# the exception object is a bit undesirable.
 
 
300
# TODO: Probably this behavior of should be a common superclass 
 
 
301
class NotBranchError(PathError):
 
 
302
    """Not a branch: %(path)s"""
 
 
304
    def __init__(self, path):
 
 
305
       import bzrlib.urlutils as urlutils
 
 
306
       self.path = urlutils.unescape_for_display(path, 'ascii')
 
 
309
class AlreadyBranchError(PathError):
 
 
310
    """Already a branch: %(path)s."""
 
 
313
class BranchExistsWithoutWorkingTree(PathError):
 
 
314
    """Directory contains a branch, but no working tree \
 
 
315
(use bzr checkout if you wish to build a working tree): %(path)s"""
 
 
318
class AtomicFileAlreadyClosed(PathError):
 
 
319
    """'%(function)s' called on an AtomicFile after it was closed: %(path)s"""
 
 
321
    def __init__(self, path, function):
 
 
322
        PathError.__init__(self, path=path, extra=None)
 
 
323
        self.function = function
 
 
326
class InaccessibleParent(PathError):
 
 
327
    """Parent not accessible given base %(base)s and relative path %(path)s"""
 
 
329
    def __init__(self, path, base):
 
 
330
        PathError.__init__(self, path)
 
 
334
class NoRepositoryPresent(BzrNewError):
 
 
335
    """No repository present: %(path)r"""
 
 
336
    def __init__(self, bzrdir):
 
 
337
        BzrNewError.__init__(self)
 
 
338
        self.path = bzrdir.transport.clone('..').base
 
 
341
class FileInWrongBranch(BzrNewError):
 
 
342
    """File %(path)s in not in branch %(branch_base)s."""
 
 
344
    def __init__(self, branch, path):
 
 
345
        BzrNewError.__init__(self)
 
 
347
        self.branch_base = branch.base
 
 
351
class UnsupportedFormatError(BzrNewError):
 
 
352
    """Unsupported branch format: %(format)s"""
 
 
355
class UnknownFormatError(BzrNewError):
 
 
356
    """Unknown branch format: %(format)r"""
 
 
359
class IncompatibleFormat(BzrNewError):
 
 
360
    """Format %(format)s is not compatible with .bzr version %(bzrdir)s."""
 
 
362
    def __init__(self, format, bzrdir_format):
 
 
363
        BzrNewError.__init__(self)
 
 
365
        self.bzrdir = bzrdir_format
 
 
368
class NotVersionedError(BzrNewError):
 
 
369
    """%(path)s is not versioned"""
 
 
370
    def __init__(self, path):
 
 
371
        BzrNewError.__init__(self)
 
 
375
class PathsNotVersionedError(BzrNewError):
 
 
376
    # used when reporting several paths are not versioned
 
 
377
    """Path(s) are not versioned: %(paths_as_string)s"""
 
 
379
    def __init__(self, paths):
 
 
380
        from bzrlib.osutils import quotefn
 
 
381
        BzrNewError.__init__(self)
 
 
383
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
 
 
386
class PathsDoNotExist(BzrNewError):
 
 
387
    """Path(s) do not exist: %(paths_as_string)s"""
 
 
389
    # used when reporting that paths are neither versioned nor in the working
 
 
392
    def __init__(self, paths):
 
 
394
        from bzrlib.osutils import quotefn
 
 
395
        BzrNewError.__init__(self)
 
 
397
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
 
 
400
class BadFileKindError(BzrNewError):
 
 
401
    """Cannot operate on %(filename)s of unsupported kind %(kind)s"""
 
 
404
class ForbiddenControlFileError(BzrNewError):
 
 
405
    """Cannot operate on %(filename)s because it is a control file"""
 
 
408
class LockError(BzrNewError):
 
 
409
    """Lock error: %(message)s"""
 
 
410
    # All exceptions from the lock/unlock functions should be from
 
 
411
    # this exception class.  They will be translated as necessary. The
 
 
412
    # original exception is available as e.original_error
 
 
414
    # New code should prefer to raise specific subclasses
 
 
415
    def __init__(self, message):
 
 
416
        self.message = message
 
 
419
class CommitNotPossible(LockError):
 
 
420
    """A commit was attempted but we do not have a write lock open."""
 
 
425
class AlreadyCommitted(LockError):
 
 
426
    """A rollback was requested, but is not able to be accomplished."""
 
 
431
class ReadOnlyError(LockError):
 
 
432
    """A write attempt was made in a read only transaction on %(obj)s"""
 
 
433
    def __init__(self, obj):
 
 
437
class OutSideTransaction(BzrNewError):
 
 
438
    """A transaction related operation was attempted after the transaction finished."""
 
 
441
class ObjectNotLocked(LockError):
 
 
442
    """%(obj)r is not locked"""
 
 
444
    is_user_error = False
 
 
446
    # this can indicate that any particular object is not locked; see also
 
 
447
    # LockNotHeld which means that a particular *lock* object is not held by
 
 
448
    # the caller -- perhaps they should be unified.
 
 
449
    def __init__(self, obj):
 
 
453
class ReadOnlyObjectDirtiedError(ReadOnlyError):
 
 
454
    """Cannot change object %(obj)r in read only transaction"""
 
 
455
    def __init__(self, obj):
 
 
459
class UnlockableTransport(LockError):
 
 
460
    """Cannot lock: transport is read only: %(transport)s"""
 
 
461
    def __init__(self, transport):
 
 
462
        self.transport = transport
 
 
465
class LockContention(LockError):
 
 
466
    """Could not acquire lock %(lock)s"""
 
 
467
    # TODO: show full url for lock, combining the transport and relative bits?
 
 
468
    def __init__(self, lock):
 
 
472
class LockBroken(LockError):
 
 
473
    """Lock was broken while still open: %(lock)s - check storage consistency!"""
 
 
474
    def __init__(self, lock):
 
 
478
class LockBreakMismatch(LockError):
 
 
479
    """Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"""
 
 
480
    def __init__(self, lock, holder, target):
 
 
486
class LockNotHeld(LockError):
 
 
487
    """Lock not held: %(lock)s"""
 
 
488
    def __init__(self, lock):
 
 
492
class PointlessCommit(BzrNewError):
 
 
493
    """No changes to commit"""
 
 
496
class UpgradeReadonly(BzrNewError):
 
 
497
    """Upgrade URL cannot work with readonly URL's."""
 
 
500
class UpToDateFormat(BzrNewError):
 
 
501
    """The branch format %(format)s is already at the most recent format."""
 
 
503
    def __init__(self, format):
 
 
504
        BzrNewError.__init__(self)
 
 
508
class StrictCommitFailed(Exception):
 
 
509
    """Commit refused because there are unknowns in the tree."""
 
 
512
class NoSuchRevision(BzrNewError):
 
 
513
    """Branch %(branch)s has no revision %(revision)s"""
 
 
515
    is_user_error = False
 
 
517
    def __init__(self, branch, revision):
 
 
518
        BzrNewError.__init__(self, branch=branch, revision=revision)
 
 
521
class NoSuchRevisionSpec(BzrNewError):
 
 
522
    """No namespace registered for string: %(spec)r"""
 
 
524
    def __init__(self, spec):
 
 
525
        BzrNewError.__init__(self, spec=spec)
 
 
528
class InvalidRevisionSpec(BzrNewError):
 
 
529
    """Requested revision: '%(spec)s' does not exist in branch:
 
 
530
%(branch)s%(extra)s"""
 
 
532
    def __init__(self, spec, branch, extra=None):
 
 
533
        BzrNewError.__init__(self, branch=branch, spec=spec)
 
 
535
            self.extra = '\n' + str(extra)
 
 
540
class HistoryMissing(BzrError):
 
 
541
    def __init__(self, branch, object_type, object_id):
 
 
543
        BzrError.__init__(self,
 
 
544
                          '%s is missing %s {%s}'
 
 
545
                          % (branch, object_type, object_id))
 
 
548
class DivergedBranches(BzrNewError):
 
 
549
    "These branches have diverged.  Use the merge command to reconcile them."""
 
 
553
    def __init__(self, branch1, branch2):
 
 
554
        self.branch1 = branch1
 
 
555
        self.branch2 = branch2
 
 
558
class UnrelatedBranches(BzrNewError):
 
 
559
    "Branches have no common ancestor, and no merge base revision was specified."
 
 
564
class NoCommonAncestor(BzrNewError):
 
 
565
    "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
 
 
567
    def __init__(self, revision_a, revision_b):
 
 
568
        self.revision_a = revision_a
 
 
569
        self.revision_b = revision_b
 
 
572
class NoCommonRoot(BzrError):
 
 
573
    def __init__(self, revision_a, revision_b):
 
 
574
        msg = "Revisions are not derived from the same root: %s %s." \
 
 
575
            % (revision_a, revision_b) 
 
 
576
        BzrError.__init__(self, msg)
 
 
580
class NotAncestor(BzrError):
 
 
581
    def __init__(self, rev_id, not_ancestor_id):
 
 
582
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
 
 
584
        BzrError.__init__(self, msg)
 
 
586
        self.not_ancestor_id = not_ancestor_id
 
 
589
class InstallFailed(BzrError):
 
 
590
    def __init__(self, revisions):
 
 
591
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
 
 
592
        BzrError.__init__(self, msg)
 
 
593
        self.revisions = revisions
 
 
596
class AmbiguousBase(BzrError):
 
 
597
    def __init__(self, bases):
 
 
598
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
 
600
        msg = "The correct base is unclear, because %s are all equally close" %\
 
 
602
        BzrError.__init__(self, msg)
 
 
606
class NoCommits(BzrNewError):
 
 
607
    """Branch %(branch)s has no commits."""
 
 
609
    def __init__(self, branch):
 
 
610
        BzrNewError.__init__(self, branch=branch)
 
 
613
class UnlistableStore(BzrError):
 
 
614
    def __init__(self, store):
 
 
615
        BzrError.__init__(self, "Store %s is not listable" % store)
 
 
619
class UnlistableBranch(BzrError):
 
 
620
    def __init__(self, br):
 
 
621
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
 
 
624
class BoundBranchOutOfDate(BzrNewError):
 
 
625
    """Bound branch %(branch)s is out of date with master branch %(master)s."""
 
 
626
    def __init__(self, branch, master):
 
 
627
        BzrNewError.__init__(self)
 
 
632
class CommitToDoubleBoundBranch(BzrNewError):
 
 
633
    """Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."""
 
 
634
    def __init__(self, branch, master, remote):
 
 
635
        BzrNewError.__init__(self)
 
 
641
class OverwriteBoundBranch(BzrNewError):
 
 
642
    """Cannot pull --overwrite to a branch which is bound %(branch)s"""
 
 
643
    def __init__(self, branch):
 
 
644
        BzrNewError.__init__(self)
 
 
648
class BoundBranchConnectionFailure(BzrNewError):
 
 
649
    """Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"""
 
 
650
    def __init__(self, branch, target, error):
 
 
651
        BzrNewError.__init__(self)
 
 
657
class WeaveError(BzrNewError):
 
 
658
    """Error in processing weave: %(message)s"""
 
 
660
    def __init__(self, message=None):
 
 
661
        BzrNewError.__init__(self)
 
 
662
        self.message = message
 
 
665
class WeaveRevisionAlreadyPresent(WeaveError):
 
 
666
    """Revision {%(revision_id)s} already present in %(weave)s"""
 
 
667
    def __init__(self, revision_id, weave):
 
 
669
        WeaveError.__init__(self)
 
 
670
        self.revision_id = revision_id
 
 
674
class WeaveRevisionNotPresent(WeaveError):
 
 
675
    """Revision {%(revision_id)s} not present in %(weave)s"""
 
 
677
    def __init__(self, revision_id, weave):
 
 
678
        WeaveError.__init__(self)
 
 
679
        self.revision_id = revision_id
 
 
683
class WeaveFormatError(WeaveError):
 
 
684
    """Weave invariant violated: %(what)s"""
 
 
686
    def __init__(self, what):
 
 
687
        WeaveError.__init__(self)
 
 
691
class WeaveParentMismatch(WeaveError):
 
 
692
    """Parents are mismatched between two revisions."""
 
 
695
class WeaveInvalidChecksum(WeaveError):
 
 
696
    """Text did not match it's checksum: %(message)s"""
 
 
699
class WeaveTextDiffers(WeaveError):
 
 
700
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
 
 
702
    def __init__(self, revision_id, weave_a, weave_b):
 
 
703
        WeaveError.__init__(self)
 
 
704
        self.revision_id = revision_id
 
 
705
        self.weave_a = weave_a
 
 
706
        self.weave_b = weave_b
 
 
709
class WeaveTextDiffers(WeaveError):
 
 
710
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
 
 
712
    def __init__(self, revision_id, weave_a, weave_b):
 
 
713
        WeaveError.__init__(self)
 
 
714
        self.revision_id = revision_id
 
 
715
        self.weave_a = weave_a
 
 
716
        self.weave_b = weave_b
 
 
719
class VersionedFileError(BzrNewError):
 
 
720
    """Versioned file error."""
 
 
723
class RevisionNotPresent(VersionedFileError):
 
 
724
    """Revision {%(revision_id)s} not present in %(file_id)s."""
 
 
726
    def __init__(self, revision_id, file_id):
 
 
727
        VersionedFileError.__init__(self)
 
 
728
        self.revision_id = revision_id
 
 
729
        self.file_id = file_id
 
 
732
class RevisionAlreadyPresent(VersionedFileError):
 
 
733
    """Revision {%(revision_id)s} already present in %(file_id)s."""
 
 
735
    def __init__(self, revision_id, file_id):
 
 
736
        VersionedFileError.__init__(self)
 
 
737
        self.revision_id = revision_id
 
 
738
        self.file_id = file_id
 
 
741
class KnitError(BzrNewError):
 
 
745
class KnitHeaderError(KnitError):
 
 
746
    """Knit header error: %(badline)r unexpected"""
 
 
748
    def __init__(self, badline):
 
 
749
        KnitError.__init__(self)
 
 
750
        self.badline = badline
 
 
753
class KnitCorrupt(KnitError):
 
 
754
    """Knit %(filename)s corrupt: %(how)s"""
 
 
756
    def __init__(self, filename, how):
 
 
757
        KnitError.__init__(self)
 
 
758
        self.filename = filename
 
 
762
class NoSuchExportFormat(BzrNewError):
 
 
763
    """Export format %(format)r not supported"""
 
 
764
    def __init__(self, format):
 
 
765
        BzrNewError.__init__(self)
 
 
769
class TransportError(BzrNewError):
 
 
770
    """Transport error: %(msg)s %(orig_error)s"""
 
 
772
    def __init__(self, msg=None, orig_error=None):
 
 
773
        if msg is None and orig_error is not None:
 
 
774
            msg = str(orig_error)
 
 
775
        if orig_error is None:
 
 
780
        self.orig_error = orig_error
 
 
781
        BzrNewError.__init__(self)
 
 
784
# A set of semi-meaningful errors which can be thrown
 
 
785
class TransportNotPossible(TransportError):
 
 
786
    """Transport operation not possible: %(msg)s %(orig_error)%"""
 
 
789
class ConnectionError(TransportError):
 
 
790
    """Connection error: %(msg)s %(orig_error)s"""
 
 
793
class ConnectionReset(TransportError):
 
 
794
    """Connection closed: %(msg)s %(orig_error)s"""
 
 
797
class InvalidRange(TransportError):
 
 
798
    """Invalid range access in %(path)s at %(offset)s."""
 
 
800
    def __init__(self, path, offset):
 
 
801
        TransportError.__init__(self, ("Invalid range access in %s at %d"
 
 
807
class InvalidHttpResponse(TransportError):
 
 
808
    """Invalid http response for %(path)s: %(msg)s"""
 
 
810
    def __init__(self, path, msg, orig_error=None):
 
 
812
        TransportError.__init__(self, msg, orig_error=orig_error)
 
 
815
class InvalidHttpRange(InvalidHttpResponse):
 
 
816
    """Invalid http range "%(range)s" for %(path)s: %(msg)s"""
 
 
818
    def __init__(self, path, range, msg):
 
 
820
        InvalidHttpResponse.__init__(self, path, msg)
 
 
823
class InvalidHttpContentType(InvalidHttpResponse):
 
 
824
    """Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s"""
 
 
826
    def __init__(self, path, ctype, msg):
 
 
828
        InvalidHttpResponse.__init__(self, path, msg)
 
 
831
class ConflictsInTree(BzrError):
 
 
833
        BzrError.__init__(self, "Working tree has conflicts.")
 
 
836
class ParseConfigError(BzrError):
 
 
837
    def __init__(self, errors, filename):
 
 
840
        message = "Error(s) parsing config file %s:\n%s" % \
 
 
841
            (filename, ('\n'.join(e.message for e in errors)))
 
 
842
        BzrError.__init__(self, message)
 
 
845
class SigningFailed(BzrError):
 
 
846
    def __init__(self, command_line):
 
 
847
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
 
 
851
class WorkingTreeNotRevision(BzrError):
 
 
852
    def __init__(self, tree):
 
 
853
        BzrError.__init__(self, "The working tree for %s has changed since"
 
 
854
                          " last commit, but weave merge requires that it be"
 
 
855
                          " unchanged." % tree.basedir)
 
 
858
class CantReprocessAndShowBase(BzrNewError):
 
 
859
    """Can't reprocess and show base.
 
 
860
Reprocessing obscures relationship of conflicting lines to base."""
 
 
863
class GraphCycleError(BzrNewError):
 
 
864
    """Cycle in graph %(graph)r"""
 
 
865
    def __init__(self, graph):
 
 
866
        BzrNewError.__init__(self)
 
 
870
class NotConflicted(BzrNewError):
 
 
871
    """File %(filename)s is not conflicted."""
 
 
873
    def __init__(self, filename):
 
 
874
        BzrNewError.__init__(self)
 
 
875
        self.filename = filename
 
 
878
class MustUseDecorated(Exception):
 
 
879
    """A decorating function has requested its original command be used.
 
 
881
    This should never escape bzr, so does not need to be printable.
 
 
885
class NoBundleFound(BzrNewError):
 
 
886
    """No bundle was found in %(filename)s"""
 
 
887
    def __init__(self, filename):
 
 
888
        BzrNewError.__init__(self)
 
 
889
        self.filename = filename
 
 
892
class BundleNotSupported(BzrNewError):
 
 
893
    """Unable to handle bundle version %(version)s: %(msg)s"""
 
 
894
    def __init__(self, version, msg):
 
 
895
        BzrNewError.__init__(self)
 
 
896
        self.version = version
 
 
900
class MissingText(BzrNewError):
 
 
901
    """Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"""
 
 
903
    def __init__(self, branch, text_revision, file_id):
 
 
904
        BzrNewError.__init__(self)
 
 
906
        self.base = branch.base
 
 
907
        self.text_revision = text_revision
 
 
908
        self.file_id = file_id
 
 
911
class DuplicateKey(BzrNewError):
 
 
912
    """Key %(key)s is already present in map"""
 
 
915
class MalformedTransform(BzrNewError):
 
 
916
    """Tree transform is malformed %(conflicts)r"""
 
 
919
class BzrBadParameter(BzrNewError):
 
 
920
    """A bad parameter : %(param)s is not usable.
 
 
922
    This exception should never be thrown, but it is a base class for all
 
 
923
    parameter-to-function errors.
 
 
925
    def __init__(self, param):
 
 
926
        BzrNewError.__init__(self)
 
 
930
class BzrBadParameterNotUnicode(BzrBadParameter):
 
 
931
    """Parameter %(param)s is neither unicode nor utf8."""
 
 
934
class ReusingTransform(BzrNewError):
 
 
935
    """Attempt to reuse a transform that has already been applied."""
 
 
938
class CantMoveRoot(BzrNewError):
 
 
939
    """Moving the root directory is not supported at this time"""
 
 
942
class BzrBadParameterNotString(BzrBadParameter):
 
 
943
    """Parameter %(param)s is not a string or unicode string."""
 
 
946
class BzrBadParameterMissing(BzrBadParameter):
 
 
947
    """Parameter $(param)s is required but not present."""
 
 
950
class BzrBadParameterUnicode(BzrBadParameter):
 
 
951
    """Parameter %(param)s is unicode but only byte-strings are permitted."""
 
 
954
class BzrBadParameterContainsNewline(BzrBadParameter):
 
 
955
    """Parameter %(param)s contains a newline."""
 
 
958
class DependencyNotPresent(BzrNewError):
 
 
959
    """Unable to import library "%(library)s": %(error)s"""
 
 
961
    def __init__(self, library, error):
 
 
962
        BzrNewError.__init__(self, library=library, error=error)
 
 
965
class ParamikoNotPresent(DependencyNotPresent):
 
 
966
    """Unable to import paramiko (required for sftp support): %(error)s"""
 
 
968
    def __init__(self, error):
 
 
969
        DependencyNotPresent.__init__(self, 'paramiko', error)
 
 
972
class UninitializableFormat(BzrNewError):
 
 
973
    """Format %(format)s cannot be initialised by this version of bzr."""
 
 
975
    def __init__(self, format):
 
 
976
        BzrNewError.__init__(self)
 
 
980
class NoDiff(BzrNewError):
 
 
981
    """Diff is not installed on this machine: %(msg)s"""
 
 
983
    def __init__(self, msg):
 
 
984
        BzrNewError.__init__(self, msg=msg)
 
 
987
class NoDiff3(BzrNewError):
 
 
988
    """Diff3 is not installed on this machine."""
 
 
991
class ExistingLimbo(BzrNewError):
 
 
992
    """This tree contains left-over files from a failed operation.
 
 
993
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
 
994
    keep, and delete it when you are done.
 
 
996
    def __init__(self, limbo_dir):
 
 
997
       BzrNewError.__init__(self)
 
 
998
       self.limbo_dir = limbo_dir
 
 
1001
class ImmortalLimbo(BzrNewError):
 
 
1002
    """Unable to delete transform temporary directory $(limbo_dir)s.
 
 
1003
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
 
1004
    keep, and delete it when you are done.
 
 
1006
    def __init__(self, limbo_dir):
 
 
1007
       BzrNewError.__init__(self)
 
 
1008
       self.limbo_dir = limbo_dir
 
 
1011
class OutOfDateTree(BzrNewError):
 
 
1012
    """Working tree is out of date, please run 'bzr update'."""
 
 
1014
    def __init__(self, tree):
 
 
1015
        BzrNewError.__init__(self)
 
 
1019
class MergeModifiedFormatError(BzrNewError):
 
 
1020
    """Error in merge modified format"""
 
 
1023
class ConflictFormatError(BzrNewError):
 
 
1024
    """Format error in conflict listings"""
 
 
1027
class CorruptRepository(BzrNewError):
 
 
1028
    """An error has been detected in the repository %(repo_path)s.
 
 
1029
Please run bzr reconcile on this repository."""
 
 
1031
    def __init__(self, repo):
 
 
1032
        BzrNewError.__init__(self)
 
 
1033
        self.repo_path = repo.bzrdir.root_transport.base
 
 
1036
class UpgradeRequired(BzrNewError):
 
 
1037
    """To use this feature you must upgrade your branch at %(path)s."""
 
 
1039
    def __init__(self, path):
 
 
1040
        BzrNewError.__init__(self)
 
 
1044
class LocalRequiresBoundBranch(BzrNewError):
 
 
1045
    """Cannot perform local-only commits on unbound branches."""
 
 
1048
class MissingProgressBarFinish(BzrNewError):
 
 
1049
    """A nested progress bar was not 'finished' correctly."""
 
 
1052
class InvalidProgressBarType(BzrNewError):
 
 
1053
    """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
 
 
1054
Select one of: %(valid_types)s"""
 
 
1056
    def __init__(self, bar_type, valid_types):
 
 
1057
        BzrNewError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
 
1060
class UnsupportedOperation(BzrNewError):
 
 
1061
    """The method %(mname)s is not supported on objects of type %(tname)s."""
 
 
1062
    def __init__(self, method, method_self):
 
 
1063
        self.method = method
 
 
1064
        self.mname = method.__name__
 
 
1065
        self.tname = type(method_self).__name__
 
 
1068
class BinaryFile(BzrNewError):
 
 
1069
    """File is binary but should be text."""
 
 
1072
class IllegalPath(BzrNewError):
 
 
1073
    """The path %(path)s is not permitted on this platform"""
 
 
1075
    def __init__(self, path):
 
 
1076
        BzrNewError.__init__(self)
 
 
1080
class TestamentMismatch(BzrNewError):
 
 
1081
    """Testament did not match expected value.  
 
 
1082
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured 
 
 
1085
    def __init__(self, revision_id, expected, measured):
 
 
1086
        self.revision_id = revision_id
 
 
1087
        self.expected = expected
 
 
1088
        self.measured = measured
 
 
1091
class NotABundle(BzrNewError):
 
 
1092
    """Not a bzr revision-bundle: %(text)r"""
 
 
1094
    def __init__(self, text):
 
 
1095
        BzrNewError.__init__(self)
 
 
1099
class BadBundle(BzrNewError): 
 
 
1100
    """Bad bzr revision-bundle: %(text)r"""
 
 
1102
    def __init__(self, text):
 
 
1103
        BzrNewError.__init__(self)
 
 
1107
class MalformedHeader(BadBundle): 
 
 
1108
    """Malformed bzr revision-bundle header: %(text)r"""
 
 
1110
    def __init__(self, text):
 
 
1111
        BzrNewError.__init__(self)
 
 
1115
class MalformedPatches(BadBundle): 
 
 
1116
    """Malformed patches in bzr revision-bundle: %(text)r"""
 
 
1118
    def __init__(self, text):
 
 
1119
        BzrNewError.__init__(self)
 
 
1123
class MalformedFooter(BadBundle): 
 
 
1124
    """Malformed footer in bzr revision-bundle: %(text)r"""
 
 
1126
    def __init__(self, text):
 
 
1127
        BzrNewError.__init__(self)
 
 
1131
class UnsupportedEOLMarker(BadBundle):
 
 
1132
    """End of line marker was not \\n in bzr revision-bundle"""    
 
 
1135
        BzrNewError.__init__(self)
 
 
1138
class UnknownSSH(BzrNewError):
 
 
1139
    """Unrecognised value for BZR_SSH environment variable: %(vendor)s"""
 
 
1141
    def __init__(self, vendor):
 
 
1142
        BzrNewError.__init__(self)
 
 
1143
        self.vendor = vendor
 
 
1146
class GhostRevisionUnusableHere(BzrNewError):
 
 
1147
    """Ghost revision {%(revision_id)s} cannot be used here."""
 
 
1149
    def __init__(self, revision_id):
 
 
1150
        BzrNewError.__init__(self)
 
 
1151
        self.revision_id = revision_id