Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate options for forbidding throwing exceptions in specific directories. #210

Open
herregroen opened this issue May 12, 2020 · 3 comments

Comments

@herregroen
Copy link
Contributor

herregroen commented May 12, 2020

In our integrations directory we have all our classes that hook into WordPress filters and actions. As any exceptions thrown here in public functions wouldn't be able to be caught by us these would likely lead to fatals.

So ideally we'd be able to specify directories where throwing exceptions would be forbidden in public functions under the expectations that these would be hooked into WordPress filters ( if it's possible to detect which functions are hooked into filters or actions that would be excellent as well but I can see that being rather more difficult ).

So the following code would be forbidden only in public functions in a given directory:

throw new Exception( "Error!" );

While the following would be allowed:

return false;
@jrfnl
Copy link
Collaborator

jrfnl commented May 12, 2020

if it's possible to detect which functions are hooked into filters or actions that would be excellent as well but I can see that being rather more difficult

If a function hook-in (add_filter()/add_action()) is always done in the same file as the function is declared in, this would be possible, but that would need to be a condition (which could be checked by a separate sniff).

@herregroen
Copy link
Contributor Author

In the case of our integrations that is the case.

@jrfnl
Copy link
Collaborator

jrfnl commented Sep 22, 2023

We discussed this and basically this shouldn't be folder based, but based on detection of a function being hooked into a filter/action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants