Skip to content

Adds exception template variable available in custom error pages #13214

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

Merged
merged 1 commit into from
Feb 22, 2020
Merged

Adds exception template variable available in custom error pages #13214

merged 1 commit into from
Feb 22, 2020

Conversation

dbrumann
Copy link
Contributor

Alongside status_code and status_text you also have access to exception template variable in custom error pages.

@wouterj
Copy link
Member

wouterj commented Feb 22, 2020

If I look at the TwigErrorRenderer, this variable contains a flat PHP string that is generated by the HtmlErrorRenderer. Are we sure we get an exception object in this variable?

@dbrumann
Copy link
Contributor Author

I am just playing around with it and I got an error when assuming it was a string:

[2020-02-22T09:49:00.650785+00:00] request.CRITICAL: Uncaught PHP Exception Error: "Object of class Symfony\Component\ErrorHandler\Exception\FlattenException could not be converted to string" at /Users/dbr/workspace/error-demo/var/cache/prod/twig/ac/ac9e7bd5dee35e014b7f05a2dc891d2edd36162209f88af6abe5aa1fb054ffb1.php line 69 {"exception":"[object] (Error(code: 0): Object of class Symfony\\Component\\ErrorHandler\\Exception\\FlattenException could not be converted to string at /Users/dbr/workspace/error-demo/var/cache/prod/twig/ac/ac9e7bd5dee35e014b7f05a2dc891d2edd36162209f88af6abe5aa1fb054ffb1.php:69)"} []

I will have another look into it, to make sure it wasn't a fluke.

Copy link
Member

@wouterj wouterj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, you're completely correct. The HtmlErrorRenderer returns $exception->setAsString(...), which does not return a string 🤦‍♂️ . Using fluent PHP methods in this way makes code really confusing to read imho.

Anyway, this PR is correct. 👍

@dbrumann
Copy link
Contributor Author

I agree, it's a bit unfortunate. I will open an issue in symfony/symfony to straighten out the naming there and then update the docs accordingly.

@javiereguiluz javiereguiluz added this to the 4.4 milestone Feb 22, 2020
@javiereguiluz
Copy link
Member

Thanks Denis.

@javiereguiluz javiereguiluz merged commit 7ea412c into symfony:4.4 Feb 22, 2020
@dbrumann dbrumann deleted the error_handler/twig_variables branch February 22, 2020 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants