-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
WIP: Handle Logger.exception() outside "except" block #635
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
NamedTuple, | ||
Sequence, | ||
TextIO, | ||
Tuple, | ||
Union, | ||
) | ||
|
||
from ._frames import ( | ||
|
@@ -407,11 +409,9 @@ def __init__( | |
def __call__( | ||
self, logger: WrappedLogger, name: str, event_dict: EventDict | ||
) -> EventDict: | ||
exc_info = event_dict.pop("exc_info", None) | ||
if exc_info: | ||
event_dict["exception"] = self.format_exception( | ||
_figure_out_exc_info(exc_info) | ||
) | ||
exc_info = _figure_out_exc_info(event_dict.pop("exc_info", None)) | ||
if exc_info != (None, None, None): | ||
event_dict["exception"] = self.format_exception(exc_info) | ||
|
||
return event_dict | ||
|
||
|
@@ -586,7 +586,7 @@ def __call__( | |
return event_dict | ||
|
||
|
||
def _figure_out_exc_info(v: Any) -> ExcInfo: | ||
def _figure_out_exc_info(v: Any) -> Union[ExcInfo, Tuple[None, None, None]]: | ||
sscherfke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Depending on the Python version will try to do the smartest thing possible | ||
to transform *v* into an ``exc_info`` tuple. | ||
|
@@ -598,7 +598,8 @@ def _figure_out_exc_info(v: Any) -> ExcInfo: | |
return v | ||
|
||
if v: | ||
return sys.exc_info() # type: ignore[return-value] | ||
# Can be "(None, None, None)" if not called inside an error context: | ||
return sys.exc_info() | ||
|
||
return v | ||
|
||
|
@@ -642,7 +643,7 @@ def __call__( | |
exc = event_dict.pop("exception", None) | ||
if exc is None: | ||
exc_info = _figure_out_exc_info(event_dict.pop("exc_info", None)) | ||
if exc_info: | ||
if exc_info != (None, None, None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like this was the actual bug, right? because a negative result from _figure_out_exc_info isn't falsey There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, more or less. The |
||
exc = _format_exception(exc_info) | ||
|
||
if exc: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this would pass any
None
/Falsy exc_info in the event dict into the formatter. Is this expected?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to
if exc_info and exc_info != (None, None, None)
. This should work.Not happy though, that
exc_info
can be literally anything. I will take a look if this can somehow be changed/improved.