~bzr-pqm/bzr/bzr.dev

1 by mbp at sourcefrog
import from baz patch-364
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
1185.16.51 by Martin Pool
doc
21
# TODO: Change to a standard exception pattern: 
22
#
23
# - docstring of exceptions is a template for formatting the exception
24
#   so the __str__ method can be defined only in the superclass
25
# - the arguments to the exception are interpolated into this string
26
#
27
# when printing the exception we'd then require special handling only
28
# for built-in exceptions with no decent __str__ method, such as 
29
# ValueError and AssertionError.  See 
30
# scott@canonical.com--2005/hct--devel--0.10 util/errors.py
31
1 by mbp at sourcefrog
import from baz patch-364
32
33
######################################################################
34
# exceptions 
35
class BzrError(StandardError):
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
36
    def __str__(self):
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
37
        # XXX: Should we show the exception class in 
38
        # exceptions that don't provide their own message?  
39
        # maybe it should be done at a higher level
40
        ## n = self.__class__.__name__ + ': '
41
        n = ''
1195 by Martin Pool
- better error display
42
        if len(self.args) == 1:
1449 by Robert Collins
teach check about ghosts
43
            return str(self.args[0])
1195 by Martin Pool
- better error display
44
        elif len(self.args) == 2:
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
45
            # further explanation or suggestions
1405 by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave
46
            try:
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
47
                return n + '\n  '.join([self.args[0]] + self.args[1])
1405 by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave
48
            except TypeError:
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
49
                return n + "%r" % self
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
50
        else:
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
51
            return n + `self.args`
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
52
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
53
1 by mbp at sourcefrog
import from baz patch-364
54
class BzrCheckError(BzrError):
55
    pass
56
57
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
58
class InvalidRevisionNumber(BzrError):
59
    def __str__(self):
60
        return 'invalid revision number: %r' % self.args[0]
61
62
63
class InvalidRevisionId(BzrError):
64
    pass
65
66
329 by Martin Pool
- refactor command functions into command classes
67
class BzrCommandError(BzrError):
68
    # Error from malformed user command
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
69
    def __str__(self):
70
        return self.args[0]
1 by mbp at sourcefrog
import from baz patch-364
71
72
573 by Martin Pool
- new exception NotBranchError
73
class NotBranchError(BzrError):
74
    """Specified path is not in a branch"""
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
75
    def __str__(self):
76
        return 'not a branch: %s' % self.args[0]
573 by Martin Pool
- new exception NotBranchError
77
78
1185.1.53 by Robert Collins
raise a specific error on unsupported branches so that they can be distinguished from generic errors
79
class UnsupportedFormatError(BzrError):
80
    """Specified path is a bzr branch that we cannot read."""
81
    def __str__(self):
82
        return 'unsupported branch format: %s' % self.args[0]
83
84
753 by Martin Pool
- new exception NotVersionedError
85
class NotVersionedError(BzrError):
86
    """Specified object is not versioned."""
87
88
599 by Martin Pool
- better error reporting from smart_add
89
class BadFileKindError(BzrError):
90
    """Specified file is of a kind that cannot be added.
91
92
    (For example a symlink or device file.)"""
93
    pass
94
95
96
class ForbiddenFileError(BzrError):
97
    """Cannot operate on a file because it is a control file."""
98
    pass
99
100
614 by Martin Pool
- unify two defintions of LockError
101
class LockError(Exception):
102
    """All exceptions from the lock/unlock functions should be from
103
    this exception class.  They will be translated as necessary. The
104
    original exception is available as e.original_error
105
    """
106
    def __init__(self, e=None):
107
        self.original_error = e
108
        if e:
109
            Exception.__init__(self, e)
110
        else:
111
            Exception.__init__(self)
882 by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this.
112
113
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
114
class CommitNotPossible(LockError):
115
    """A commit was attempted but we do not have a write lock open."""
116
117
118
class AlreadyCommitted(LockError):
119
    """A rollback was requested, but is not able to be accomplished."""
120
121
1417.1.8 by Robert Collins
use transactions in the weave store interface, which enables caching for log
122
class ReadOnlyError(LockError):
123
    """A write attempt was made in a read only transaction."""
124
125
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
126
class PointlessCommit(Exception):
882 by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this.
127
    """Commit failed because nothing was changed."""
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
128
129
130
class NoSuchRevision(BzrError):
131
    def __init__(self, branch, revision):
132
        self.branch = branch
133
        self.revision = revision
134
        msg = "Branch %s has no revision %s" % (branch, revision)
135
        BzrError.__init__(self, msg)
136
1034 by Martin Pool
- merge bzrlib.revision.is_ancestor from aaron
137
1192 by Martin Pool
- clean up code for retrieving stored inventories
138
class HistoryMissing(BzrError):
139
    def __init__(self, branch, object_type, object_id):
140
        self.branch = branch
141
        BzrError.__init__(self,
142
                          '%s is missing %s {%s}'
143
                          % (branch, object_type, object_id))
144
145
1185.2.1 by Lalo Martins
moving DivergedBranches from bzrlib.branch to bzrlib.errors, obeying:
146
class DivergedBranches(BzrError):
147
    def __init__(self, branch1, branch2):
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
148
        BzrError.__init__(self, "These branches have diverged.")
1185.2.1 by Lalo Martins
moving DivergedBranches from bzrlib.branch to bzrlib.errors, obeying:
149
        self.branch1 = branch1
150
        self.branch2 = branch2
151
1390 by Robert Collins
pair programming worx... merge integration and weave
152
1105 by Martin Pool
- expose 'find-merge-base' as a new expert command,
153
class UnrelatedBranches(BzrCommandError):
154
    def __init__(self):
155
        msg = "Branches have no common ancestor, and no base revision"\
156
            " specified."
157
        BzrCommandError.__init__(self, msg)
158
974.1.80 by Aaron Bentley
Improved merge error handling and testing
159
class NoCommonAncestor(BzrError):
160
    def __init__(self, revision_a, revision_b):
161
        msg = "Revisions have no common ancestor: %s %s." \
162
            % (revision_a, revision_b) 
163
        BzrError.__init__(self, msg)
164
165
class NoCommonRoot(BzrError):
166
    def __init__(self, revision_a, revision_b):
167
        msg = "Revisions are not derived from the same root: %s %s." \
168
            % (revision_a, revision_b) 
169
        BzrError.__init__(self, msg)
1105 by Martin Pool
- expose 'find-merge-base' as a new expert command,
170
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
171
class NotAncestor(BzrError):
172
    def __init__(self, rev_id, not_ancestor_id):
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
173
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
174
                                                        rev_id)
175
        BzrError.__init__(self, msg)
176
        self.rev_id = rev_id
177
        self.not_ancestor_id = not_ancestor_id
1185.1.12 by Robert Collins
merge in lsdiff/filterdiff friendliness
178
179
1092.3.4 by Robert Collins
update symlink branch to integration
180
class NotAncestor(BzrError):
181
    def __init__(self, rev_id, not_ancestor_id):
182
        self.rev_id = rev_id
183
        self.not_ancestor_id = not_ancestor_id
184
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
185
                                                        rev_id)
186
        BzrError.__init__(self, msg)
187
188
974.1.30 by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions
189
class InstallFailed(BzrError):
190
    def __init__(self, revisions):
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
191
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
192
        BzrError.__init__(self, msg)
974.1.30 by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions
193
        self.revisions = revisions
1154 by Martin Pool
- fix imports for moved errors
194
195
196
class AmbiguousBase(BzrError):
197
    def __init__(self, bases):
198
        msg = "The correct base is unclear, becase %s are all equally close" %\
199
            ", ".join(bases)
200
        BzrError.__init__(self, msg)
201
        self.bases = bases
202
974.1.80 by Aaron Bentley
Improved merge error handling and testing
203
class NoCommits(BzrError):
204
    def __init__(self, branch):
205
        msg = "Branch %s has no commits." % branch
206
        BzrError.__init__(self, msg)
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
207
208
class UnlistableStore(BzrError):
209
    def __init__(self, store):
210
        BzrError.__init__(self, "Store %s is not listable" % store)
211
212
class UnlistableBranch(BzrError):
213
    def __init__(self, br):
214
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
1392 by Robert Collins
reinstate testfetch test case
215
216
1185.13.4 by Robert Collins
make reweave visible as a weave method, and quickly integrate into fetch
217
from bzrlib.weave import WeaveError, WeaveParentMismatch
1393.2.1 by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still.
218
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
219
class TransportError(BzrError):
220
    """All errors thrown by Transport implementations should derive
221
    from this class.
222
    """
223
    def __init__(self, msg=None, orig_error=None):
224
        if msg is None and orig_error is not None:
225
            msg = str(orig_error)
226
        BzrError.__init__(self, msg)
227
        self.msg = msg
228
        self.orig_error = orig_error
229
230
# A set of semi-meaningful errors which can be thrown
231
class TransportNotPossible(TransportError):
232
    """This is for transports where a specific function is explicitly not
233
    possible. Such as pushing files to an HTTP server.
234
    """
235
    pass
236
237
class NonRelativePath(TransportError):
238
    """An absolute path was supplied, that could not be decoded into
239
    a relative path.
240
    """
241
    pass
242
243
class NoSuchFile(TransportError, IOError):
244
    """A get() was issued for a file that doesn't exist."""
1405 by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave
245
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
246
    # XXX: Is multiple inheritance for exceptions really needed?
247
1405 by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave
248
    def __str__(self):
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
249
        return 'no such file: ' + self.msg
1405 by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave
250
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
251
    def __init__(self, msg=None, orig_error=None):
252
        import errno
253
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
254
        IOError.__init__(self, errno.ENOENT, self.msg)
255
256
class FileExists(TransportError, OSError):
257
    """An operation was attempted, which would overwrite an entry,
258
    but overwritting is not supported.
259
260
    mkdir() can throw this, but put() just overwites existing files.
261
    """
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
262
    # XXX: Is multiple inheritance for exceptions really needed?
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
263
    def __init__(self, msg=None, orig_error=None):
264
        import errno
265
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
266
        OSError.__init__(self, errno.EEXIST, self.msg)
267
268
class PermissionDenied(TransportError):
269
    """An operation cannot succeed because of a lack of permissions."""
270
    pass
271
272
class ConnectionReset(TransportError):
273
    """The connection has been closed."""
274
    pass
275
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
276
class ConflictsInTree(BzrError):
277
    def __init__(self):
278
        BzrError.__init__(self, "Working tree has conflicts.")
1185.12.49 by Aaron Bentley
Switched to ConfigObj
279
280
class ParseConfigError(BzrError):
281
    def __init__(self, errors, filename):
282
        if filename is None:
283
            filename = ""
284
        message = "Error(s) parsing config file %s:\n%s" % \
285
            (filename, ('\n'.join(e.message for e in errors)))
286
        BzrError.__init__(self, message)
1185.12.52 by Aaron Bentley
Merged more config stuff from Robert
287
1442.1.58 by Robert Collins
gpg signing of content
288
class SigningFailed(BzrError):
289
    def __init__(self, command_line):
290
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
291
                               % command_line)