Skip to content

[TwigBundle] Fix error page preview for custom twig.exception_controller #12147

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
wants to merge 2 commits into from
Closed

[TwigBundle] Fix error page preview for custom twig.exception_controller #12147

wants to merge 2 commits into from

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented Oct 6, 2014

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #12147
License MIT
Doc PR n/a

The testErrorPageAction() always used the showAction() of TwigBundle's ExceptionController.
You can, however, configure an alternate controller by setting twig.exception_controller.

Thus, in order to get a proper preview, we need to forward to this configured controller (which
may be the default one).

This requires us to pass an additional parameter to ExceptionController::showAction to be able to
get the error page even if configured otherwise in the constructor.

(The other approach would have been to fiddle around with ExceptionController's debug flag through a setter when going through the preview action, but that would have been even more messy.)

@mpdude mpdude changed the title [TwigBundle] Fix that error page preview does not work for custom twig.exception_controller [TwigBundle] Fix error page preview for custom twig.exception_controller Oct 6, 2014
…g.exception_controller

The testErrorPageAction() always used the showAction() of TwigBundle's ExceptionController.
You can, however, configure an alternate controller by setting twig.exception_controller.

Thus, in order to get a proper preview, we need to forward to this configured controller (which
may be the default one).

This requires us to pass an additional parameter to ExceptionController::showAction to be able to
get the *error* page even if configured otherwise in the constructor.
@stof stof added the TwigBundle label Oct 6, 2014
weaverryan added a commit to symfony/symfony-docs that referenced this pull request Oct 19, 2014
This PR was merged into the master branch.

Discussion
----------

Document error page preview (Symfony ~2.6)

This adds documentation how to use the new preview feature from symfony/symfony#12096 (and hopefully the fix in symfony/symfony#12147).

Commits
-------

d02c7c4 Updates according to GH feedback
8e70373 Document error page preview in Symfony ~2.6 (#4293)
@lyrixx
Copy link
Member

lyrixx commented Oct 23, 2014

@mpdude In your PR description, the link to "Fixed tickets" targets this PR.

@mpdude
Copy link
Contributor Author

mpdude commented Oct 23, 2014

Yes, this is the issue that describes the problem an provides a fix for it. Should I do it differently...?

@@ -26,47 +27,43 @@
class ExceptionController
{
protected $twig;
protected $debug;
protected $showException;
Copy link
Contributor

Choose a reason for hiding this comment

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

bc break

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. Is that an issue even if it is not @api?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we try to avoid Bc breaks whenever possible. So, the old name should be kept.

@mpdude
Copy link
Contributor Author

mpdude commented Nov 2, 2014

If I am not missing anything, this should be 100% BC now.

*
* @return Response
*/
protected function createResponse(Request $request, FlattenException $exception, $debug, DebugLoggerInterface $logger = null, $currentContent = '')
Copy link
Member

Choose a reason for hiding this comment

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

For others, this method was introduced in 2.6, so removing it is not a BC break.

Copy link
Member

Choose a reason for hiding this comment

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

but only if we merge this before making 2.6 stable

@fabpot
Copy link
Member

fabpot commented Nov 2, 2014

👍

@@ -48,25 +57,20 @@ public function __construct(\Twig_Environment $twig, $debug)
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
{
$currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
$showException = $request->get('showException', $this->debug); // As opposed to an additional parameter, this maintains BC
Copy link
Member

Choose a reason for hiding this comment

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

should be $request->attributes->get('showException' actually

@stof
Copy link
Member

stof commented Nov 21, 2014

Except for the change I requested above, this is fine for me

@fabpot
Copy link
Member

fabpot commented Nov 21, 2014

Thank you @mpdude.

fabpot added a commit that referenced this pull request Nov 21, 2014
…ption_controller (mpdude)

This PR was submitted for the master branch but it was merged into the 2.6 branch instead (closes #12147).

Discussion
----------

[TwigBundle] Fix error page preview for custom twig.exception_controller

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #12147
| License       | MIT
| Doc PR        | n/a

The `testErrorPageAction()` always used the `showAction()` of TwigBundle's `ExceptionController`.
You can, however, configure an alternate controller by setting `twig.exception_controller`.

Thus, in order to get a proper preview, we need to forward to this configured controller (which
may be the default one).

This requires us to pass an additional parameter to `ExceptionController::showAction` to be able to
get the *error* page even if configured otherwise in the constructor.

(The other approach would have been to fiddle around with `ExceptionController`'s `debug` flag through a setter when going through the preview action, but that would have been even more messy.)

Commits
-------

2065e00 [TwigBundle] Fix error page preview for custom twig.exception_controller
@fabpot
Copy link
Member

fabpot commented Nov 21, 2014

I've fixed the comment from @stof in 7bb1abe

@fabpot fabpot closed this Nov 21, 2014
@fabpot
Copy link
Member

fabpot commented Nov 21, 2014

@mpdude Actually, that breaks tests :( Can you have a look at the problems? https://travis-ci.org/symfony/symfony/jobs/41700375

@mpdude
Copy link
Contributor Author

mpdude commented Nov 21, 2014

It’s the change in 7bb1abe that @stof requested.

Is the way I set up the request wrong?

That parameter does not show up in $request->attributes.

@xabbuh
Copy link
Member

xabbuh commented Nov 21, 2014

@mpdude Can you have a look at #12539?

@stof
Copy link
Member

stof commented Nov 21, 2014

hmm yeah, you are creating the request with a query string setting, not an attribute (so you are not testing the same thing than what the preview controller uses)

@mpdude
Copy link
Contributor Author

mpdude commented Nov 21, 2014

Fix (at least for one issue) is in #12541.

@mpdude
Copy link
Contributor Author

mpdude commented Nov 21, 2014

Where can I find more about the different semantics of Request::get and Request::$attribtues and when to use which?

@xabbuh
Copy link
Member

xabbuh commented Nov 21, 2014

@mpdude
Copy link
Contributor Author

mpdude commented Nov 21, 2014

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.

7 participants