Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Twig][Exception] Unknown filter instead of real exception message #25610

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

Closed
fancyweb opened this issue Dec 27, 2017 · 9 comments
Closed

[Twig][Exception] Unknown filter instead of real exception message #25610

fancyweb opened this issue Dec 27, 2017 · 9 comments

Comments

@fancyweb
Copy link
Contributor

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.4

Since 3.4 (bug is not there in 3.3), if one of my app Twig extensions throws an exception, I end up with the following message instead of the real exception message :

 (2/2) Twig_Error_Syntax

Unknown "abbr_class" filter.

From what I've found, this is because my app Twig extension is added before the Symfony Twig Bridge CodeExtension which is the one that adds the abbr_class Twig filter. This filter is used in the default exception.html.twig template and ends up being never registered. However, it seems it is also the case in previous Symfony version so I don't get why it only bugs in 3.4...

Reproducer incoming

@fancyweb
Copy link
Contributor Author

You can see the bug if you use this project : https://github.com/fancyweb/symfony-standard/tree/issue-25610.

Start the server and go on the default page.

@avo7
Copy link

avo7 commented Dec 28, 2017

Happened to me as well, in Symfony 4.0, right after running Ubuntu update. PHP was not updated (7.1.7), so I'm not sure what's the reason.

@xabbuh
Copy link
Member

xabbuh commented Dec 28, 2017

You are right. This will be fixed by #25601. However, I am closing here anyway as we already have #25256 to keep track of it.

@xabbuh xabbuh closed this as completed Dec 28, 2017
@fancyweb
Copy link
Contributor Author

fancyweb commented Jan 8, 2018

@xabbuh #25601 was merged and released in 3.4.3 but the problem I described is still the same. Could you reopen please ?

@xabbuh
Copy link
Member

xabbuh commented Jan 8, 2018

Do you mean you don't get the more helpful error message?

@fancyweb
Copy link
Contributor Author

fancyweb commented Jan 8, 2018

I get this
1

instead of my exception.

Edit : the real exception is way below, which is not intuitive.

@xabbuh
Copy link
Member

xabbuh commented Jan 8, 2018

Can you create a small example project that allows to reproduce the issue?

Never mind, I am looking at the project you linked to in #25610 (comment).

@fancyweb
Copy link
Contributor Author

fancyweb commented Jan 8, 2018

The link is in the second message of this issue.

@stof
Copy link
Member

stof commented Jan 8, 2018

hmm, if the instantiation of Twig extensions is triggering exceptions, this would indeed leave Twig in an unusable state (and so create issues when trying to use it to render the custom exception page)

@xabbuh xabbuh reopened this Jan 9, 2018
fabpot added a commit that referenced this issue Feb 7, 2018
This PR was squashed before being merged into the 3.4 branch (closes #25756).

Discussion
----------

[TwigBundle] Register TwigBridge extensions first

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25610
| License       | MIT
| Doc PR        | -

The only extension that is really needed to display the current exception page is the `CodeExtension` so we could only prepend this one. However, prepending all of them seems safer to me in the long term.

Also I deeply looked into why this problem only appeared in 3.4 and found the reason. Before 3.4 it actually never reaches the `ExceptionController` for this kind of error because it cannot be resolved because it needs a twig instance in its constructor. This instance is directly taken from the container. Before 3.4 when an exception is thrown when you try to get a service from the container, the instance stored in the `$services` array is unset which is not the case in further versions. So in 3.4+, the `ExceptionController` can be resolved because the instance of twig is still in the container even after the initial exception.

It also means these kind of exceptions are displayed with bugs on all versions before 3.4 I guess. Actually it shows the message 2 times : one for the initial exception and the other one when it tries to resolve the `ExceptionController`.

Maybe another solution might be to use a dedicated twig instance with the right settings just for the exception page ?

Commits
-------

c8465ed [TwigBundle] Register TwigBridge extensions first
symfony-splitter pushed a commit to symfony/twig-bundle that referenced this issue Feb 7, 2018
This PR was squashed before being merged into the 3.4 branch (closes #25756).

Discussion
----------

[TwigBundle] Register TwigBridge extensions first

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#25610
| License       | MIT
| Doc PR        | -

The only extension that is really needed to display the current exception page is the `CodeExtension` so we could only prepend this one. However, prepending all of them seems safer to me in the long term.

Also I deeply looked into why this problem only appeared in 3.4 and found the reason. Before 3.4 it actually never reaches the `ExceptionController` for this kind of error because it cannot be resolved because it needs a twig instance in its constructor. This instance is directly taken from the container. Before 3.4 when an exception is thrown when you try to get a service from the container, the instance stored in the `$services` array is unset which is not the case in further versions. So in 3.4+, the `ExceptionController` can be resolved because the instance of twig is still in the container even after the initial exception.

It also means these kind of exceptions are displayed with bugs on all versions before 3.4 I guess. Actually it shows the message 2 times : one for the initial exception and the other one when it tries to resolve the `ExceptionController`.

Maybe another solution might be to use a dedicated twig instance with the right settings just for the exception page ?

Commits
-------

c8465ed97f [TwigBundle] Register TwigBridge extensions first
@fabpot fabpot closed this as completed Feb 7, 2018
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

7 participants