Revision 6797ec29

b/daemons/ganeti-masterd
167 167
      try:
168 168
        result = self._ops.handle_request(method, args)
169 169
        success = True
170
      except errors.GenericError, err:
171
        success = False
172
        result = (err.__class__.__name__, err.args)
170 173
      except:
171 174
        logging.error("Unexpected exception", exc_info=True)
172 175
        err = sys.exc_info()
b/lib/errors.py
241 241
  """Job queue error.
242 242

  
243 243
  """
244

  
245

  
246
# errors should be added above
247

  
248

  
249
def GetErrorClass(name):
250
  """Return the class of an exception.
251

  
252
  Given the class name, return the class itself.
253

  
254
  @type name: str
255
  @param name: the exception name
256
  @rtype: class
257
  @return: the actual class, or None if not found
258

  
259
  """
260
  item = globals().get(name, None)
261
  if item is not None:
262
    if not (isinstance(item, type(Exception)) and
263
            issubclass(item, GenericError)):
264
      item = None
265
  return item
b/lib/luxi.py
36 36

  
37 37
from ganeti import serializer
38 38
from ganeti import constants
39
from ganeti import errors
39 40

  
40 41

  
41 42
KEY_METHOD = 'method'
......
275 276
        KEY_RESULT not in data):
276 277
      raise DecodingError("Invalid response from server: %s" % str(data))
277 278

  
279
    result = data[KEY_RESULT]
280

  
278 281
    if not data[KEY_SUCCESS]:
279 282
      # TODO: decide on a standard exception
280
      raise RequestError(data[KEY_RESULT])
283
      if (isinstance(result, (tuple, list)) and len(result) == 2 and
284
          isinstance(result[1], (tuple, list))):
285
        # custom ganeti errors
286
        err_class = errors.GetErrorClass(result[0])
287
        if err_class is not None:
288
          raise err_class, tuple(result[1])
289

  
290
      raise RequestError(result)
281 291

  
282
    return data[KEY_RESULT]
292
    return result
283 293

  
284 294
  def SubmitJob(self, ops):
285 295
    ops_state = map(lambda op: op.__getstate__(), ops)

Also available in: Unified diff