Revision a6607331
b/daemons/ganeti-masterd | ||
---|---|---|
167 | 167 |
success = True |
168 | 168 |
except errors.GenericError, err: |
169 | 169 |
success = False |
170 |
result = (err.__class__.__name__, err.args)
|
|
170 |
result = errors.EncodeException(err)
|
|
171 | 171 |
except: |
172 | 172 |
logging.error("Unexpected exception", exc_info=True) |
173 | 173 |
err = sys.exc_info() |
b/lib/errors.py | ||
---|---|---|
285 | 285 |
issubclass(item, GenericError)): |
286 | 286 |
item = None |
287 | 287 |
return item |
288 |
|
|
289 |
|
|
290 |
def EncodeException(err): |
|
291 |
"""Encodes an exception into a format that L{MaybeRaise} will recognise. |
|
292 |
|
|
293 |
The passed L{err} argument will be formatted as a tuple (exception |
|
294 |
name, arguments) that the MaybeRaise function will recognise. |
|
295 |
|
|
296 |
@type err: GenericError child |
|
297 |
@param err: usually a child of GenericError (but any exception |
|
298 |
will be accepted) |
|
299 |
@rtype: tuple |
|
300 |
@return: tuple of (exception name, exception arguments) |
|
301 |
|
|
302 |
""" |
|
303 |
return (err.__class__.__name__, err.args) |
|
304 |
|
|
305 |
|
|
306 |
def MaybeRaise(result): |
|
307 |
"""Is this looks like an encoded Ganeti exception, raise it. |
|
308 |
|
|
309 |
This function tries to parse the passed argument and if it looks |
|
310 |
like an encoding done by EncodeException, it will re-raise it. |
|
311 |
|
|
312 |
""" |
|
313 |
tlt = (tuple, list) |
|
314 |
if (isinstance(result, tlt) and len(result) == 2 and |
|
315 |
isinstance(result[1], tlt)): |
|
316 |
# custom ganeti errors |
|
317 |
err_class = GetErrorClass(result[0]) |
|
318 |
if err_class is not None: |
|
319 |
raise err_class, tuple(result[1]) |
b/lib/luxi.py | ||
---|---|---|
324 | 324 |
result = data[KEY_RESULT] |
325 | 325 |
|
326 | 326 |
if not data[KEY_SUCCESS]: |
327 |
# TODO: decide on a standard exception |
|
328 |
if (isinstance(result, (tuple, list)) and len(result) == 2 and |
|
329 |
isinstance(result[1], (tuple, list))): |
|
330 |
# custom ganeti errors |
|
331 |
err_class = errors.GetErrorClass(result[0]) |
|
332 |
if err_class is not None: |
|
333 |
raise err_class, tuple(result[1]) |
|
334 |
|
|
327 |
errors.MaybeRaise(result) |
|
335 | 328 |
raise RequestError(result) |
336 | 329 |
|
337 | 330 |
return result |
Also available in: Unified diff