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 #509 #528

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/dependency_injector/providers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ cdef class Provider(object):
if self.__last_overriding is not None:
result = self.__last_overriding(*args, **kwargs)
else:
result = self._provide(args, kwargs)
try:
result = self._provide(args, kwargs)
except Exception as exc:
print(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure about using print() here. It will send some data to stdout, which might not always be the desired behavior.

The idea, generally, looks interesting. Maybe we can use the logging module?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree with @rmk135 to use the logging module with logger.exception with some extra useful messages as it allows users to have more control on the output through logging.config. Meanwhile, I believe the LogRecord may not provide precise info given the cython context (caller line number, stacktrace etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reply!

@rmk135 @gen-xu

Please look at updated pull request.
I hope logging.debug() is good idea because, by default, we have warning log level, and I hope no one use debug level in production) - so nothing will change for current users until logging level set to debug.
If this request will be accepted - I'll add article to documentation about this.

raise exc

if self.is_async_mode_disabled():
return result
Expand Down