Merge fix for compatibility with svn built with --enable-runtime-module-search
[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                            RedirectRequested)
23
24 import urllib
25 from bzrlib.plugins.svn import core
26
27
28 class InvalidExternalsDescription(BzrError):
29     _fmt = """Unable to parse externals description."""
30
31
32 ERR_UNKNOWN_HOSTNAME = 670002
33 ERR_UNKNOWN_HOSTNAME = 670002
34 ERR_RA_SVN_CONNECTION_CLOSED = 210002
35 ERR_WC_LOCKED = 155004
36 ERR_RA_NOT_AUTHORIZED = 170001
37 ERR_INCOMPLETE_DATA = 200003
38 ERR_RA_SVN_MALFORMED_DATA = 210004
39 ERR_RA_NOT_IMPLEMENTED = 170003
40 ERR_FS_NO_SUCH_REVISION = 160006
41 ERR_FS_TXN_OUT_OF_DATE = 160028
42 ERR_REPOS_DISABLED_FEATURE = 165006
43 ERR_STREAM_MALFORMED_DATA = 140001
44 ERR_RA_ILLEGAL_URL = 170000
45 ERR_RA_LOCAL_REPOS_OPEN_FAILED = 180001
46 ERR_BAD_URL = 125002
47 ERR_RA_DAV_REQUEST_FAILED = 175002
48 ERR_RA_DAV_PATH_NOT_FOUND = 175007
49 ERR_FS_NOT_DIRECTORY = 160016
50 ERR_FS_NOT_FOUND = 160013
51 ERR_FS_ALREADY_EXISTS = 160020
52 ERR_RA_SVN_REPOS_NOT_FOUND = 210005
53 ERR_WC_NOT_DIRECTORY = 155007
54 ERR_ENTRY_EXISTS = 150002
55 ERR_WC_PATH_NOT_FOUND = 155010
56 ERR_CANCELLED = 200015
57 ERR_WC_UNSUPPORTED_FORMAT = 155021
58 ERR_UNKNOWN_CAPABILITY = 200026
59 ERR_AUTHN_NO_PROVIDER = 215001
60 ERR_RA_DAV_RELOCATED = 175011
61
62
63 class NotSvnBranchPath(NotBranchError):
64     """Error raised when a path was specified that did not exist."""
65     _fmt = """%(path)s is not a valid Subversion branch path. 
66 See 'bzr help svn-branching-schemes' for details."""
67
68     def __init__(self, branch_path, mapping=None):
69         NotBranchError.__init__(self, urllib.quote(branch_path))
70         self.mapping = mapping
71
72
73 class NoSvnRepositoryPresent(NoRepositoryPresent):
74
75     def __init__(self, url):
76         BzrError.__init__(self)
77         self.path = url
78
79
80 class ChangesRootLHSHistory(BzrError):
81     _fmt = """changing lhs branch history not possible on repository root"""
82
83
84 class MissingPrefix(BzrError):
85     _fmt = """Prefix missing for %(path)s; please create it before pushing. """
86
87     def __init__(self, path):
88         BzrError.__init__(self)
89         self.path = path
90
91
92 class RevpropChangeFailed(BzrError):
93     _fmt = """Unable to set revision property %(name)s."""
94
95     def __init__(self, name):
96         BzrError.__init__(self)
97         self.name = name
98
99
100 def convert_error(err):
101     """Convert a Subversion exception to the matching BzrError.
102
103     :param err: SubversionException.
104     :return: BzrError instance if it could be converted, err otherwise
105     """
106     (msg, num) = err.args
107
108     if num == ERR_RA_SVN_CONNECTION_CLOSED:
109         return ConnectionReset(msg=msg)
110     elif num == ERR_WC_LOCKED:
111         return LockError(message=msg)
112     elif num == ERR_RA_NOT_AUTHORIZED:
113         return PermissionDenied('.', msg)
114     elif num == ERR_INCOMPLETE_DATA:
115         return UnexpectedEndOfContainerError()
116     elif num == ERR_RA_SVN_MALFORMED_DATA:
117         return TransportError("Malformed data", msg)
118     elif num == ERR_RA_NOT_IMPLEMENTED:
119         return NotImplementedError("Function not implemented in remote server")
120     elif num == ERR_UNKNOWN_HOSTNAME:
121         return ConnectionError(msg=msg)
122     elif num > 0 and num < 1000:
123         return OSError(num, msg)
124     else:
125         return err
126
127
128 def convert_svn_error(unbound):
129     """Decorator that catches particular Subversion exceptions and 
130     converts them to Bazaar exceptions.
131     """
132     def convert(*args, **kwargs):
133         try:
134             return unbound(*args, **kwargs)
135         except core.SubversionException, e:
136             raise convert_error(e)
137
138     convert.__doc__ = unbound.__doc__
139     convert.__name__ = unbound.__name__
140     return convert
141
142
143 class LocalCommitsUnsupported(BzrError):
144
145     _fmt = 'Local commits are not supported for lightweight Subversion checkouts.'
146
147
148 class InvalidPropertyValue(BzrError):
149     _fmt = 'Invalid property value for Subversion property %(property)s: %(msg)s'
150
151     def __init__(self, property, msg):
152         BzrError.__init__(self)
153         self.property = property
154         self.msg = msg
155
156 class RebaseNotPresent(DependencyNotPresent):
157     _fmt = "Unable to import bzr-rebase (required for svn-upgrade support): %(error)s"
158
159     def __init__(self, error):
160         DependencyNotPresent.__init__(self, 'bzr-rebase', error)
161
162
163 class InvalidFileName(BzrError):
164     _fmt = "Unable to convert Subversion path %(path)s because it contains characters invalid in Bazaar."
165
166     def __init__(self, path):
167         BzrError.__init__(self)
168         self.path = path
169
170
171 class CorruptMappingData(BzrError):
172     _fmt = """An invalid change was made to the bzr-specific properties in %(path)s."""
173
174     def __init__(self, path):
175         BzrError.__init__(self)
176         self.path = path
177
178
179 class InvalidSvnBranchPath(NotBranchError):
180     """Error raised when a path was specified that is not a child of or itself
181     a valid branch path in the current branching scheme."""
182     _fmt = """%(path)s is not a valid Subversion branch path in the current 
183 repository layout. See 'bzr help svn-repository-layout' for details."""
184
185     def __init__(self, path, layout):
186         assert isinstance(path, str)
187         NotBranchError.__init__(self, urllib.quote(path))
188         self.layout = layout
189