~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Robert Collins
  • Date: 2005-10-06 12:14:01 UTC
  • mfrom: (1393.1.67)
  • Revision ID: robertc@robertcollins.net-20051006121401-ce87bcb93909bbdf
merge martins latest

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
######################################################################
23
23
# exceptions 
24
24
class BzrError(StandardError):
25
 
    pass
 
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`
26
41
 
27
42
 
28
43
class BzrCheckError(BzrError):
30
45
 
31
46
 
32
47
class InvalidRevisionNumber(BzrError):
33
 
    def __init__(self, revno):
34
 
        self.args = [revno]
35
 
        
36
48
    def __str__(self):
37
49
        return 'invalid revision number: %r' % self.args[0]
38
50
 
43
55
 
44
56
class BzrCommandError(BzrError):
45
57
    # Error from malformed user command
46
 
    pass
 
58
    def __str__(self):
 
59
        return self.args[0]
47
60
 
48
61
 
49
62
class NotBranchError(BzrError):
50
63
    """Specified path is not in a branch"""
51
 
    pass
 
64
    def __str__(self):
 
65
        return 'not a branch: %s' % self.args[0]
52
66
 
53
67
 
54
68
class NotVersionedError(BzrError):
92
106
        BzrError.__init__(self, msg)
93
107
 
94
108
 
 
109
class HistoryMissing(BzrError):
 
110
    def __init__(self, branch, object_type, object_id):
 
111
        self.branch = branch
 
112
        BzrError.__init__(self,
 
113
                          '%s is missing %s {%s}'
 
114
                          % (branch, object_type, object_id))
 
115
 
 
116
 
95
117
class DivergedBranches(BzrError):
96
118
    def __init__(self, branch1, branch2):
97
119
        BzrError.__init__(self, "These branches have diverged.")
98
120
        self.branch1 = branch1
99
121
        self.branch2 = branch2
100
122
 
 
123
 
101
124
class UnrelatedBranches(BzrCommandError):
102
125
    def __init__(self):
103
126
        msg = "Branches have no common ancestor, and no base revision"\
125
148
        self.not_ancestor_id = not_ancestor_id
126
149
 
127
150
 
 
151
class NotAncestor(BzrError):
 
152
    def __init__(self, rev_id, not_ancestor_id):
 
153
        self.rev_id = rev_id
 
154
        self.not_ancestor_id = not_ancestor_id
 
155
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
 
156
                                                        rev_id)
 
157
        BzrError.__init__(self, msg)
 
158
 
 
159
 
128
160
class InstallFailed(BzrError):
129
161
    def __init__(self, revisions):
130
162
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
143
175
    def __init__(self, branch):
144
176
        msg = "Branch %s has no commits." % branch
145
177
        BzrError.__init__(self, msg)
 
178
 
 
179
class UnlistableStore(BzrError):
 
180
    def __init__(self, store):
 
181
        BzrError.__init__(self, "Store %s is not listable" % store)
 
182
 
 
183
class UnlistableBranch(BzrError):
 
184
    def __init__(self, br):
 
185
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
 
186
 
 
187
 
 
188
from bzrlib.weave import WeaveError
 
189
 
 
190
class TransportError(BzrError):
 
191
    """All errors thrown by Transport implementations should derive
 
192
    from this class.
 
193
    """
 
194
    def __init__(self, msg=None, orig_error=None):
 
195
        if msg is None and orig_error is not None:
 
196
            msg = str(orig_error)
 
197
        BzrError.__init__(self, msg)
 
198
        self.msg = msg
 
199
        self.orig_error = orig_error
 
200
 
 
201
# A set of semi-meaningful errors which can be thrown
 
202
class TransportNotPossible(TransportError):
 
203
    """This is for transports where a specific function is explicitly not
 
204
    possible. Such as pushing files to an HTTP server.
 
205
    """
 
206
    pass
 
207
 
 
208
class NonRelativePath(TransportError):
 
209
    """An absolute path was supplied, that could not be decoded into
 
210
    a relative path.
 
211
    """
 
212
    pass
 
213
 
 
214
class NoSuchFile(TransportError, IOError):
 
215
    """A get() was issued for a file that doesn't exist."""
 
216
 
 
217
    # XXX: Is multiple inheritance for exceptions really needed?
 
218
 
 
219
    def __str__(self):
 
220
        return 'no such file: ' + self.msg
 
221
 
 
222
    def __init__(self, msg=None, orig_error=None):
 
223
        import errno
 
224
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
 
225
        IOError.__init__(self, errno.ENOENT, self.msg)
 
226
 
 
227
class FileExists(TransportError, OSError):
 
228
    """An operation was attempted, which would overwrite an entry,
 
229
    but overwritting is not supported.
 
230
 
 
231
    mkdir() can throw this, but put() just overwites existing files.
 
232
    """
 
233
    # XXX: Is multiple inheritance for exceptions really needed?
 
234
    def __init__(self, msg=None, orig_error=None):
 
235
        import errno
 
236
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
 
237
        OSError.__init__(self, errno.EEXIST, self.msg)
 
238
 
 
239
class PermissionDenied(TransportError):
 
240
    """An operation cannot succeed because of a lack of permissions."""
 
241
    pass
 
242
 
 
243
class ConnectionReset(TransportError):
 
244
    """The connection has been closed."""
 
245
    pass
 
246