-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add an action to show *error* pages in kernel.debug mode #12096
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
Conversation
@weaverryan Can you have a look at this PR. It would be great if we can accept it today or tomorrow for inclusion in 2.6. Thanks. |
When do you need PRs for symfony/symfony-standard and or -docs at the latest? |
@mpdude before the end of the week (Sunday.) |
{ | ||
try { | ||
throw new \Exception("Something has intentionally gone wrong."); | ||
} catch (\Exception $exception) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this on accident or am I missing the point of this try
-catch
block? Should we just have the return new Response
part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, nevermind, I see what you are doing. Why not just create the Exception
and use it - I don't think we need to actually throw it here:
$exception = new \Exception('This is a generic exception being used to help test your error page');
return new Response(...);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unsure whether this was needed to give the exception for example a "real" stack trace, just in case the error page is to display that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stack trace is created when the exception is created, so you can remove the try/catch block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just did that :-)
@mpdude Thanks for this! First, everything works exactly as advertised and I only spotted one change I can see to make. Second - about your to be discussed: I understand your point about custom exception messages. In this PR, we just create a generic Do we fix this? As you said, adding a Cheers! |
👍 Looks good to me. Can you submit a PR on symfony/symfony-standard? |
Thanks! See symfony/symfony-standard#720. |
Yeah, this is very simple ! Nice contributions ! |
I will need another 24h for a docs PR. Can also write up something for the Symfony blog of you like. |
* | ||
* @return Response | ||
*/ | ||
protected function createResponse(Request $request, FlattenException $exception, $debug, DebugLoggerInterface $logger = null, $currentContent = '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was in the meantime, but I reverted it back to protected.
Reason: The docs mention subclassing this controller in order to pass additional variables to the template. As this part of the code as moved from the showAction to this method, I'd like to keep the possibility to override it.
@stof agree?
@mpdude If you can write the blog post the the Symfony blog as well, that would be wonderful. Thanks. |
The docs (http://symfony.com/doc/current/cookbook/controller/error_pages.html) explicitly mentioned subclassing the controller and overriding the showAction method to pass additional variables to the template. The variables are now defined in createResponse(), so I'd like to keep the possibility to change them. The new testErrorPageAction() method might even work in these cases.
Doc PR at symfony/symfony-docs#4293. |
Here's a suggestion for the blog article: https://gist.github.com/mpdude/ffa505570858e674c62b. |
Thank you @mpdude. |
…de (mpdude) This PR was squashed before being merged into the 2.6-dev branch (closes #12096). Discussion ---------- Add an action to show *error* pages in kernel.debug mode | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #7446, #1486, #11327 | License | MIT | Doc PR | symfony/symfony-docs#4293 See #7446 for the initial reasoning. In short, add to your `routing_development.yml` file the following ```yaml _errors: resource: "@TwigBundle/Resources/config/routing/errors.xml" prefix: /_error ``` Then you can use `http://localhost/app_dev.php/_error/xxx` to preview the HTML *error* page that the default `ExceptionController` (from `TwigBundle`) would pick for the XXX status code. You can also use `http://localhost/app_dev.php/_error/xxx.{some_format}` to show error pages for other formats than HTML, most notably `txt`. Note that the status code will be 500 for all exceptions [that do not implement `HttpExceptionInterface`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Debug/Exception/FlattenException.php#L47). ##### Want to test with a custom exception? ~~Folks might want to display (part of) the exception even on error pages and thus need to work with generic (own) exceptions.~~ ~~They could write an arbitrary controller and throw their exception there. By default, the `ExceptionController` would be used to handle this, only that it would not show *error* pages in `kernel.debug` mode.~~ ~~Thus, a simple public setter to change the `debug` flag after construction could help. Do we want to add that as well?~~ If you want to test error pages with your own exceptions, * create a subclass of `ExceptionController` * set the protected `debug` flag to false * register it as twig.exception_controller in the config * throw your custom exception from any controller. That should give you the error page also in `kernel.debug` mode. ##### To-Do - [x] Update docs - [x] Add route in symfony/symfony-default Commits ------- 66ed177 Add an action to show *error* pages in kernel.debug mode
This PR was merged into the 2.6-dev branch. Discussion ---------- Add route to preview error pages in development See symfony/symfony#12096 for details. I think this is my first contribution to symfony-standard, does that earn me a badge :-)? Commits ------- c7d9f6a Add route to preview error pages in development (see Symfony issue #12096)
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)
See #7446 for the initial reasoning. In short, add to your
routing_development.yml
file the followingThen you can use
http://localhost/app_dev.php/_error/xxx
to preview the HTML error page that the defaultExceptionController
(fromTwigBundle
) would pick for the XXX status code.You can also use
http://localhost/app_dev.php/_error/xxx.{some_format}
to show error pages for other formats than HTML, most notablytxt
.Note that the status code will be 500 for all exceptions that do not implement
HttpExceptionInterface
.Want to test with a custom exception?
Folks might want to display (part of) the exception even on error pages and thus need to work with generic (own) exceptions.They could write an arbitrary controller and throw their exception there. By default, theExceptionController
would be used to handle this, only that it would not show error pages inkernel.debug
mode.Thus, a simple public setter to change thedebug
flag after construction could help. Do we want to add that as well?If you want to test error pages with your own exceptions,
ExceptionController
debug
flag to falseThat should give you the error page also in
kernel.debug
mode.To-Do