Match only_rerun against wrapped exception causes - #364
Merged
Conversation
Wrapped errors such as raise RuntimeError(...) from MemoryError(...) were matched on the outer type and message only, so --only-rerun MemoryError did not retry them.
icemac
reviewed
Sep 10, 2026
icemac
left a comment
Contributor
There was a problem hiding this comment.
Automated review of this PR. Four findings; the first two are behavioral regressions I reproduced against master.
The root cause of both is that _try_match_error is shared by _matches_any_only_rerun_error and _matches_any_rerun_except_error, so walking the exception chain broadens both filters — and for --rerun-except, broader means fewer reruns.
— Comment created by Claude
--rerun-except matching implicit __context__ skipped reruns for exceptions raised inside except/finally. only_rerun still walks the full chain.
icemac
approved these changes
Sep 11, 2026
icemac
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thank you for the PR.
icemac
enabled auto-merge (squash)
September 11, 2026 06:24
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.
Fixes #353.
--only-rerun/only_rerun(and--rerun-except) match the outermost exception only. A transient error wrapped withraise ... fromis not retried, even when the inner type is exactly what the filter is for.The same test without the wrapper reruns as expected.
_try_match_errorbuilt the match string fromexcinfo.type/excinfo.valueand never walked__cause__or__context__.The matcher now walks that chain (skipping a context suppressed by
raise ... from None) and treats a hit on any linked exception as a match. Existing outer-exception matches are unchanged.Regression tests cover a
__cause__wrap, an implicit__context__wrap, the exception-class form ofonly_rerun,rerun_excepton a wrapped error, a suppressed context, and a non-matching control.