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)
24 from bzrlib.plugins.svn import core
27 class InvalidExternalsDescription(BzrError):
28 _fmt = """Unable to parse externals description."""
31 ERR_UNKNOWN_HOSTNAME = 670002
32 ERR_UNKNOWN_HOSTNAME = 670002
33 ERR_RA_SVN_CONNECTION_CLOSED = 210002
34 ERR_WC_LOCKED = 155004
35 ERR_RA_NOT_AUTHORIZED = 170001
36 ERR_INCOMPLETE_DATA = 200003
37 ERR_RA_SVN_MALFORMED_DATA = 210004
38 ERR_RA_NOT_IMPLEMENTED = 170003
39 ERR_FS_NO_SUCH_REVISION = 160006
40 ERR_FS_TXN_OUT_OF_DATE = 160028
41 ERR_REPOS_DISABLED_FEATURE = 165006
42 ERR_STREAM_MALFORMED_DATA = 140001
43 ERR_RA_ILLEGAL_URL = 170000
44 ERR_RA_LOCAL_REPOS_OPEN_FAILED = 180001
46 ERR_RA_DAV_REQUEST_FAILED = 175002
47 ERR_RA_DAV_PATH_NOT_FOUND = 175007
48 ERR_FS_NOT_DIRECTORY = 160016
49 ERR_FS_NOT_FOUND = 160013
50 ERR_FS_ALREADY_EXISTS = 160020
51 ERR_RA_SVN_REPOS_NOT_FOUND = 210005
52 ERR_WC_NOT_DIRECTORY = 155007
53 ERR_ENTRY_EXISTS = 150002
54 ERR_WC_PATH_NOT_FOUND = 155010
55 ERR_CANCELLED = 200015
56 ERR_WC_UNSUPPORTED_FORMAT = 155021
59 class NotSvnBranchPath(NotBranchError):
60 """Error raised when a path was specified that did not exist."""
61 _fmt = """%(path)s is not a valid Subversion branch path.
62 See 'bzr help svn-branching-schemes' for details."""
64 def __init__(self, branch_path, mapping=None):
65 NotBranchError.__init__(self, urllib.quote(branch_path))
66 self.mapping = mapping
69 class NoSvnRepositoryPresent(NoRepositoryPresent):
71 def __init__(self, url):
72 BzrError.__init__(self)
76 class ChangesRootLHSHistory(BzrError):
77 _fmt = """changing lhs branch history not possible on repository root"""
80 class MissingPrefix(BzrError):
81 _fmt = """Prefix missing for %(path)s; please create it before pushing. """
83 def __init__(self, path):
84 BzrError.__init__(self)
88 class RevpropChangeFailed(BzrError):
89 _fmt = """Unable to set revision property %(name)s."""
91 def __init__(self, name):
92 BzrError.__init__(self)
96 def convert_error(err):
97 """Convert a Subversion exception to the matching BzrError.
99 :param err: SubversionException.
100 :return: BzrError instance if it could be converted, err otherwise
102 (msg, num) = err.args
104 if num == ERR_RA_SVN_CONNECTION_CLOSED:
105 return ConnectionReset(msg=msg)
106 elif num == ERR_WC_LOCKED:
107 return LockError(message=msg)
108 elif num == ERR_RA_NOT_AUTHORIZED:
109 return PermissionDenied('.', msg)
110 elif num == ERR_INCOMPLETE_DATA:
111 return UnexpectedEndOfContainerError()
112 elif num == ERR_RA_SVN_MALFORMED_DATA:
113 return TransportError("Malformed data", msg)
114 elif num == ERR_RA_NOT_IMPLEMENTED:
115 return NotImplementedError("Function not implemented in remote server")
116 elif num == ERR_UNKNOWN_HOSTNAME:
117 return ConnectionError(msg=msg)
118 elif num > 0 and num < 1000:
119 return OSError(num, msg)
124 def convert_svn_error(unbound):
125 """Decorator that catches particular Subversion exceptions and
126 converts them to Bazaar exceptions.
128 def convert(*args, **kwargs):
130 return unbound(*args, **kwargs)
131 except core.SubversionException, e:
132 raise convert_error(e)
134 convert.__doc__ = unbound.__doc__
135 convert.__name__ = unbound.__name__
139 class InvalidPropertyValue(BzrError):
140 _fmt = 'Invalid property value for Subversion property %(property)s: %(msg)s'
142 def __init__(self, property, msg):
143 BzrError.__init__(self)
144 self.property = property
147 class RebaseNotPresent(DependencyNotPresent):
148 _fmt = "Unable to import bzr-rebase (required for svn-upgrade support): %(error)s"
150 def __init__(self, error):
151 DependencyNotPresent.__init__(self, 'bzr-rebase', error)
154 class InvalidFileName(BzrError):
155 _fmt = "Unable to convert Subversion path %(path)s because it contains characters invalid in Bazaar."
157 def __init__(self, path):
158 BzrError.__init__(self)
162 class CorruptMappingData(BzrError):
163 _fmt = """An invalid change was made to the bzr-specific properties in %(path)s."""
165 def __init__(self, path):
166 BzrError.__init__(self)
170 class InvalidSvnBranchPath(NotBranchError):
171 """Error raised when a path was specified that is not a child of or itself
172 a valid branch path in the current branching scheme."""
173 _fmt = """%(path)s is not a valid Subversion branch path in the current
174 repository layout. See 'bzr help svn-repository-layout' for details."""
176 def __init__(self, path, layout):
177 assert isinstance(path, str)
178 NotBranchError.__init__(self, urllib.quote(path))