/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Robert Collins
  • Date: 2005-10-06 05:13:21 UTC
  • mfrom: (1393.3.3)
  • Revision ID: robertc@robertcollins.net-20051006051321-88f1053c3bf1ca4a
merge in an adjusted version of Jelmer's empty-log detection patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: UTF-8 -*-
 
2
 
 
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.
 
7
 
 
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.
 
12
 
 
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
 
16
 
 
17
 
 
18
__copyright__ = "Copyright (C) 2005 Canonical Ltd."
 
19
__author__ = "Martin Pool <mbp@canonical.com>"
 
20
 
 
21
 
 
22
######################################################################
 
23
# exceptions 
 
24
class BzrError(StandardError):
 
25
    def __str__(self):
 
26
        if len(self.args) == 1:
 
27
            return self.args[0]
 
28
        elif len(self.args) == 2:
 
29
            # further explanation or suggestions
 
30
            try:
 
31
                return '\n  '.join([self.args[0]] + self.args[1])
 
32
            except TypeError:
 
33
                return "%r" % self
 
34
        else:
 
35
            return `self.args`
 
36
 
 
37
 
 
38
class BzrCheckError(BzrError):
 
39
    pass
 
40
 
 
41
 
 
42
class InvalidRevisionNumber(BzrError):
 
43
    def __str__(self):
 
44
        return 'invalid revision number: %r' % self.args[0]
 
45
 
 
46
 
 
47
class InvalidRevisionId(BzrError):
 
48
    pass
 
49
 
 
50
 
 
51
class BzrCommandError(BzrError):
 
52
    # Error from malformed user command
 
53
    pass
 
54
 
 
55
 
 
56
class NotBranchError(BzrError):
 
57
    """Specified path is not in a branch"""
 
58
    pass
 
59
 
 
60
 
 
61
class NotVersionedError(BzrError):
 
62
    """Specified object is not versioned."""
 
63
 
 
64
 
 
65
class BadFileKindError(BzrError):
 
66
    """Specified file is of a kind that cannot be added.
 
67
 
 
68
    (For example a symlink or device file.)"""
 
69
    pass
 
70
 
 
71
 
 
72
class ForbiddenFileError(BzrError):
 
73
    """Cannot operate on a file because it is a control file."""
 
74
    pass
 
75
 
 
76
 
 
77
class LockError(Exception):
 
78
    """All exceptions from the lock/unlock functions should be from
 
79
    this exception class.  They will be translated as necessary. The
 
80
    original exception is available as e.original_error
 
81
    """
 
82
    def __init__(self, e=None):
 
83
        self.original_error = e
 
84
        if e:
 
85
            Exception.__init__(self, e)
 
86
        else:
 
87
            Exception.__init__(self)
 
88
 
 
89
 
 
90
class PointlessCommit(Exception):
 
91
    """Commit failed because nothing was changed."""
 
92
 
 
93
 
 
94
class NoSuchRevision(BzrError):
 
95
    def __init__(self, branch, revision):
 
96
        self.branch = branch
 
97
        self.revision = revision
 
98
        msg = "Branch %s has no revision %s" % (branch, revision)
 
99
        BzrError.__init__(self, msg)
 
100
 
 
101
 
 
102
class HistoryMissing(BzrError):
 
103
    def __init__(self, branch, object_type, object_id):
 
104
        self.branch = branch
 
105
        BzrError.__init__(self,
 
106
                          '%s is missing %s {%s}'
 
107
                          % (branch, object_type, object_id))
 
108
 
 
109
 
 
110
class DivergedBranches(BzrError):
 
111
    def __init__(self, branch1, branch2):
 
112
        BzrError.__init__(self, "These branches have diverged.")
 
113
        self.branch1 = branch1
 
114
        self.branch2 = branch2
 
115
 
 
116
 
 
117
class UnrelatedBranches(BzrCommandError):
 
118
    def __init__(self):
 
119
        msg = "Branches have no common ancestor, and no base revision"\
 
120
            " specified."
 
121
        BzrCommandError.__init__(self, msg)
 
122
 
 
123
class NoCommonAncestor(BzrError):
 
124
    def __init__(self, revision_a, revision_b):
 
125
        msg = "Revisions have no common ancestor: %s %s." \
 
126
            % (revision_a, revision_b) 
 
127
        BzrError.__init__(self, msg)
 
128
 
 
129
class NoCommonRoot(BzrError):
 
130
    def __init__(self, revision_a, revision_b):
 
131
        msg = "Revisions are not derived from the same root: %s %s." \
 
132
            % (revision_a, revision_b) 
 
133
        BzrError.__init__(self, msg)
 
134
 
 
135
class NotAncestor(BzrError):
 
136
    def __init__(self, rev_id, not_ancestor_id):
 
137
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
 
138
                                                        rev_id)
 
139
        BzrError.__init__(self, msg)
 
140
        self.rev_id = rev_id
 
141
        self.not_ancestor_id = not_ancestor_id
 
142
 
 
143
 
 
144
class NotAncestor(BzrError):
 
145
    def __init__(self, rev_id, not_ancestor_id):
 
146
        self.rev_id = rev_id
 
147
        self.not_ancestor_id = not_ancestor_id
 
148
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
 
149
                                                        rev_id)
 
150
        BzrError.__init__(self, msg)
 
151
 
 
152
 
 
153
class InstallFailed(BzrError):
 
154
    def __init__(self, revisions):
 
155
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
 
156
        BzrError.__init__(self, msg)
 
157
        self.revisions = revisions
 
158
 
 
159
 
 
160
class AmbiguousBase(BzrError):
 
161
    def __init__(self, bases):
 
162
        msg = "The correct base is unclear, becase %s are all equally close" %\
 
163
            ", ".join(bases)
 
164
        BzrError.__init__(self, msg)
 
165
        self.bases = bases
 
166
 
 
167
class NoCommits(BzrError):
 
168
    def __init__(self, branch):
 
169
        msg = "Branch %s has no commits." % branch
 
170
        BzrError.__init__(self, msg)
 
171
 
 
172
class UnlistableStore(BzrError):
 
173
    def __init__(self, store):
 
174
        BzrError.__init__(self, "Store %s is not listable" % store)
 
175
 
 
176
class UnlistableBranch(BzrError):
 
177
    def __init__(self, br):
 
178
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
 
179
 
 
180
 
 
181
from bzrlib.weave import WeaveError
 
182
 
 
183
class TransportError(BzrError):
 
184
    """All errors thrown by Transport implementations should derive
 
185
    from this class.
 
186
    """
 
187
    def __init__(self, msg=None, orig_error=None):
 
188
        if msg is None and orig_error is not None:
 
189
            msg = str(orig_error)
 
190
        BzrError.__init__(self, msg)
 
191
        self.msg = msg
 
192
        self.orig_error = orig_error
 
193
 
 
194
# A set of semi-meaningful errors which can be thrown
 
195
class TransportNotPossible(TransportError):
 
196
    """This is for transports where a specific function is explicitly not
 
197
    possible. Such as pushing files to an HTTP server.
 
198
    """
 
199
    pass
 
200
 
 
201
class NonRelativePath(TransportError):
 
202
    """An absolute path was supplied, that could not be decoded into
 
203
    a relative path.
 
204
    """
 
205
    pass
 
206
 
 
207
class NoSuchFile(TransportError, IOError):
 
208
    """A get() was issued for a file that doesn't exist."""
 
209
 
 
210
    def __str__(self):
 
211
        return self.msg
 
212
 
 
213
    def __init__(self, msg=None, orig_error=None):
 
214
        import errno
 
215
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
 
216
        IOError.__init__(self, errno.ENOENT, self.msg)
 
217
 
 
218
class FileExists(TransportError, OSError):
 
219
    """An operation was attempted, which would overwrite an entry,
 
220
    but overwritting is not supported.
 
221
 
 
222
    mkdir() can throw this, but put() just overwites existing files.
 
223
    """
 
224
    def __init__(self, msg=None, orig_error=None):
 
225
        import errno
 
226
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
 
227
        OSError.__init__(self, errno.EEXIST, self.msg)
 
228
 
 
229
class PermissionDenied(TransportError):
 
230
    """An operation cannot succeed because of a lack of permissions."""
 
231
    pass
 
232
 
 
233
class ConnectionReset(TransportError):
 
234
    """The connection has been closed."""
 
235
    pass
 
236