-
Notifications
You must be signed in to change notification settings - Fork 535
feat: Make timeout error log cleaner #1170
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
15 commits
Select commit
Hold shift + click to select a range
9b32634
Draft
Pijukatel cf90e33
Hacky way of cleaning.
Pijukatel e35bdbf
More robust log filtering
Pijukatel 9499491
Format and cleanup
Pijukatel 19bc9c5
Further compress the error log for timeouts
Pijukatel 5ae90bb
Ignore stac trace highlighters as well
Pijukatel af2bf1f
Properly strip pep657 highlighters
Pijukatel 3bbdcec
Generalize one line summary for other errors as well
Pijukatel c526354
Expand strip pep657 regexp
Pijukatel c2d9f23
Merge remote-tracking branch 'origin/master' into cleaner-error-logging
Pijukatel d1bc4ad
Merge remote-tracking branch 'origin/master' into cleaner-error-logging
Pijukatel 3a6a59d
Regenerate lock with uv=0.6.15
Pijukatel 95c62e0
Update retry error based on discussion 2 lines
Pijukatel 284a9cc
Merge remote-tracking branch 'origin/master' into cleaner-error-logging
Pijukatel 415038b
Merge remote-tracking branch 'origin/master' into cleaner-error-logging
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,64 @@ | ||
| import asyncio | ||
| import re | ||
| import traceback | ||
|
|
||
|
|
||
| def _get_only_innermost_exception(error: BaseException) -> BaseException: | ||
| """Get innermost exception by following __cause__ and __context__ attributes of exception.""" | ||
| if error.__cause__: | ||
| return _get_only_innermost_exception(error.__cause__) | ||
| if error.__context__: | ||
| return _get_only_innermost_exception(error.__context__) | ||
| # No __cause__ and no __context__, this is as deep as it can get. | ||
| return error | ||
|
|
||
|
|
||
| def _get_filtered_traceback_parts_for_asyncio_timeout_error(traceback_parts: list[str]) -> list[str]: | ||
| """Extract only the most relevant traceback parts from stack trace.""" | ||
| ignore_pattern = ( | ||
| r'([\\/]{1}asyncio[\\/]{1})|' # internal asyncio parts | ||
| r'(Traceback \(most recent call last\))|' # common part of the stack trace formatting | ||
| r'(asyncio\.exceptions\.CancelledError)' # internal asyncio exception | ||
| ) | ||
| return [ | ||
| _strip_pep657_highlighting(traceback_part) | ||
| for traceback_part in traceback_parts | ||
| if not re.findall(ignore_pattern, traceback_part) | ||
| ] | ||
|
|
||
|
|
||
| def _strip_pep657_highlighting(traceback_part: str) -> str: | ||
| """Remove PEP 657 highlighting from the traceback.""" | ||
| highlight_pattern = r'(\n\s*~*\^+~*\n)$' | ||
| return re.sub(highlight_pattern, '\n', traceback_part) | ||
|
|
||
|
|
||
| def reduce_asyncio_timeout_error_to_relevant_traceback_parts( | ||
| timeout_error: asyncio.exceptions.TimeoutError, | ||
| ) -> list[str]: | ||
| innermost_error_traceback_parts = _get_traceback_parts_for_innermost_exception(timeout_error) | ||
| return _get_filtered_traceback_parts_for_asyncio_timeout_error(innermost_error_traceback_parts) | ||
|
|
||
|
|
||
| def _get_traceback_parts_for_innermost_exception(error: Exception) -> list[str]: | ||
| innermost_error = _get_only_innermost_exception(error) | ||
| return traceback.format_exception( | ||
| type(innermost_error), value=innermost_error, tb=innermost_error.__traceback__, chain=True | ||
| ) | ||
|
|
||
|
|
||
| def get_one_line_error_summary_if_possible(error: Exception) -> str: | ||
| if isinstance(error, asyncio.exceptions.TimeoutError): | ||
| most_relevant_part = reduce_asyncio_timeout_error_to_relevant_traceback_parts(error)[-1] | ||
| else: | ||
| traceback_parts = _get_traceback_parts_for_innermost_exception(error) | ||
| # Commonly last traceback part is type of the error, and the second last part is the relevant file. | ||
| # If there are not enough traceback parts, then we are not sure how to summarize the error. | ||
| relevant_traceback_part_index_from_end = 2 | ||
| most_relevant_part = _strip_pep657_highlighting( | ||
| _get_traceback_parts_for_innermost_exception(error)[-relevant_traceback_part_index_from_end] | ||
| if len(traceback_parts) >= relevant_traceback_part_index_from_end | ||
| else '' | ||
| ) | ||
|
|
||
| return most_relevant_part.strip('\n ').replace('\n', ', ') |
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.
Uh oh!
There was an error while loading. Please reload this page.