Move upgrade code to bzr-foreign.
[jelmer/subvertpy.git] / errors.py
1 # Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
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 3 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 """Subversion-specific errors and conversion of Subversion-specific errors."""
17
18 from bzrlib.errors import (BzrError, ConnectionError, ConnectionReset, 
19                            LockError, NotBranchError, PermissionDenied, 
20                            DependencyNotPresent, NoRepositoryPresent,
21                            TransportError, UnexpectedEndOfContainerError,
22                            NoSuchRevision)
23
24 import urllib
25 from bzrlib.plugins.svn import core
26
27
28 ERR_UNKNOWN_HOSTNAME = 670002
29 ERR_UNKNOWN_HOSTNAME = 670002
30 ERR_RA_SVN_CONNECTION_CLOSED = 210002
31 ERR_WC_LOCKED = 155004
32 ERR_RA_NOT_AUTHORIZED = 170001
33 ERR_INCOMPLETE_DATA = 200003
34 ERR_RA_SVN_MALFORMED_DATA = 210004
35 ERR_RA_NOT_IMPLEMENTED = 170003
36 ERR_FS_NO_SUCH_REVISION = 160006
37 ERR_FS_TXN_OUT_OF_DATE = 160028
38 ERR_REPOS_DISABLED_FEATURE = 165006
39 ERR_STREAM_MALFORMED_DATA = 140001
40 ERR_RA_ILLEGAL_URL = 170000
41 ERR_RA_LOCAL_REPOS_OPEN_FAILED = 180001
42 ERR_BAD_URL = 125002
43 ERR_RA_DAV_REQUEST_FAILED = 175002
44 ERR_RA_DAV_PATH_NOT_FOUND = 175007
45 ERR_FS_NOT_DIRECTORY = 160016
46 ERR_FS_NOT_FOUND = 160013
47 ERR_FS_ALREADY_EXISTS = 160020
48 ERR_RA_SVN_REPOS_NOT_FOUND = 210005
49 ERR_WC_NOT_DIRECTORY = 155007
50 ERR_ENTRY_EXISTS = 150002
51 ERR_WC_PATH_NOT_FOUND = 155010
52 ERR_CANCELLED = 200015
53 ERR_WC_UNSUPPORTED_FORMAT = 155021
54 ERR_UNKNOWN_CAPABILITY = 200026
55 ERR_AUTHN_NO_PROVIDER = 215001
56 ERR_RA_DAV_RELOCATED = 175011
57 ERR_FS_NOT_FILE = 160017
58 ERR_WC_BAD_ADM_LOG = 155009
59
60
61 class InvalidBzrSvnRevision(NoSuchRevision):
62     _fmt = """Revision id %(revid)s was added incorrectly"""
63
64     def __init__(self, revid):
65         self.revid = revid
66
67
68 class NotSvnBranchPath(NotBranchError):
69     """Error raised when a path was specified that did not exist."""
70     _fmt = """%(path)s is not a valid Subversion branch path. 
71 See 'bzr help svn-repository-layout' for details."""
72
73     def __init__(self, branch_path, mapping=None):
74         NotBranchError.__init__(self, urllib.quote(branch_path))
75         self.mapping = mapping
76
77
78 class NoSvnRepositoryPresent(NoRepositoryPresent):
79
80     def __init__(self, url):
81         BzrError.__init__(self)
82         self.path = url
83
84
85 class ChangesRootLHSHistory(BzrError):
86     _fmt = """changing lhs branch history not possible on repository root"""
87
88
89 class MissingPrefix(BzrError):
90     _fmt = """Prefix missing for %(path)s; please create it before pushing. """
91
92     def __init__(self, path, existing_path):
93         BzrError.__init__(self)
94         self.path = path
95         self.existing_path = existing_path
96
97
98 class RaRequestFailed(BzrError):
99     _fmt = """A Subversion remote access command failed: %(message)"""
100
101     def __init__(self, message):
102         BzrError.__init__(self)
103         self.mesage = message
104
105
106 class RevpropChangeFailed(BzrError):
107     _fmt = """Unable to set revision property %(name)s."""
108
109     def __init__(self, name):
110         BzrError.__init__(self)
111         self.name = name
112
113
114 class DavRequestFailed(BzrError):
115     _fmt = """%(msg)s"""
116
117     def __init__(self, msg):
118         BzrError.__init__(self)
119         self.msg = msg
120
121
122 def convert_error(err):
123     """Convert a Subversion exception to the matching BzrError.
124
125     :param err: SubversionException.
126     :return: BzrError instance if it could be converted, err otherwise
127     """
128     (msg, num) = err.args
129
130     if num == ERR_RA_SVN_CONNECTION_CLOSED:
131         return ConnectionReset(msg=msg)
132     elif num == ERR_WC_LOCKED:
133         return LockError(message=msg)
134     elif num == ERR_RA_NOT_AUTHORIZED:
135         return PermissionDenied('.', msg)
136     elif num == ERR_INCOMPLETE_DATA:
137         return UnexpectedEndOfContainerError()
138     elif num == ERR_RA_SVN_MALFORMED_DATA:
139         return TransportError("Malformed data", msg)
140     elif num == ERR_RA_NOT_IMPLEMENTED:
141         return NotImplementedError("Function not implemented in remote server")
142     elif num == ERR_RA_DAV_REQUEST_FAILED:
143         return RaRequestFailed(msg)
144     elif num == ERR_UNKNOWN_HOSTNAME:
145         return ConnectionError(msg=msg)
146     elif num == ERR_RA_DAV_REQUEST_FAILED:
147         return DavRequestFailed(msg)
148     else:
149         return err
150
151
152 def convert_svn_error(unbound):
153     """Decorator that catches particular Subversion exceptions and 
154     converts them to Bazaar exceptions.
155     """
156     def convert(*args, **kwargs):
157         try:
158             return unbound(*args, **kwargs)
159         except core.SubversionException, e:
160             raise convert_error(e)
161
162     convert.__doc__ = unbound.__doc__
163     convert.__name__ = unbound.__name__
164     return convert
165
166
167 class InvalidPropertyValue(BzrError):
168     _fmt = 'Invalid property value for Subversion property %(property)s: %(msg)s'
169
170     def __init__(self, property, msg):
171         BzrError.__init__(self)
172         self.property = property
173         self.msg = msg
174
175 class InvalidFileName(BzrError):
176     _fmt = "Unable to convert Subversion path %(path)s because it contains characters invalid in Bazaar."
177
178     def __init__(self, path):
179         BzrError.__init__(self)
180         self.path = path
181
182
183 class CorruptMappingData(BzrError):
184     _fmt = """An invalid change was made to the bzr-specific properties in %(path)s."""
185
186     def __init__(self, path):
187         BzrError.__init__(self)
188         self.path = path
189
190
191 class InvalidSvnBranchPath(NotBranchError):
192     """Error raised when a path was specified that is not a child of or itself
193     a valid branch path in the current branching scheme."""
194     _fmt = """%(path)s is not a valid Subversion branch path in the current 
195 repository layout. See 'bzr help svn-repository-layout' for details."""
196
197     def __init__(self, path, layout):
198         assert isinstance(path, str)
199         NotBranchError.__init__(self, urllib.quote(path))
200         self.layout = layout
201
202
203 class LayoutUnusable(BzrError):
204     _fmt = """Unable to use layout %(layout)r with mapping %(mapping)r."""
205
206     def __init__(self, layout, mapping):
207         BzrError.__init__(self)
208         self.layout = layout
209         self.mapping = mapping