Revision 84f790e6 lib/errors.py
b/lib/errors.py | ||
---|---|---|
394 | 394 |
return (err.__class__.__name__, err.args) |
395 | 395 |
|
396 | 396 |
|
397 |
def MaybeRaise(result):
|
|
398 |
"""If this looks like an encoded Ganeti exception, raise it.
|
|
397 |
def GetEncodedError(result):
|
|
398 |
"""If this looks like an encoded Ganeti exception, return it.
|
|
399 | 399 |
|
400 | 400 |
This function tries to parse the passed argument and if it looks |
401 |
like an encoding done by EncodeException, it will re-raise it. |
|
401 |
like an encoding done by EncodeException, it will return the class |
|
402 |
object and arguments. |
|
402 | 403 |
|
403 | 404 |
""" |
404 | 405 |
tlt = (tuple, list) |
405 | 406 |
if (isinstance(result, tlt) and len(result) == 2 and |
406 | 407 |
isinstance(result[1], tlt)): |
407 | 408 |
# custom ganeti errors |
408 |
err_class = GetErrorClass(result[0]) |
|
409 |
if err_class is not None: |
|
410 |
raise err_class, tuple(result[1]) |
|
409 |
errcls = GetErrorClass(result[0]) |
|
410 |
if errcls: |
|
411 |
return (errcls, tuple(result[1])) |
|
412 |
|
|
413 |
return None |
|
414 |
|
|
415 |
|
|
416 |
def MaybeRaise(result): |
|
417 |
"""If this looks like an encoded Ganeti exception, raise it. |
|
418 |
|
|
419 |
This function tries to parse the passed argument and if it looks |
|
420 |
like an encoding done by EncodeException, it will re-raise it. |
|
421 |
|
|
422 |
""" |
|
423 |
error = GetEncodedError(result) |
|
424 |
if error: |
|
425 |
(errcls, args) = error |
|
426 |
raise errcls, args |
Also available in: Unified diff