fix(statistics): handle exceptions without a traceback in ErrorTracker#2035
Merged
Merged
Conversation
…out a traceback `ErrorTracker._get_file_and_line` called `traceback.extract_tb(error.__traceback__)` and unconditionally indexed the last frame. For an exception that was never raised (its `__traceback__` is `None`), `extract_tb` returns an empty list, so `[-1]` raised `IndexError` out of the best-effort `ErrorTracker.add` statistics path. Guard the empty case and return an empty file-and-line string, matching the behaviour when `show_file_and_line_number` is disabled. Add a regression test that adds a freshly constructed exception and asserts it is tracked without crashing. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
vdusek
approved these changes
Jul 7, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ErrorTracker._get_file_and_linecallstraceback.extract_tb(error.__traceback__)and then unconditionally reads the last frame with
error_traceback[-1]. For anexception whose
__traceback__isNone(for example a freshly constructedexception that was never raised),
extract_tbreturns an empty list, so[-1]raises
IndexError._get_file_and_lineis called fromErrorTracker.add, which is a best-effortstatistics path, so a valid
Exceptionargument that happens to carry notraceback crashes the tracker instead of being counted.
This guards the empty case: when there are no traceback frames, return an empty
file-and-line string, which is exactly the value the method already returns when
show_file_and_line_numberis disabled. That empty value is already handledeverywhere downstream (it is used as the top-level grouping key in
add, and_get_error_reprrenders an empty file-and-line as no prefix), so grouping andthe error representation stay correct.
ErrorTracker._get_file_and_lineand return''.Issues
argsin_get_error_messageforErrorTracker#1181.Testing
test_error_tracker_error_without_tracebackintests/unit/_statistics/test_error_tracker.py. It constructsValueError('Some value error')(never raised, so
__traceback__isNone), callsawait error_tracker.add(...),and asserts
total == 1,unique_error_count == 1, and thatget_most_common_errors()reports'ValueError:Some value error'(name andmessage, with no file:line prefix). The test fails with
IndexErroronmasterand passes with the fix.uv run pytest tests/unit/_statistics/test_error_tracker.py-> 14 passed (offline).uv run poe lint-> all checks passed.uv run poe type-checkon the changed files -> passed. (The full type-check reportspre-existing diagnostics only in the unrelated
_pydantic_aimodule, which needs anoptional dependency; the changed files are clean.)
Checklist
The diff (2 files, +16)