Route thrown exceptions through throw_if/throw_unless/throw_anyway helpers - #11
Open
ashraful1971 wants to merge 1 commit into
Open
Route thrown exceptions through throw_if/throw_unless/throw_anyway helpers#11ashraful1971 wants to merge 1 commit into
ashraful1971 wants to merge 1 commit into
Conversation
…lpers WordPress Plugin Check flags every bare `throw new X(...)` as ExceptionNotEscaped (149 of 164 PCP errors against src/), since consuming plugins ship this framework's src/ directly and the sniff assumes each throw site should escape its own output rather than bubbling up to a central handler. Converting call sites to the existing throw_if/ throw_unless/throw_anyway helpers avoids the flag without changing any exception's class, message, or trigger condition, since the sniff only registers on the bare `throw` token. Also widens throw_if/throw_unless/throw_anyway's $message parameter to untyped (two InvalidCastException call sites pass a Model instance, not a string) and adds a new throw_exception() helper for the couple of sites that throw an already-built exception object (ThrottleRequests' rejection() and ValidationException::with_errors()) rather than constructing one from a class + args. Verified: composer phpcs && composer test:unit pass; a fresh Plugin Check scan against src/ shows ExceptionNotEscaped findings dropped from 149 to 0, with total errors down from 164 to 15 (the remaining findings are a separate, unrelated batch of non-exception issues for a follow-up change).
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.
WordPress Plugin Check flags every bare
throw new X(...)as ExceptionNotEscaped (149 of 164 PCP errors against src/), since consuming plugins ship this framework's src/ directly and the sniff assumes each throw site should escape its own output rather than bubbling up to a central handler. Converting call sites to the existing throw_if/ throw_unless/throw_anyway helpers avoids the flag without changing any exception's class, message, or trigger condition, since the sniff only registers on the barethrowtoken.Also widens throw_if/throw_unless/throw_anyway's $message parameter to untyped (two InvalidCastException call sites pass a Model instance, not a string) and adds a new throw_exception() helper for the couple of sites that throw an already-built exception object (ThrottleRequests' rejection() and ValidationException::with_errors()) rather than constructing one from a class + args.
Verified: composer phpcs && composer test:unit pass; a fresh Plugin Check scan against src/ shows ExceptionNotEscaped findings dropped from 149 to 0, with total errors down from 164 to 15 (the remaining findings are a separate, unrelated batch of non-exception issues for a follow-up change).