-
Notifications
You must be signed in to change notification settings - Fork 131
Fix notice_error logic for non-iterable exceptions. #1564
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -360,16 +360,23 @@ def _observe_exception(self, exc_info=None, ignore=None, expected=None, status_c | |
| return fullname, message, message_raw, tb, is_expected | ||
|
|
||
| def notice_error(self, error=None, attributes=None, expected=None, ignore=None, status_code=None): | ||
| def error_is_iterable(error): | ||
| return hasattr(error, "__iter__") and not isinstance(error, (str, bytes)) | ||
|
|
||
| def none_in_error(error): | ||
| return error_is_iterable(error) and None in error | ||
|
|
||
| attributes = attributes if attributes is not None else {} | ||
|
|
||
| # If no exception details provided, use current exception. | ||
|
|
||
| # Pull from sys.exc_info if no exception is passed | ||
| if not error or None in error: | ||
| # Pull from sys.exc_info() if no exception is passed | ||
| # Check that the error exists and that it is a fully populated iterable | ||
| if not error or none_in_error(error) or (error and not error_is_iterable(error)): | ||
| error = sys.exc_info() | ||
|
|
||
| # If no exception to report, exit | ||
| if not error or None in error: | ||
| if not error or none_in_error(error) or (error and not error_is_iterable(error)): | ||
|
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. This line should only ever deal with the output of sys.exc_info, which is guaranteed to be a tuple of |
||
| return | ||
|
|
||
| exc, value, tb = error | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If the intent of this change is to make it possible to pass in an instance of BaseException to be able to report it then this change is overcomplicated and unfortunately looks to be introducing a bug.
Take for example this code:
Previously the exception instance was not allowed as an input, and would have caused an error that would crash.
With this PR's changes instead, it silently reports the wrong exception. The user is trying to pass in an exception to report, but as written this will trigger a pull from
sys.exc_info()which will yield back the tuple forexc2, instead ofexc1which was passed in.There's also a lot of complexity in these
ifstatements now that I don't care for, as well as a bunch of new function calls that add overhead. Instead, I propose we construct a tuple in the form we expect from the exception instance if and only if the error passed in is an instance of BaseException and it has a non None__traceback__attribute.