~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
21
22
######################################################################
23
# exceptions 
24
class BzrError(StandardError):
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
25
    def __str__(self):
1195 by Martin Pool
- better error display
26
        if len(self.args) == 1:
27
            return self.args[0]
28
        elif len(self.args) == 2:
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
29
            # further explanation or suggestions
30
            return '\n  '.join([self.args[0]] + self.args[1])
31
        else:
32
            return `self.args`
33
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
34
1 by mbp at sourcefrog
import from baz patch-364
35
class BzrCheckError(BzrError):
36
    pass
37
38
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
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
329 by Martin Pool
- refactor command functions into command classes
48
class BzrCommandError(BzrError):
49
    # Error from malformed user command
50
    pass
1 by mbp at sourcefrog
import from baz patch-364
51
52
573 by Martin Pool
- new exception NotBranchError
53
class NotBranchError(BzrError):
54
    """Specified path is not in a branch"""
55
    pass
56
57
753 by Martin Pool
- new exception NotVersionedError
58
class NotVersionedError(BzrError):
59
    """Specified object is not versioned."""
60
61
599 by Martin Pool
- better error reporting from smart_add
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
614 by Martin Pool
- unify two defintions of LockError
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)
882 by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this.
85
86
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
87
class PointlessCommit(Exception):
882 by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this.
88
    """Commit failed because nothing was changed."""
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
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
1034 by Martin Pool
- merge bzrlib.revision.is_ancestor from aaron
98
1192 by Martin Pool
- clean up code for retrieving stored inventories
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
1185.2.1 by Lalo Martins
moving DivergedBranches from bzrlib.branch to bzrlib.errors, obeying:
107
class DivergedBranches(BzrError):
108
    def __init__(self, branch1, branch2):
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
109
        BzrError.__init__(self, "These branches have diverged.")
1185.2.1 by Lalo Martins
moving DivergedBranches from bzrlib.branch to bzrlib.errors, obeying:
110
        self.branch1 = branch1
111
        self.branch2 = branch2
112
1390 by Robert Collins
pair programming worx... merge integration and weave
113
1105 by Martin Pool
- expose 'find-merge-base' as a new expert command,
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
974.1.80 by Aaron Bentley
Improved merge error handling and testing
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)
1105 by Martin Pool
- expose 'find-merge-base' as a new expert command,
131
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
132
class NotAncestor(BzrError):
133
    def __init__(self, rev_id, not_ancestor_id):
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
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
1185.1.12 by Robert Collins
merge in lsdiff/filterdiff friendliness
139
140
1092.3.4 by Robert Collins
update symlink branch to integration
141
class NotAncestor(BzrError):
142
    def __init__(self, rev_id, not_ancestor_id):
143
        self.rev_id = rev_id
144
        self.not_ancestor_id = not_ancestor_id
145
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
146
                                                        rev_id)
147
        BzrError.__init__(self, msg)
148
149
974.1.30 by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions
150
class InstallFailed(BzrError):
151
    def __init__(self, revisions):
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
152
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
153
        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
154
        self.revisions = revisions
1154 by Martin Pool
- fix imports for moved errors
155
156
157
class AmbiguousBase(BzrError):
158
    def __init__(self, bases):
159
        msg = "The correct base is unclear, becase %s are all equally close" %\
160
            ", ".join(bases)
161
        BzrError.__init__(self, msg)
162
        self.bases = bases
163
974.1.80 by Aaron Bentley
Improved merge error handling and testing
164
class NoCommits(BzrError):
165
    def __init__(self, branch):
166
        msg = "Branch %s has no commits." % branch
167
        BzrError.__init__(self, msg)
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
168
169
class UnlistableStore(BzrError):
170
    def __init__(self, store):
171
        BzrError.__init__(self, "Store %s is not listable" % store)
172
173
class UnlistableBranch(BzrError):
174
    def __init__(self, br):
175
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
1392 by Robert Collins
reinstate testfetch test case
176
177
178
from bzrlib.weave import WeaveError
1393.2.1 by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still.
179
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
180
class TransportError(BzrError):
181
    """All errors thrown by Transport implementations should derive
182
    from this class.
183
    """
184
    def __init__(self, msg=None, orig_error=None):
185
        if msg is None and orig_error is not None:
186
            msg = str(orig_error)
187
        BzrError.__init__(self, msg)
188
        self.msg = msg
189
        self.orig_error = orig_error
190
191
# A set of semi-meaningful errors which can be thrown
192
class TransportNotPossible(TransportError):
193
    """This is for transports where a specific function is explicitly not
194
    possible. Such as pushing files to an HTTP server.
195
    """
196
    pass
197
198
class NonRelativePath(TransportError):
199
    """An absolute path was supplied, that could not be decoded into
200
    a relative path.
201
    """
202
    pass
203
204
class NoSuchFile(TransportError, IOError):
205
    """A get() was issued for a file that doesn't exist."""
206
    def __init__(self, msg=None, orig_error=None):
207
        import errno
208
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
209
        IOError.__init__(self, errno.ENOENT, self.msg)
210
211
class FileExists(TransportError, OSError):
212
    """An operation was attempted, which would overwrite an entry,
213
    but overwritting is not supported.
214
215
    mkdir() can throw this, but put() just overwites existing files.
216
    """
217
    def __init__(self, msg=None, orig_error=None):
218
        import errno
219
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
220
        OSError.__init__(self, errno.EEXIST, self.msg)
221
222
class PermissionDenied(TransportError):
223
    """An operation cannot succeed because of a lack of permissions."""
224
    pass
225
226
class ConnectionReset(TransportError):
227
    """The connection has been closed."""
228
    pass
229