1
# -*- coding: UTF-8 -*-
 
 
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
 
 
18
__copyright__ = "Copyright (C) 2005 Canonical Ltd."
 
 
19
__author__ = "Martin Pool <mbp@canonical.com>"
 
 
22
######################################################################
 
 
24
class BzrError(StandardError):
 
 
26
        if len(self.args) == 1:
 
 
28
        elif len(self.args) == 2:
 
 
29
            # further explanation or suggestions
 
 
30
            return '\n  '.join([self.args[0]] + self.args[1])
 
 
35
class BzrCheckError(BzrError):
 
 
39
class InvalidRevisionNumber(BzrError):
 
 
41
        return 'invalid revision number: %r' % self.args[0]
 
 
44
class InvalidRevisionId(BzrError):
 
 
48
class BzrCommandError(BzrError):
 
 
49
    # Error from malformed user command
 
 
53
class NotBranchError(BzrError):
 
 
54
    """Specified path is not in a branch"""
 
 
58
class NotVersionedError(BzrError):
 
 
59
    """Specified object is not versioned."""
 
 
62
class BadFileKindError(BzrError):
 
 
63
    """Specified file is of a kind that cannot be added.
 
 
65
    (For example a symlink or device file.)"""
 
 
69
class ForbiddenFileError(BzrError):
 
 
70
    """Cannot operate on a file because it is a control file."""
 
 
74
class LockError(Exception):
 
 
75
    """All exceptions from the lock/unlock functions should be from
 
 
76
    this exception class.  They will be translated as necessary. The
 
 
77
    original exception is available as e.original_error
 
 
79
    def __init__(self, e=None):
 
 
80
        self.original_error = e
 
 
82
            Exception.__init__(self, e)
 
 
84
            Exception.__init__(self)
 
 
87
class PointlessCommit(Exception):
 
 
88
    """Commit failed because nothing was changed."""
 
 
91
class NoSuchRevision(BzrError):
 
 
92
    def __init__(self, branch, revision):
 
 
94
        self.revision = revision
 
 
95
        msg = "Branch %s has no revision %s" % (branch, revision)
 
 
96
        BzrError.__init__(self, msg)
 
 
99
class HistoryMissing(BzrError):
 
 
100
    def __init__(self, branch, object_type, object_id):
 
 
102
        BzrError.__init__(self,
 
 
103
                          '%s is missing %s {%s}'
 
 
104
                          % (branch, object_type, object_id))
 
 
107
class DivergedBranches(BzrError):
 
 
108
    def __init__(self, branch1, branch2):
 
 
109
        BzrError.__init__(self, "These branches have diverged.")
 
 
110
        self.branch1 = branch1
 
 
111
        self.branch2 = branch2
 
 
114
class UnrelatedBranches(BzrCommandError):
 
 
116
        msg = "Branches have no common ancestor, and no base revision"\
 
 
118
        BzrCommandError.__init__(self, msg)
 
 
120
class NoCommonAncestor(BzrError):
 
 
121
    def __init__(self, revision_a, revision_b):
 
 
122
        msg = "Revisions have no common ancestor: %s %s." \
 
 
123
            % (revision_a, revision_b) 
 
 
124
        BzrError.__init__(self, msg)
 
 
126
class NoCommonRoot(BzrError):
 
 
127
    def __init__(self, revision_a, revision_b):
 
 
128
        msg = "Revisions are not derived from the same root: %s %s." \
 
 
129
            % (revision_a, revision_b) 
 
 
130
        BzrError.__init__(self, msg)
 
 
132
class NotAncestor(BzrError):
 
 
133
    def __init__(self, rev_id, not_ancestor_id):
 
 
134
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
 
 
136
        BzrError.__init__(self, msg)
 
 
138
        self.not_ancestor_id = not_ancestor_id
 
 
141
class InstallFailed(BzrError):
 
 
142
    def __init__(self, revisions):
 
 
143
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
 
 
144
        BzrError.__init__(self, msg)
 
 
145
        self.revisions = revisions
 
 
148
class AmbiguousBase(BzrError):
 
 
149
    def __init__(self, bases):
 
 
150
        msg = "The correct base is unclear, becase %s are all equally close" %\
 
 
152
        BzrError.__init__(self, msg)
 
 
155
class NoCommits(BzrError):
 
 
156
    def __init__(self, branch):
 
 
157
        msg = "Branch %s has no commits." % branch
 
 
158
        BzrError.__init__(self, msg)