Skip to content

Commit

Permalink
add locals for async exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
gen-xu committed Sep 15, 2021
1 parent 4de3fa7 commit 9abd18a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/dependency_injector/providers.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ cdef inline void __async_prepare_args_kwargs_callback(
for value, (key, _) in zip(result, future_args_kwargs):
args[key] = value
except Exception as exception:
exception.__traceback__.tb_frame.f_locals.clear()
exception.__traceback__.tb_frame.f_locals.update(locals())
future_result.set_exception(exception)
else:
future_result.set_result(args)
Expand Down Expand Up @@ -525,6 +527,8 @@ cdef inline void __async_inject_attributes_callback(object future_result, object
for name, value in attributes.items():
setattr(instance, name, value)
except Exception as exception:
exception.__traceback__.tb_frame.f_locals.clear()
exception.__traceback__.tb_frame.f_locals.update(locals())
future_result.set_exception(exception)
else:
future_result.set_result(instance)
Expand Down Expand Up @@ -577,16 +581,18 @@ cdef inline object __call(
return future_result
try:
return call(*args, **kwargs)
except Exception as e:
e.__traceback__.tb_frame.f_locals.clear()
e.__traceback__.tb_frame.f_locals.update(locals())
raise e
except Exception as exception:
exception.__traceback__.tb_frame.f_locals.clear()
exception.__traceback__.tb_frame.f_locals.update(locals())
raise exception

cdef inline void __async_call_callback(object future_result, object call, object future):
try:
args, kwargs = future.result()
result = call(*args, **kwargs)
except Exception as exception:
exception.__traceback__.tb_frame.f_locals.clear()
exception.__traceback__.tb_frame.f_locals.update(locals())
future_result.set_exception(exception)
else:
if __is_future_or_coroutine(result):
Expand All @@ -600,6 +606,8 @@ cdef inline object __async_result_callback(object future_result, object future):
try:
result = future.result()
except Exception as exception:
exception.__traceback__.tb_frame.f_locals.clear()
exception.__traceback__.tb_frame.f_locals.update(locals())
future_result.set_exception(exception)
else:
future_result.set_result(result)
Expand Down

0 comments on commit 9abd18a

Please sign in to comment.