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

Ignore exceptions from undefined handlers when using the guard tag #4511

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

fabpot
Copy link
Contributor

@fabpot fabpot commented Dec 19, 2024

Fixes #4505

@fabpot fabpot mentioned this pull request Dec 19, 2024
@fabpot fabpot force-pushed the guard-fix-exception branch from 1e05a3c to 7a473c6 Compare December 19, 2024 07:41
@fabpot fabpot force-pushed the guard-fix-exception branch from 7a473c6 to b53c639 Compare December 19, 2024 14:11
@fabpot fabpot merged commit c1f7277 into twigphp:3.x Dec 20, 2024
49 of 50 checks passed
@fabpot fabpot deleted the guard-fix-exception branch December 20, 2024 06:51
@javiereguiluz
Copy link
Contributor

Thanks for merging this and for releasing it as part of Twig 3.18.0.

Sadly, this change didn't fix the issue for me. See the failing tests:

https://github.com/EasyCorp/EasyAdminBundle/actions/runs/12550268707

@xabbuh
Copy link
Contributor

xabbuh commented Jan 3, 2025

The reason for the failure Javier observes (and also the reason for #4528 (comment)) is that the following subparseIgnoreUnknownTwigCallables() in GuardTokenParser also throws a SyntaxError.

@javiereguiluz
Copy link
Contributor

Maybe we should reopen this issue to not forget about it. Thanks.

@stof
Copy link
Member

stof commented Jan 17, 2025

I found the root cause of the issue.

if (!$function = $this->env->getFunction($name)) {
relies on getting a falsy value for non-existent functions before deciding to ignore them or to fail. To fully support the case of undefined handlers throwing a SyntaxError to provide a custom message, we also need to catch exceptions in that case (this was not caught by tests because this PR did not implement a functional test covering that case but only a unit test, which does not catch that it handles only half of the places that need to be handled).
I will try to do a PR with the missing part.

@javiereguiluz we cannot reopen because this is not an issue. It is the merged PR implementing the change.

fabpot added a commit that referenced this pull request Feb 9, 2025
…er in guard (stof)

This PR was merged into the 3.x branch.

Discussion
----------

Fix support for ignoring syntax erros in an undefined handler in guard

This fixes the issue discussed in #4511 (comment) so that ignoring SyntaxError from undefined handlers wanting to provide a custom message actually works in the `{% guard %}` tag.

This adds an integration test covering that behavior to ensure it works.

Commits
-------

3794efe Fix support for ignoring syntax erros in an undefined handler in guard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Issue with the guard tag
4 participants