Skip to content
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

[ErrorHandler] merge and remove the ErrorRenderer component #34312

Merged
merged 2 commits into from Nov 12, 2019

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 10, 2019

Q A
Branch? 4.4
Bug fix? yes
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR -

This PR supersedes #34288.

Here is what it does:

  • Merge the ErrorRenderer component into ErrorHandler
  • Add ErrorRendererInterface::render(\Throwable $e): FlattenException and refactor error renderers around it.
  • Add FlattenException::setAsString() to make the previous possible.
  • Add CliErrorRenderer to render error on the CLI too. This means VarDumper is now a required dependency of ErrorHandler. This paves the way to use it also for rendering HTML - the logic there is much more advanced than what HtmlErrorRenderer provides and ever should provide.
  • Make BufferingLogger map its collected logs to error_log() if they are not emptied before.
  • Remove some classes that are not needed anymore (ErrorRenderer, ErrorRendererPass, HtmlErrorRendererInterface)
  • Simplified the logic in Debug::enable() - nobody uses its arguments
  • Fix a few issues found meanwhile.

With these changes, the component can be used standalone. One is now able to require only it, register it either with either ErrorHandler::register() or Debug::enable() and profit.

/*
* This Request mimics the parameters set by
* \Symfony\Component\HttpKernel\EventListener\ErrorListener::duplicateRequest, with
* the additional "showException" flag.
*/
$subRequest = $request->duplicate(null, null, [
'_controller' => $this->controller,
'exception' => $exception,
'exception' => new HttpException($code, 'This is a sample exception.'),
'logger' => null,
'showException' => false,
Copy link
Member

@yceruto yceruto Nov 10, 2019

Choose a reason for hiding this comment

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

We are missing this attribute to show the non-debug version of the response (useful to test custom Twig-based HTML error pages) on e.g. /__error/404.html.

Copy link
Member

@yceruto yceruto Nov 10, 2019

Choose a reason for hiding this comment

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

However, I'm not sure it's useful for non-HTML formats.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll let you follow up on this topic after merge if you don't mind.

Copy link
Member

Choose a reason for hiding this comment

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

Done in #34331

UPGRADE-5.0.md Outdated Show resolved Hide resolved
UPGRADE-4.4.md Outdated Show resolved Hide resolved
UPGRADE-4.4.md Outdated Show resolved Hide resolved
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER_ARGUMENTS => 'onControllerArguments',
Copy link
Member

@yceruto yceruto Nov 11, 2019

Choose a reason for hiding this comment

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

It would be much better if we could add this listener only when necessary, i.e. within the onKernelException method.

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered doing this but decided not: mutating the event-dispatcher at runtime is something we'd better avoid all the time. Also, this could introduce subtle order-dependent behaviors.
I think the check is specific enough for having it always enabled, with better unconditional behavior.

Copy link
Member

@yceruto yceruto left a comment

Choose a reason for hiding this comment

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

It looks good to me as far as I've tried. However, we need another iteration to restore the preview mechanism.

Thank you Nicolas for taking over and improving it.

@fabpot
Copy link
Member

fabpot commented Nov 12, 2019

Thank you @nicolas-grekas.

fabpot added a commit that referenced this pull request Nov 12, 2019
…onent (nicolas-grekas, yceruto)

This PR was merged into the 4.4 branch.

Discussion
----------

[ErrorHandler] merge and remove the ErrorRenderer component

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

This PR supersedes #34288.

Here is what it does:
- Merge the `ErrorRenderer` component into `ErrorHandler`
- Add `ErrorRendererInterface::render(\Throwable $e): FlattenException` and refactor error renderers around it.
- Add `FlattenException::setAsString()` to make the previous possible.
- Add `CliErrorRenderer` to render error on the CLI too. This means `VarDumper` is now a required dependency of `ErrorHandler`. This paves the way to use it also for rendering HTML - the logic there is much more advanced than what `HtmlErrorRenderer` provides and ever should provide.
- Make `BufferingLogger` map its collected logs to `error_log()` if they are not emptied before.
- Remove some classes that are not needed anymore (`ErrorRenderer`, `ErrorRendererPass`, `HtmlErrorRendererInterface`)
- Simplified the logic in `Debug::enable()` - nobody uses its arguments
- Fix a few issues found meanwhile.

With these changes, the component can be used standalone. One is now able to require only it, register it either with either `ErrorHandler::register()` or `Debug::enable()` and profit.

Commits
-------

d1bf1ca [ErrorHandler] help finish the PR
6c9157b [ErrorHandler] merge and remove the ErrorRenderer component
@fabpot fabpot merged commit d1bf1ca into symfony:4.4 Nov 12, 2019
@nicolas-grekas nicolas-grekas deleted the eh-vd branch November 12, 2019 11:46
nicolas-grekas added a commit that referenced this pull request Nov 12, 2019
This PR was merged into the 4.4 branch.

Discussion
----------

[TwigBundle] Restore the preview mechanism

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

follow up #34312

Commits
-------

d3f1121 [TwigBundle] Restore the preview mechanism
This was referenced Nov 12, 2019
@fancyweb fancyweb mentioned this pull request Dec 11, 2019
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.

None yet

6 participants