~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: mbp at sourcefrog
  • Date: 2005-04-05 08:24:51 UTC
  • Revision ID: mbp@sourcefrog.net-20050405082451-408ebb0fd108440f
start adding quotes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
1
2
# -*- coding: UTF-8 -*-
2
3
 
3
4
# This program is free software; you can redistribute it and/or modify
22
23
######################################################################
23
24
# exceptions 
24
25
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
 
            return '\n  '.join([self.args[0]] + self.args[1])
31
 
        else:
32
 
            return `self.args`
33
 
 
 
26
    pass
34
27
 
35
28
class BzrCheckError(BzrError):
36
29
    pass
37
30
 
38
31
 
39
 
class InvalidRevisionNumber(BzrError):
40
 
    def __str__(self):
41
 
        return 'invalid revision number: %r' % self.args[0]
42
 
 
43
 
 
44
 
class InvalidRevisionId(BzrError):
45
 
    pass
46
 
 
47
 
 
48
 
class BzrCommandError(BzrError):
49
 
    # Error from malformed user command
50
 
    pass
51
 
 
52
 
 
53
 
class NotBranchError(BzrError):
54
 
    """Specified path is not in a branch"""
55
 
    pass
56
 
 
57
 
 
58
 
class NotVersionedError(BzrError):
59
 
    """Specified object is not versioned."""
60
 
 
61
 
 
62
 
class BadFileKindError(BzrError):
63
 
    """Specified file is of a kind that cannot be added.
64
 
 
65
 
    (For example a symlink or device file.)"""
66
 
    pass
67
 
 
68
 
 
69
 
class ForbiddenFileError(BzrError):
70
 
    """Cannot operate on a file because it is a control file."""
71
 
    pass
72
 
 
73
 
 
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
78
 
    """
79
 
    def __init__(self, e=None):
80
 
        self.original_error = e
81
 
        if e:
82
 
            Exception.__init__(self, e)
83
 
        else:
84
 
            Exception.__init__(self)
85
 
 
86
 
 
87
 
class PointlessCommit(Exception):
88
 
    """Commit failed because nothing was changed."""
89
 
 
90
 
 
91
 
class NoSuchRevision(BzrError):
92
 
    def __init__(self, branch, revision):
93
 
        self.branch = branch
94
 
        self.revision = revision
95
 
        msg = "Branch %s has no revision %s" % (branch, revision)
96
 
        BzrError.__init__(self, msg)
97
 
 
98
 
 
99
 
class HistoryMissing(BzrError):
100
 
    def __init__(self, branch, object_type, object_id):
101
 
        self.branch = branch
102
 
        BzrError.__init__(self,
103
 
                          '%s is missing %s {%s}'
104
 
                          % (branch, object_type, object_id))
105
 
 
106
 
 
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
112
 
 
113
 
 
114
 
class UnrelatedBranches(BzrCommandError):
115
 
    def __init__(self):
116
 
        msg = "Branches have no common ancestor, and no base revision"\
117
 
            " specified."
118
 
        BzrCommandError.__init__(self, msg)
119
 
 
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)
125
 
 
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)
131
 
 
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, 
135
 
                                                        rev_id)
136
 
        BzrError.__init__(self, msg)
137
 
        self.rev_id = rev_id
138
 
        self.not_ancestor_id = not_ancestor_id
139
 
 
140
 
 
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
146
 
 
147
 
 
148
 
class AmbiguousBase(BzrError):
149
 
    def __init__(self, bases):
150
 
        msg = "The correct base is unclear, becase %s are all equally close" %\
151
 
            ", ".join(bases)
152
 
        BzrError.__init__(self, msg)
153
 
        self.bases = bases
154
 
 
155
 
class NoCommits(BzrError):
156
 
    def __init__(self, branch):
157
 
        msg = "Branch %s has no commits." % branch
158
 
        BzrError.__init__(self, msg)
159
 
 
160
 
class UnlistableStore(BzrError):
161
 
    def __init__(self, store):
162
 
        BzrError.__init__(self, "Store %s is not listable" % store)
163
 
 
164
 
class UnlistableBranch(BzrError):
165
 
    def __init__(self, br):
166
 
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
167
 
 
168
 
 
169
 
from bzrlib.weave import WeaveError
170
 
 
171
 
class TransportError(BzrError):
172
 
    """All errors thrown by Transport implementations should derive
173
 
    from this class.
174
 
    """
175
 
    def __init__(self, msg=None, orig_error=None):
176
 
        if msg is None and orig_error is not None:
177
 
            msg = str(orig_error)
178
 
        BzrError.__init__(self, msg)
179
 
        self.msg = msg
180
 
        self.orig_error = orig_error
181
 
 
182
 
# A set of semi-meaningful errors which can be thrown
183
 
class TransportNotPossible(TransportError):
184
 
    """This is for transports where a specific function is explicitly not
185
 
    possible. Such as pushing files to an HTTP server.
186
 
    """
187
 
    pass
188
 
 
189
 
class NonRelativePath(TransportError):
190
 
    """An absolute path was supplied, that could not be decoded into
191
 
    a relative path.
192
 
    """
193
 
    pass
194
 
 
195
 
class NoSuchFile(TransportError, IOError):
196
 
    """A get() was issued for a file that doesn't exist."""
197
 
    def __init__(self, msg=None, orig_error=None):
198
 
        import errno
199
 
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
200
 
        IOError.__init__(self, errno.ENOENT, self.msg)
201
 
 
202
 
class FileExists(TransportError, OSError):
203
 
    """An operation was attempted, which would overwrite an entry,
204
 
    but overwritting is not supported.
205
 
 
206
 
    mkdir() can throw this, but put() just overwites existing files.
207
 
    """
208
 
    def __init__(self, msg=None, orig_error=None):
209
 
        import errno
210
 
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
211
 
        OSError.__init__(self, errno.EEXIST, self.msg)
212
 
 
213
 
class PermissionDenied(TransportError):
214
 
    """An operation cannot succeed because of a lack of permissions."""
215
 
    pass
216
 
 
217
 
class ConnectionReset(TransportError):
218
 
    """The connection has been closed."""
219
 
    pass
 
32
 
 
33
 
 
34
def bailout(msg, explanation=[]):
 
35
    ex = BzrError(msg, explanation)
 
36
    import trace
 
37
    trace._tracefile.write('* raising %s\n' % ex)
 
38
    raise ex
220
39