fix(retry): raise a proper exception type (S5632) #71
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "Claude/backup-script:fix/issue-30-S5632-retry-non-exception-raise"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #30
Problem
SonarQube rule S5632 flags
raise last_excatcore/retry.py:127asraising a non-
BaseExceptionvalue.last_excis typedBaseException | Noneand is never reassigned anywhere in the currentimplementation — at the only point it can be raised, it is always
None,which is not a valid raise target.
Fix
Replace
raise last_excwithraise RuntimeError(...) from last_exc. Theexplicit
RuntimeErroris guaranteed to be a real exception type, and thefrom last_excclause preserves any chained cause if a future patch everpopulates the variable. The
if last_exc is not None:guard becomestype-safe for the
fromclause (which requiresBaseException | None).Verification
pytest -q tests/unit/— all 211 tests pass, includingtests/unit/test_retry_policy.pywhich covers the retry loop on bothretried and non-retried exception types.
mypy --strict src/gardien/core/— clean (10 source files, no issues).Note
Overlaps with #29 — the surrounding
if last_exc is not None:identitycheck is the S5727 companion bug. This PR only changes the raise target;
it deliberately leaves the identity check in place so that #29 can be
reviewed independently. Either PR landing first will leave the other
mergeable with a trivial conflict resolution.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.