You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the 14.0 release we ran into unfortunate issues where we were not catching all our own exceptions, thus leading to fatals.
Because of this we'd like to explore options for sniffs that forbid the usage of functions that can throw exceptions without using try and catch.
So the following would be invalid code:
function_that_can_throw_exception();
With the following being a valid replacement;
try {
function_that_can_throw_exception();
}
catch( Exception$e ) {
// Anything, possibly even rethrowing the exception with added context.// In which case this function can't be used without catching it.
}
Even rethrowing the exception would help with developer awareness that exceptions have to be dealt with and can't simply be left.
The text was updated successfully, but these errors were encountered:
Is this only global/namespaced function calls or also method calls ?
Is there a list available of the functions which throw exceptions ?
This would need to be a list-based sniff as 1) PHPCS only scans a codebase once, so can't keep track of where it has seen a throw statement and 2) add-on plugins may use functions which throw from Free/Premium.
This would also be for both function calls as well as for methods. For methods there'd be the complexity of finding out what the object is, can PHPCS determine this if either the object is passed as a type-hinted argument, constructed in the same function or is a type-hinted property?
Although PHPCS only scanning once does make it even more complex. Ideally we'd be able to detect which functions throw exceptions, adding free and/or premium as a dev-dependency to projects which use them to ensure the code is also available there.
First thing that comes to mind would be to use https://github.com/nikic/PHP-Parser to dynamically create a list of all functions and methods that throw exceptions and use that as the basis for a sniff.
With the 14.0 release we ran into unfortunate issues where we were not catching all our own exceptions, thus leading to fatals.
Because of this we'd like to explore options for sniffs that forbid the usage of functions that can throw exceptions without using
try
andcatch
.So the following would be invalid code:
function_that_can_throw_exception();
With the following being a valid replacement;
Even rethrowing the exception would help with developer awareness that exceptions have to be dealt with and can't simply be left.
The text was updated successfully, but these errors were encountered: