Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error handling: Re-raise with function reference on error #510

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 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 @@ -575,15 +579,20 @@ cdef inline object __call(
asyncio.ensure_future(args_kwargs_ready)

return future_result

return call(*args, **kwargs)

try:
return call(*args, **kwargs)
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 @@ -597,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