1 # Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
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.
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.
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."""
18 from bzrlib.errors import (BzrError, ConnectionError, ConnectionReset,
19 LockError, NotBranchError, PermissionDenied,
20 DependencyNotPresent, NoRepositoryPresent,
21 TransportError, UnexpectedEndOfContainerError,
25 from bzrlib.plugins.svn import core
28 class InvalidExternalsDescription(BzrError):
29 _fmt = """Unable to parse externals description."""
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
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
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."""
68 def __init__(self, branch_path, mapping=None):
69 NotBranchError.__init__(self, urllib.quote(branch_path))
70 self.mapping = mapping
73 class NoSvnRepositoryPresent(NoRepositoryPresent):
75 def __init__(self, url):
76 BzrError.__init__(self)
80 class ChangesRootLHSHistory(BzrError):
81 _fmt = """changing lhs branch history not possible on repository root"""
84 class MissingPrefix(BzrError):
85 _fmt = """Prefix missing for %(path)s; please create it before pushing. """
87 def __init__(self, path):
88 BzrError.__init__(self)
92 class RevpropChangeFailed(BzrError):
93 _fmt = """Unable to set revision property %(name)s."""
95 def __init__(self, name):
96 BzrError.__init__(self)
100 def convert_error(err):
101 """Convert a Subversion exception to the matching BzrError.
103 :param err: SubversionException.
104 :return: BzrError instance if it could be converted, err otherwise
106 (msg, num) = err.args
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)
128 def convert_svn_error(unbound):
129 """Decorator that catches particular Subversion exceptions and
130 converts them to Bazaar exceptions.
132 def convert(*args, **kwargs):
134 return unbound(*args, **kwargs)
135 except core.SubversionException, e:
136 raise convert_error(e)
138 convert.__doc__ = unbound.__doc__
139 convert.__name__ = unbound.__name__
143 class LocalCommitsUnsupported(BzrError):
145 _fmt = 'Local commits are not supported for lightweight Subversion checkouts.'
148 class InvalidPropertyValue(BzrError):
149 _fmt = 'Invalid property value for Subversion property %(property)s: %(msg)s'
151 def __init__(self, property, msg):
152 BzrError.__init__(self)
153 self.property = property
156 class RebaseNotPresent(DependencyNotPresent):
157 _fmt = "Unable to import bzr-rebase (required for svn-upgrade support): %(error)s"
159 def __init__(self, error):
160 DependencyNotPresent.__init__(self, 'bzr-rebase', error)
163 class InvalidFileName(BzrError):
164 _fmt = "Unable to convert Subversion path %(path)s because it contains characters invalid in Bazaar."
166 def __init__(self, path):
167 BzrError.__init__(self)
171 class CorruptMappingData(BzrError):
172 _fmt = """An invalid change was made to the bzr-specific properties in %(path)s."""
174 def __init__(self, path):
175 BzrError.__init__(self)
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."""
185 def __init__(self, path, layout):
186 assert isinstance(path, str)
187 NotBranchError.__init__(self, urllib.quote(path))