/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-08 00:32:39 UTC
  • mfrom: (1185.13.4)
  • mto: This revision was merged to the branch mainline in revision 1422.
  • Revision ID: robertc@robertcollins.net-20051008003239-b4e2f1ad62bbe3f6
merge in reweave support

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