callback could raises (not only returns)
This commit is contained in:
parent
cb89c74201
commit
952c880d10
|
@ -211,7 +211,7 @@ def carry_out_calculation(option, context, callback, callback_params,
|
|||
args.append(val)
|
||||
else:
|
||||
kwargs[key] = val
|
||||
return calculate(callback, args, kwargs)
|
||||
return calculate(callback, args, kwargs, returns_raise)
|
||||
else:
|
||||
# no value is multi
|
||||
# return a single value
|
||||
|
@ -224,7 +224,7 @@ def carry_out_calculation(option, context, callback, callback_params,
|
|||
args.append(couple[0])
|
||||
else:
|
||||
kwargs[key] = couple[0]
|
||||
ret = calculate(callback, args, kwargs)
|
||||
ret = calculate(callback, args, kwargs, returns_raise)
|
||||
if not option.impl_is_optiondescription() and callback_params != {} and isinstance(ret, list) and \
|
||||
option.impl_is_master_slaves('slave'):
|
||||
raise SlaveError(_("callback cannot return a list for a "
|
||||
|
@ -232,7 +232,7 @@ def carry_out_calculation(option, context, callback, callback_params,
|
|||
return ret
|
||||
|
||||
|
||||
def calculate(callback, args, kwargs):
|
||||
def calculate(callback, args, kwargs, returns_raise):
|
||||
"""wrapper that launches the 'callback'
|
||||
|
||||
:param callback: callback function
|
||||
|
@ -240,4 +240,10 @@ def calculate(callback, args, kwargs):
|
|||
:param kwargs: in the callback's arity, the named parameters
|
||||
|
||||
"""
|
||||
return callback(*args, **kwargs)
|
||||
if returns_raise:
|
||||
try:
|
||||
return callback(*args, **kwargs)
|
||||
except ValueError, err:
|
||||
return err
|
||||
else:
|
||||
return callback(*args, **kwargs)
|
||||
|
|
Loading…
Reference in New Issue