Skip to content

RequirePreviousExceptionPass: accept exception passed to nested call - #369

Merged
janedbal merged 1 commit into
masterfrom
jn-previous-exception-nested-call
Oct 1, 2026
Merged

janedbal merged 1 commit into
masterfrom
jn-previous-exception-nested-call

Conversation

@janedbal

@janedbal janedbal commented Oct 1, 2026

Copy link
Copy Markdown
Member

The rule now also searches arguments of nested calls for the caught exception. Before, it checked only the direct arguments of the thrown call.

This code caused a false positive:

try {
    // ...
} catch (LoginLockedException $e) {
    throw new HttpException(401, $msg, TooManyLoginAttemptsException::fromLock($e));
}
  • The rule searches nested calls at any depth, e.g. new Outer(Inner::wrap(new Other('x', 0, $e))).
  • A nested first-class callable, e.g. MyException::create(...), does not count as a pass.
  • Limitation: the rule does not check if the nested call chains $e as previous. A nested call that only reads $e also counts as a pass.

Co-Authored-By: Claude Code

The rule now also searches arguments of nested calls for the caught
exception. Before, it checked only the direct arguments of the thrown
call. So it reported a false positive for this code:

    throw new HttpException(401, $msg, MyException::fromPrevious($e));

A nested first-class callable, e.g. `MyException::create(...)`, does not
count as a pass.

Co-Authored-By: Claude Code
@janedbal
janedbal marked this pull request as ready for review October 1, 2026 13:38
@janedbal
janedbal merged commit 67e54e4 into master Oct 1, 2026
22 checks passed
@janedbal
janedbal deleted the jn-previous-exception-nested-call branch October 1, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant