Revision 6956e9cd

b/daemons/ganeti-masterd
171 171
        success = True
172 172
      except errors.GenericError, err:
173 173
        success = False
174
        result = (err.__class__.__name__, err.args)
174
        result = errors.EncodeException(err)
175 175
      except:
176 176
        logging.error("Unexpected exception", exc_info=True)
177 177
        err = sys.exc_info()
b/lib/errors.py
311 311
            issubclass(item, GenericError)):
312 312
      item = None
313 313
  return item
314

  
315

  
316
def EncodeException(err):
317
  """Encodes an exception into a format that L{MaybeRaise} will recognise.
318

  
319
  The passed L{err} argument will be formatted as a tuple (exception
320
  name, arguments) that the MaybeRaise function will recognise.
321

  
322
  @type err: GenericError child
323
  @param err: usually a child of GenericError (but any exception
324
      will be accepted)
325
  @rtype: tuple
326
  @return: tuple of (exception name, exception arguments)
327

  
328
  """
329
  return (err.__class__.__name__, err.args)
330

  
331

  
332
def MaybeRaise(result):
333
  """Is this looks like an encoded Ganeti exception, raise it.
334

  
335
  This function tries to parse the passed argument and if it looks
336
  like an encoding done by EncodeException, it will re-raise it.
337

  
338
  """
339
  tlt = (tuple, list)
340
  if (isinstance(result, tlt) and len(result) == 2 and
341
      isinstance(result[1], tlt)):
342
    # custom ganeti errors
343
    err_class = GetErrorClass(result[0])
344
    if err_class is not None:
345
      raise err_class, tuple(result[1])
b/lib/luxi.py
325 325
    result = data[KEY_RESULT]
326 326

  
327 327
    if not data[KEY_SUCCESS]:
328
      # TODO: decide on a standard exception
329
      if (isinstance(result, (tuple, list)) and len(result) == 2 and
330
          isinstance(result[1], (tuple, list))):
331
        # custom ganeti errors
332
        err_class = errors.GetErrorClass(result[0])
333
        if err_class is not None:
334
          raise err_class, tuple(result[1])
335

  
328
      errors.MaybeRaise(result)
336 329
      raise RequestError(result)
337 330

  
338 331
    return result

Also available in: Unified diff