Show More
@@ -1,196 +1,205 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2014-2016 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | """ |
|
22 | 22 | Custom vcs exceptions module. |
|
23 | 23 | """ |
|
24 | 24 | |
|
25 | 25 | import functools |
|
26 | 26 | import urllib2 |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | class VCSCommunicationError(Exception): |
|
30 | 30 | pass |
|
31 | 31 | |
|
32 | 32 | |
|
33 | 33 | class PyroVCSCommunicationError(VCSCommunicationError): |
|
34 | 34 | pass |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | class HttpVCSCommunicationError(VCSCommunicationError): |
|
38 | 38 | pass |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | class VCSError(Exception): |
|
42 | 42 | pass |
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | class RepositoryError(VCSError): |
|
46 | 46 | pass |
|
47 | 47 | |
|
48 | 48 | |
|
49 | 49 | class RepositoryRequirementError(RepositoryError): |
|
50 | 50 | pass |
|
51 | 51 | |
|
52 | 52 | |
|
53 | 53 | class VCSBackendNotSupportedError(VCSError): |
|
54 | 54 | """ |
|
55 | 55 | Exception raised when VCSServer does not support requested backend |
|
56 | 56 | """ |
|
57 | 57 | |
|
58 | 58 | |
|
59 | 59 | class EmptyRepositoryError(RepositoryError): |
|
60 | 60 | pass |
|
61 | 61 | |
|
62 | 62 | |
|
63 | 63 | class TagAlreadyExistError(RepositoryError): |
|
64 | 64 | pass |
|
65 | 65 | |
|
66 | 66 | |
|
67 | 67 | class TagDoesNotExistError(RepositoryError): |
|
68 | 68 | pass |
|
69 | 69 | |
|
70 | 70 | |
|
71 | 71 | class BranchAlreadyExistError(RepositoryError): |
|
72 | 72 | pass |
|
73 | 73 | |
|
74 | 74 | |
|
75 | 75 | class BranchDoesNotExistError(RepositoryError): |
|
76 | 76 | pass |
|
77 | 77 | |
|
78 | 78 | |
|
79 | 79 | class CommitError(RepositoryError): |
|
80 | 80 | """ |
|
81 | 81 | Exceptions related to an existing commit |
|
82 | 82 | """ |
|
83 | 83 | |
|
84 | 84 | |
|
85 | 85 | class CommitDoesNotExistError(CommitError): |
|
86 | 86 | pass |
|
87 | 87 | |
|
88 | 88 | |
|
89 | 89 | class CommittingError(RepositoryError): |
|
90 | 90 | """ |
|
91 | 91 | Exceptions happening while creating a new commit |
|
92 | 92 | """ |
|
93 | 93 | |
|
94 | 94 | |
|
95 | 95 | class NothingChangedError(CommittingError): |
|
96 | 96 | pass |
|
97 | 97 | |
|
98 | 98 | |
|
99 | 99 | class NodeError(VCSError): |
|
100 | 100 | pass |
|
101 | 101 | |
|
102 | 102 | |
|
103 | 103 | class RemovedFileNodeError(NodeError): |
|
104 | 104 | pass |
|
105 | 105 | |
|
106 | 106 | |
|
107 | 107 | class NodeAlreadyExistsError(CommittingError): |
|
108 | 108 | pass |
|
109 | 109 | |
|
110 | 110 | |
|
111 | 111 | class NodeAlreadyChangedError(CommittingError): |
|
112 | 112 | pass |
|
113 | 113 | |
|
114 | 114 | |
|
115 | 115 | class NodeDoesNotExistError(CommittingError): |
|
116 | 116 | pass |
|
117 | 117 | |
|
118 | 118 | |
|
119 | 119 | class NodeNotChangedError(CommittingError): |
|
120 | 120 | pass |
|
121 | 121 | |
|
122 | 122 | |
|
123 | 123 | class NodeAlreadyAddedError(CommittingError): |
|
124 | 124 | pass |
|
125 | 125 | |
|
126 | 126 | |
|
127 | 127 | class NodeAlreadyRemovedError(CommittingError): |
|
128 | 128 | pass |
|
129 | 129 | |
|
130 | 130 | |
|
131 | class SubrepoMergeError(RepositoryError): | |
|
132 | """ | |
|
133 | This happens if we try to merge a repository which contains subrepos and | |
|
134 | the subrepos cannot be merged. The subrepos are not merged itself but | |
|
135 | their references in the root repo are merged. | |
|
136 | """ | |
|
137 | ||
|
138 | ||
|
131 | 139 | class ImproperArchiveTypeError(VCSError): |
|
132 | 140 | pass |
|
133 | 141 | |
|
134 | 142 | |
|
135 | 143 | class CommandError(VCSError): |
|
136 | 144 | pass |
|
137 | 145 | |
|
138 | 146 | |
|
139 | 147 | class UnhandledException(VCSError): |
|
140 | 148 | """ |
|
141 | 149 | Signals that something unexpected went wrong. |
|
142 | 150 | |
|
143 | 151 | This usually means we have a programming error on the side of the VCSServer |
|
144 | 152 | and should inspect the logfile of the VCSServer to find more details. |
|
145 | 153 | """ |
|
146 | 154 | |
|
147 | 155 | |
|
148 | 156 | _EXCEPTION_MAP = { |
|
149 | 157 | 'abort': RepositoryError, |
|
150 | 158 | 'archive': ImproperArchiveTypeError, |
|
151 | 159 | 'error': RepositoryError, |
|
152 | 160 | 'lookup': CommitDoesNotExistError, |
|
153 | 161 | 'repo_locked': RepositoryError, |
|
154 | 162 | 'requirement': RepositoryRequirementError, |
|
155 | 163 | 'unhandled': UnhandledException, |
|
156 | 164 | # TODO: johbo: Define our own exception for this and stop abusing |
|
157 | 165 | # urllib's exception class. |
|
158 | 166 | 'url_error': urllib2.URLError, |
|
167 | 'subrepo_merge_error': SubrepoMergeError, | |
|
159 | 168 | } |
|
160 | 169 | |
|
161 | 170 | |
|
162 | 171 | def map_vcs_exceptions(func): |
|
163 | 172 | """ |
|
164 | 173 | Utility to decorate functions so that plain exceptions are translated. |
|
165 | 174 | |
|
166 | 175 | The translation is based on `exc_map` which maps a `str` indicating |
|
167 | 176 | the error type into an exception class representing this error inside |
|
168 | 177 | of the vcs layer. |
|
169 | 178 | """ |
|
170 | 179 | |
|
171 | 180 | @functools.wraps(func) |
|
172 | 181 | def wrapper(*args, **kwargs): |
|
173 | 182 | try: |
|
174 | 183 | return func(*args, **kwargs) |
|
175 | 184 | except Exception as e: |
|
176 | 185 | # The error middleware adds information if it finds |
|
177 | 186 | # __traceback_info__ in a frame object. This way the remote |
|
178 | 187 | # traceback information is made available in error reports. |
|
179 | 188 | remote_tb = getattr(e, '_pyroTraceback', None) |
|
180 | 189 | if remote_tb: |
|
181 | 190 | __traceback_info__ = ( |
|
182 | 191 | 'Found Pyro4 remote traceback information:\n\n' + |
|
183 | 192 | '\n'.join(remote_tb)) |
|
184 | 193 | |
|
185 | 194 | # Avoid that remote_tb also appears in the frame |
|
186 | 195 | del remote_tb |
|
187 | 196 | |
|
188 | 197 | # Special vcs errors had an attribute "_vcs_kind" which is used |
|
189 | 198 | # to translate them to the proper exception class in the vcs |
|
190 | 199 | # client layer. |
|
191 | 200 | kind = getattr(e, '_vcs_kind', None) |
|
192 | 201 | if kind: |
|
193 | 202 | raise _EXCEPTION_MAP[kind](*e.args) |
|
194 | 203 | else: |
|
195 | 204 | raise |
|
196 | 205 | return wrapper |
General Comments 0
You need to be logged in to leave comments.
Login now