python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

Better error handling

Open gen-xu opened this issue 2 years ago • 8 comments

Currently if the callable provider fails due to missing arguments or other errors, it may be hard to find out which guy is missing arguments if one provider is being referred many times.

src/dependency_injector/providers.pxd:422: in dependency_injector.providers.__provide_keyword_args
    ???
src/dependency_injector/providers.pxd:345: in dependency_injector.providers.__get_value
    ???
src/dependency_injector/providers.pyx:195: in dependency_injector.providers.Provider.__call__
    ???
src/dependency_injector/providers.pyx:197: in dependency_injector.providers.Provider.__call__
    ???
src/dependency_injector/providers.pyx:2755: in dependency_injector.providers.Singleton._provide
    ???
src/dependency_injector/providers.pxd:620: in dependency_injector.providers.__factory_call
    ???
src/dependency_injector/providers.pxd:606: in dependency_injector.providers.__callable_call
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   TypeError: __init__() missing 1 required positional argument: 'config'

src/dependency_injector/providers.pxd:579: TypeError

it may be hard to find out which __init__, consider re-raise the exception with the function reference

gen-xu avatar Sep 14 '21 20:09 gen-xu

Hi @gen-xu. Yes, I agree that it turns to be a problem. Thanks for the PR. I'll look at it later today.

rmk135 avatar Sep 14 '21 20:09 rmk135

@gen-xu , commented on the PR.

rmk135 avatar Sep 15 '21 01:09 rmk135

@rmk135 Is there are any way to run dependency-injector in pure python for debug?

whysage avatar Oct 15 '21 08:10 whysage

@whysage , no, you can only run it as a C extension

rmk135 avatar Oct 15 '21 12:10 rmk135

I was troubleshooting a missing argument today in a FastAPI application and I agree that the error handling makes it hard to see where the error occurred. The only hint I get is the token_service.

../../../../Library/Caches/pypoetry/virtualenvs/xxx-auth-v2-7R6iqtGQ-py3.9/lib/python3.9/site-packages/dependency_injector/wiring.py:628: in _patched
    provide = provider()
src/dependency_injector/providers.pyx:207: in dependency_injector.providers.Provider.__call__
    ???
src/dependency_injector/providers.pyx:2385: in dependency_injector.providers.Factory._provide
    ???
src/dependency_injector/providers.pxd:620: in dependency_injector.providers.__factory_call
    ???
src/dependency_injector/providers.pxd:606: in dependency_injector.providers.__callable_call
    ???
src/dependency_injector/providers.pxd:552: in dependency_injector.providers.__call
    ???
src/dependency_injector/providers.pxd:422: in dependency_injector.providers.__provide_keyword_args
    ???
src/dependency_injector/providers.pxd:345: in dependency_injector.providers.__get_value
    ???
src/dependency_injector/providers.pyx:685: in dependency_injector.providers.Dependency.__call__
    ???
src/dependency_injector/providers.pyx:207: in dependency_injector.providers.Provider.__call__
    ???
src/dependency_injector/providers.pyx:2822: in dependency_injector.providers.Singleton._provide
    ???
src/dependency_injector/providers.pxd:620: in dependency_injector.providers.__factory_call
    ???
src/dependency_injector/providers.pxd:606: in dependency_injector.providers.__callable_call
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   TypeError: __init__() got an unexpected keyword argument 'token_service'

src/dependency_injector/providers.pxd:579: TypeError

chbndrhnns avatar Oct 22 '21 11:10 chbndrhnns

Nothing much to add, just having my first experiences with dependency-injector after using lots of other DI stacks, I have about 20 items in my container and am currently having trouble locating the place init() is failing.

Library seems great otherwise 👏

attentive avatar Jan 29 '23 03:01 attentive

Hey @rmk135, error handling still seems to be an issue. Any updates on this? I see there are a couple of PRs attempting to solve this.

thatguysimon avatar Sep 20 '23 10:09 thatguysimon

@rmk135 I also request this issue

dharmagetic avatar Apr 24 '24 12:04 dharmagetic