Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
mpdude wants to merge6 commits intosymfony:masterfromwebfactory:test-error-pages
Closed

Add an action to show *error* pages in kernel.debug mode#12096

mpdude wants to merge6 commits intosymfony:masterfromwebfactory:test-error-pages

Conversation

@mpdude
Copy link
Contributor

QA
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#7446,#1486,#11327
LicenseMIT
Doc PRsymfony/symfony-docs#4293

See#7446 for the initial reasoning. In short, add to yourrouting_development.yml file the following

_errors:resource:"@TwigBundle/Resources/config/routing/errors.xml"prefix:/_error

Then you can usehttp://localhost/app_dev.php/_error/xxx to preview the HTMLerror page that the defaultExceptionController (fromTwigBundle) would pick for the XXX status code.

You can also usehttp://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 exceptionsthat do not implementHttpExceptionInterface.

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 showerror 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,

  • create a subclass ofExceptionController
  • set the protecteddebug 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 inkernel.debug mode.

To-Do
  • Update docs
  • Add route in symfony/symfony-default

@fabpot
Copy link
Member

@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.

@mpdude
Copy link
ContributorAuthor

When do you need PRs for symfony/symfony-standard and or -docs at the latest?

@fabpot
Copy link
Member

@mpdude before the end of the week (Sunday.)

Copy link
Member

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 thistry-catch block? Should we just have thereturn new Response part?

Copy link
Member

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 theException 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');returnnewResponse(...);

Copy link
ContributorAuthor

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...

Copy link
Member

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.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Just did that :-)

@weaverryan
Copy link
Member

@mpdude Thanks for this!

First, everything works exactly as advertised and I only spotted one change I can see to make.

Second - about yourto be discussed: I understand your point about custom exception messages. In this PR, we just create a generic\Exception with a generic message. So you're right that if someone is doing something in the template with their custom Exception class or message, then they can't really replicate that here.

Do we fix this? As you said, adding asetDebug method toExceptionController (or maybe you call it->forceProductErrorPage()), then you could call this in your controller temporarily to test your custom error message. But that seems hacky enough and enough of an edge case that I'm -1 on it.

Cheers!

@mpdudempdude changed the titleAdd an action to show *error* pages in kernel.debug mode[WIP] Add an action to show *error* pages in kernel.debug modeOct 3, 2014
@mpdudempdude changed the title[WIP] Add an action to show *error* pages in kernel.debug modeAdd an action to show *error* pages in kernel.debug modeOct 3, 2014
@fabpot
Copy link
Member

👍 Looks good to me. Can you submit a PR on symfony/symfony-standard?

@mpdude
Copy link
ContributorAuthor

Thanks! Seesymfony/symfony-standard#720.

@lyrixx
Copy link
Member

Yeah, this is very simple ! Nice contributions !

@mpdude
Copy link
ContributorAuthor

I will need another 24h for a docs PR. Can also write up something for the Symfony blog of you like.

Copy link
Member

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

Copy link
ContributorAuthor

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?

@fabpot
Copy link
Member

@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) explicitlymentioned subclassing the controller and overriding the showAction method to passadditional variables to the template.The variables are now defined in createResponse(), so I'd like to keep the possibilityto change them. The new testErrorPageAction() method might even work in these cases.
@mpdude
Copy link
ContributorAuthor

Doc PR atsymfony/symfony-docs#4293.

@mpdude
Copy link
ContributorAuthor

Here's a suggestion for the blog article:https://gist.github.com/mpdude/ffa505570858e674c62b.

@fabpot
Copy link
Member

Thank you@mpdude.

@fabpotfabpot closed thisOct 5, 2014
fabpot added a commit that referenced this pull requestOct 5, 2014
…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#4293See#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-defaultCommits-------66ed177 Add an action to show *error* pages in kernel.debug mode
fabpot added a commit to symfony/symfony-standard that referenced this pull requestOct 5, 2014
This PR was merged into the 2.6-dev branch.Discussion----------Add route to preview error pages in developmentSeesymfony/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)
@mpdudempdude deleted the test-error-pages branchOctober 6, 2014 11:24
weaverryan added a commit to symfony/symfony-docs that referenced this pull requestOct 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 fromsymfony/symfony#12096 (and hopefully the fix insymfony/symfony#12147).Commits-------d02c7c4 Updates according to GH feedback8e70373 Document error page preview in Symfony ~2.6 (#4293)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@mpdude@fabpot@weaverryan@lyrixx@stof@Tobion

[8]ページ先頭

©2009-2025 Movatter.jp