Skip to content

Ease development for error pages #7446

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
perprogramming opened this issue Mar 21, 2013 · 7 comments
Closed

Ease development for error pages #7446

perprogramming opened this issue Mar 21, 2013 · 7 comments

Comments

@perprogramming
Copy link

It is currently quiet hard to test modifications within custom error pages. It involves the following steps:

  1. Make the exception controller use the right template:
    When in development mode the exception controller defaults to use a template called "exception_". In production it searches for "error_". So you either need to switch to production locally or rename your template temporarily. When switching to production locally Twig will start to cache the compiled templates. So you even need to clear the cache after each modification or deactivate caching in your Twig configuration. It is ugly anyway.
  2. Trigger an exception
    To actually see the error page, an exception has to be thrown. This might still be easy for 404 exceptions (http://localhost/app.php/there/is/no/page/here...), but is more difficult for other exception types (e.g. 403, 500).

Suggestion:

  1. The exception controller should offer a way to make him use the "production" templates within development mode. This could be a configuration variable in TwigBundle.
  2. We could offer routes for exception tests in development mode (e.g. /_exceptions-test/403). This routes would start a controller that just throws the specified exception.
    It would be even nicer if calling the test route would implicitly switch to "production" templates without having to reconfigure TwigBundle.

I have already had a look into TwigBundle and could provide a PR if you like the idea.

Or am I overseeing something existing?

@stof
Copy link
Member

stof commented Mar 21, 2013

the first suggestion is a duplicate of #1486

For the second suggestion, I'm against adding routes triggering errors.
Btw, you can test any error status code as easily as 404: throw new \Symfony\Component\HttpKernel\Exception\HttpException(412, 'Testing the 412 error page');

@perprogramming
Copy link
Author

@stof Regarding my motivation for the second suggestion: We have Designers/Frontend-Engineers developing our error pages, that do not know where or how to throw an exception... Might be an organizational problem though...

@aderuwe
Copy link
Contributor

aderuwe commented Mar 21, 2013

Couldn't a bundle be created to provide your second suggestion? Load it only in dev and possibly test env. Create a controller to throw exceptions as described by @stof (/_exception/{statusCode} throws the provided status code exception).

@perprogramming
Copy link
Author

@aderuwe Creating a new bundle only for that might be overkill. Why not in TwigBundle? Of course that test routes / controller would only be available in dev mode...

@mpdude
Copy link
Contributor

mpdude commented Mar 21, 2013

Might be a route contained in Symfony's TwigBundle that you can add to your routing_development.yml (for example) file if you want to test production-like exceptions unter /_exception/{status}/... while in kernel.debug mode.

Whether or not the exception is rendered as error* or exception* could be triggered by the route as well, since the Request is already passed into the Controller. (Probably makes no sense to see the exception* page for an intentionally-thrown exception, though.)

@thewholelifetolearn
Copy link

I find the idea of providing special routes in development and/or test environment good.
I think it should be included in TwigBundle and not through an other bundle. Error pages are basic pages that are included in each application. Every project takes error pages in consideration. They are not optional as it would imply if those routes are implemented through an external bundle.

@mpdude
Copy link
Contributor

mpdude commented Feb 13, 2014

weaverryan added a commit to symfony/symfony-docs that referenced this issue Mar 9, 2014
… need to set kernel.debug=false (mpdude)

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

Discussion
----------

Development of custom error pages is impractical if you need to set kernel.debug=false

Also see
symfony/symfony#7446 and symfony/symfony#1486

Commits
-------

6aa90e0 Use WebfactoryExceptionsBundle instead of webfactory/exceptions-bundle
2fee263 Update error_pages.rst
435019c Point out the difference between error and exception pages.
2194607 Add a pointer to webfactory/exceptions-bundle which helps with development of custom error pages.
@fabpot fabpot closed this as completed Oct 5, 2014
fabpot added a commit that referenced this issue Oct 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#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
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

6 participants