-
Notifications
You must be signed in to change notification settings - Fork 708
feat: Extend ErrorTracker with error grouping #1014
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
10 commits
Select commit
Hold shift + click to select a range
39a3bf7
WIP
Pijukatel 682eacc
Basic structure
Pijukatel 0388886
Basic filtering working.
Pijukatel 433dadb
Add most common errors
Pijukatel 09b4752
Merge remote-tracking branch 'origin/master' into error-tracker
Pijukatel dacc810
Add detailed message option.
Pijukatel 104cf26
Update comments
Pijukatel 96b5c51
Update _error_tracker.py
Pijukatel 39c5c28
Review comments
Pijukatel 6784a0e
Remove stack from variable names
Pijukatel 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
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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import traceback | ||
|
|
||
| import pytest | ||
|
|
||
| from crawlee.statistics._error_tracker import ErrorTracker | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ('error_tracker', 'expected_unique_errors'), | ||
| [ | ||
| (ErrorTracker(), 4), | ||
| (ErrorTracker(show_file_and_line_number=False), 3), | ||
| (ErrorTracker(show_error_name=False), 3), | ||
| (ErrorTracker(show_error_message=False), 3), | ||
| (ErrorTracker(show_error_name=False, show_file_and_line_number=False), 2), | ||
| (ErrorTracker(show_file_and_line_number=False, show_error_message=False), 2), | ||
| (ErrorTracker(show_error_name=False, show_file_and_line_number=False, show_error_message=False), 1), | ||
| ], | ||
| ) | ||
| def test_error_tracker_counts(error_tracker: ErrorTracker, expected_unique_errors: int) -> None: | ||
| """Use different settings of `error_tracker` and test unique errors count.""" | ||
|
|
||
| for error in [ | ||
| Exception('Some value error abc'), | ||
| ValueError('Some value error abc'), # Different type, different error | ||
| ValueError('Some value error cde'), # Same type and similar message to previous, considered the same. | ||
| ValueError( | ||
| 'Another value error efg' | ||
| ), # Same type, but too different message to previous, considered different. | ||
| ]: | ||
| try: | ||
| raise error # Errors raised on same line | ||
| except Exception as e: # noqa:PERF203 | ||
| error_tracker.add(e) | ||
|
|
||
| try: | ||
| raise ValueError('Some value error abc') # Same as one previous error, but different line. | ||
| except Exception as e: | ||
| error_tracker.add(e) | ||
|
|
||
| assert error_tracker.total == 5 | ||
| assert error_tracker.unique_error_count == expected_unique_errors | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ('message_1', 'message_2', 'expected_generic_message'), | ||
| [ | ||
| ('Some error number 123', 'Some error number 456', 'Some error number ***'), | ||
| ('Some error number 123 456', 'Some error number 123 456 789', 'Some error number 123 456 ***'), | ||
| ('Some error number 0 0 0', 'Some error number 1 0 1', 'Some error number *** 0 ***'), | ||
| ], | ||
| ) | ||
| def test_error_tracker_similar_messages_full_stack( | ||
| message_1: str, message_2: str, expected_generic_message: str | ||
| ) -> None: | ||
| """Test that similar messages collapse into same group with generic name that contains wildcard symbols.""" | ||
| error_tracker = ErrorTracker() | ||
| for error in [ | ||
| KeyError(message_1), | ||
| KeyError(message_1), | ||
| KeyError(message_1), | ||
| ValueError(message_1), | ||
| ValueError(message_2), | ||
| RuntimeError(message_2), | ||
| ]: | ||
| try: | ||
| raise error # Errors raised on the same line | ||
| except Exception as e: # noqa:PERF203 | ||
| error_tracker.add(e) | ||
| line = traceback.extract_tb(e.__traceback__)[0].lineno | ||
|
|
||
| file_name = __file__.split('/')[-1] | ||
| errors = error_tracker.get_most_common_errors() | ||
| assert errors[0][0] == f'{file_name}:{line}:KeyError:{message_1}' | ||
| assert errors[0][1] == 3 | ||
| assert errors[1][0] == f'{file_name}:{line}:ValueError:{expected_generic_message}' | ||
| assert errors[1][1] == 2 | ||
| assert errors[2][0] == f'{file_name}:{line}:RuntimeError:{message_2}' | ||
| assert errors[2][1] == 1 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ('show_full_message', 'expected_message'), | ||
| [ | ||
| (True, 'Error line 1\n Error line 2'), | ||
| (False, 'Error line 1'), | ||
| ], | ||
| ) | ||
| def test_show_full_message(*, show_full_message: bool, expected_message: str) -> None: | ||
| """Test error message settings with both options of `show_full_message`.""" | ||
| error_tracker = ErrorTracker( | ||
| show_error_name=False, show_file_and_line_number=False, show_full_message=show_full_message | ||
| ) | ||
|
|
||
| try: | ||
| raise RuntimeError('Error line 1\n Error line 2') # Errors raised on the same line | ||
| except Exception as e: | ||
| error_tracker.add(e) | ||
|
|
||
| assert error_tracker.get_most_common_errors()[0][0] == expected_message |
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.
I'm kinda surprised by the choice of
_here - I think it might get mixed up with legit underscores in python error messages.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.
Maybe
***will be better in Python context