##// END OF EJS Templates
exceptions: don't log error the lookup method errors. This happens so often we spam...
marcink -
r2908:76c75f2d default
parent child Browse files
Show More
@@ -1,215 +1,215 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2014-2018 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 import logging
25 25 import functools
26 26 import urllib2
27 27
28 28 log = logging.getLogger(__name__)
29 29
30 30
31 31 class VCSCommunicationError(Exception):
32 32 pass
33 33
34 34
35 35 class HttpVCSCommunicationError(VCSCommunicationError):
36 36 pass
37 37
38 38
39 39 class VCSError(Exception):
40 40 pass
41 41
42 42
43 43 class RepositoryError(VCSError):
44 44 pass
45 45
46 46
47 47 class RepositoryRequirementError(RepositoryError):
48 48 pass
49 49
50 50
51 51 class VCSBackendNotSupportedError(VCSError):
52 52 """
53 53 Exception raised when VCSServer does not support requested backend
54 54 """
55 55
56 56
57 57 class EmptyRepositoryError(RepositoryError):
58 58 pass
59 59
60 60
61 61 class TagAlreadyExistError(RepositoryError):
62 62 pass
63 63
64 64
65 65 class TagDoesNotExistError(RepositoryError):
66 66 pass
67 67
68 68
69 69 class BranchAlreadyExistError(RepositoryError):
70 70 pass
71 71
72 72
73 73 class BranchDoesNotExistError(RepositoryError):
74 74 pass
75 75
76 76
77 77 class CommitError(RepositoryError):
78 78 """
79 79 Exceptions related to an existing commit
80 80 """
81 81
82 82
83 83 class CommitDoesNotExistError(CommitError):
84 84 pass
85 85
86 86
87 87 class CommittingError(RepositoryError):
88 88 """
89 89 Exceptions happening while creating a new commit
90 90 """
91 91
92 92
93 93 class NothingChangedError(CommittingError):
94 94 pass
95 95
96 96
97 97 class NodeError(VCSError):
98 98 pass
99 99
100 100
101 101 class RemovedFileNodeError(NodeError):
102 102 pass
103 103
104 104
105 105 class NodeAlreadyExistsError(CommittingError):
106 106 pass
107 107
108 108
109 109 class NodeAlreadyChangedError(CommittingError):
110 110 pass
111 111
112 112
113 113 class NodeDoesNotExistError(CommittingError):
114 114 pass
115 115
116 116
117 117 class NodeNotChangedError(CommittingError):
118 118 pass
119 119
120 120
121 121 class NodeAlreadyAddedError(CommittingError):
122 122 pass
123 123
124 124
125 125 class NodeAlreadyRemovedError(CommittingError):
126 126 pass
127 127
128 128
129 129 class SubrepoMergeError(RepositoryError):
130 130 """
131 131 This happens if we try to merge a repository which contains subrepos and
132 132 the subrepos cannot be merged. The subrepos are not merged itself but
133 133 their references in the root repo are merged.
134 134 """
135 135
136 136
137 137 class ImproperArchiveTypeError(VCSError):
138 138 pass
139 139
140 140
141 141 class CommandError(VCSError):
142 142 pass
143 143
144 144
145 145 class UnhandledException(VCSError):
146 146 """
147 147 Signals that something unexpected went wrong.
148 148
149 149 This usually means we have a programming error on the side of the VCSServer
150 150 and should inspect the logfile of the VCSServer to find more details.
151 151 """
152 152
153 153
154 154 _EXCEPTION_MAP = {
155 155 'abort': RepositoryError,
156 156 'archive': ImproperArchiveTypeError,
157 157 'error': RepositoryError,
158 158 'lookup': CommitDoesNotExistError,
159 159 'repo_locked': RepositoryError,
160 160 'requirement': RepositoryRequirementError,
161 161 'unhandled': UnhandledException,
162 162 # TODO: johbo: Define our own exception for this and stop abusing
163 163 # urllib's exception class.
164 164 'url_error': urllib2.URLError,
165 165 'subrepo_merge_error': SubrepoMergeError,
166 166 }
167 167
168 168
169 169 def map_vcs_exceptions(func):
170 170 """
171 171 Utility to decorate functions so that plain exceptions are translated.
172 172
173 173 The translation is based on `exc_map` which maps a `str` indicating
174 174 the error type into an exception class representing this error inside
175 175 of the vcs layer.
176 176 """
177 177
178 178 @functools.wraps(func)
179 179 def wrapper(*args, **kwargs):
180 180 try:
181 181 return func(*args, **kwargs)
182 182 except Exception as e:
183 183 # The error middleware adds information if it finds
184 184 # __traceback_info__ in a frame object. This way the remote
185 185 # traceback information is made available in error reports.
186 186 remote_tb = getattr(e, '_vcs_server_traceback', None)
187 187 __traceback_info__ = None
188 188 if remote_tb:
189 189 if isinstance(remote_tb, basestring):
190 190 remote_tb = [remote_tb]
191 191 __traceback_info__ = (
192 192 'Found VCSServer remote traceback information:\n\n' +
193 193 '\n'.join(remote_tb))
194 194
195 195 # Avoid that remote_tb also appears in the frame
196 196 del remote_tb
197 197
198 198 # Special vcs errors had an attribute "_vcs_kind" which is used
199 199 # to translate them to the proper exception class in the vcs
200 200 # client layer.
201 201 kind = getattr(e, '_vcs_kind', None)
202 202
203 203 if kind:
204 204 if any(e.args):
205 205 args = e.args
206 206 else:
207 207 args = [__traceback_info__ or 'unhandledException']
208 if __traceback_info__ and kind != 'unhandled':
208 if __traceback_info__ and kind not in ['unhandled', 'lookup']:
209 209 # for other than unhandled errors also log the traceback
210 210 # can be usefull for debugging
211 211 log.error(__traceback_info__)
212 212 raise _EXCEPTION_MAP[kind](*args)
213 213 else:
214 214 raise
215 215 return wrapper
General Comments 0
You need to be logged in to leave comments. Login now