Skip to content

Added new ErrorController + Preview and enabling there the error renderer mechanism #33271

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

Merged
merged 1 commit into from
Sep 5, 2019

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented Aug 21, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes (deps=high failure is normal)
Fixed tickets -
License MIT
Doc PR TODO

After deprecating the ExceptionController in TwigBundle (refs #31398) the twig.exception_controller config key becomes useless as feature provided by TwigBundle, while the preview controller is taking more relevance for the error renderer mechanish.

Proposal

  • Deprecate the twig.exception_controller config key in favor of framework.error_controller with default ErrorController that activates the error renderer mechanism through the current ExceptionListener, meaning also that DebugHandlersListener::onKernelException method becomes useless too.
  • Deprecate the PreviewErrorController from TwigBundle in favor of similar in FrameworkBundle.

So you no longer need to install TwigBundle to create a custom error controller or check the preview output of an error renderer (included TwigHtmlErrorRenderer).

Btw this would fix #31398 (comment), removing here workaround in SecurityBundle.

TODO:

  • Update CHANGELOG & UPGRADE files
  • Add tests

WDYT?

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

LGTM

@yceruto yceruto changed the title Add ErrorController and PreviewErrorController to FrameworkBundle Added new ErrorController + Preview and enabling there the error renderer mechanism Aug 21, 2019
@yceruto yceruto force-pushed the error_controller branch 2 times, most recently from e64481f to 9bc74f9 Compare August 21, 2019 17:32
@yceruto
Copy link
Member Author

yceruto commented Aug 22, 2019

I'm introducing here a default exception controller that will use the error rendering mechanism. If you've a completely different error rendering system you'll can to replace the default controller configuring it on framework.error_controller and done.

That possibility is available with TwigBundle installed (deprecated here), now it'll be possible with FrameworkBundle only.

@yceruto
Copy link
Member Author

yceruto commented Aug 24, 2019

Update

As there are two exception listeners when FrameworkBundle and TwigBundle are enabled, I've removed one conditionally: the twig.exception_listener service unless the option twig.exception_listener.controller contains a custom exception controller configured, in that case, I remove the exception_listener instead.

This will be the migration path:

twig:
-    exception_controller: 'App\Controller\ExceptionController'
+    exception_controller: null

framework:
+    error_controller: 'App\Controller\ExceptionController'

@yceruto yceruto force-pushed the error_controller branch 2 times, most recently from 1449e0f to 2841e59 Compare August 24, 2019 12:46
@yceruto
Copy link
Member Author

yceruto commented Aug 24, 2019

Btw, with this new implementation we should revert symfony/recipes#640. not after 5a12b6d

@@ -27,13 +29,18 @@ public function process(ContainerBuilder $container)
return;
}

// register the exception controller only if Twig is enabled and required dependencies do exist
if (!class_exists('Symfony\Component\ErrorRenderer\Exception\FlattenException') || !interface_exists('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
Copy link
Member Author

@yceruto yceruto Aug 24, 2019

Choose a reason for hiding this comment

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

I've removed all interface_exists() check here becase both interfaces are currently installed as hard deps.

@yceruto
Copy link
Member Author

yceruto commented Aug 24, 2019

This is ready for review!

@yceruto yceruto force-pushed the error_controller branch 5 times, most recently from 83755cb to 7cce955 Compare September 2, 2019 21:02
@fabpot
Copy link
Member

fabpot commented Sep 5, 2019

Thank you @yceruto.

fabpot added a commit that referenced this pull request Sep 5, 2019
… the error renderer mechanism (yceruto)

This PR was merged into the 4.4 branch.

Discussion
----------

Added new ErrorController + Preview and enabling there the error renderer mechanism

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes (deps=high failure is normal)
| Fixed tickets | -
| License       | MIT
| Doc PR        | TODO

After deprecating the `ExceptionController` in TwigBundle (refs #31398) the `twig.exception_controller` config key becomes useless as feature provided by TwigBundle, while the preview controller is taking more relevance for the error renderer mechanish.

**Proposal**
 * Deprecate the `twig.exception_controller` config key in favor of `framework.error_controller` with default `ErrorController` that activates the error renderer mechanism through the current `ExceptionListener`, meaning also that `DebugHandlersListener::onKernelException` method becomes useless too.
 * Deprecate the `PreviewErrorController` from TwigBundle in favor of similar in FrameworkBundle.

So you no longer need to install TwigBundle to create a custom error controller or check the preview output of an error renderer (included `TwigHtmlErrorRenderer`).

Btw this would fix #31398 (comment), removing here workaround in SecurityBundle.

TODO:
- [x] Update CHANGELOG & UPGRADE files
- [x] Add tests

WDYT?

Commits
-------

b79532a Add ErrorController to preview and render errors
@fabpot fabpot merged commit b79532a into symfony:4.4 Sep 5, 2019
@yceruto yceruto deleted the error_controller branch September 5, 2019 12:06
@@ -27,13 +29,18 @@ public function process(ContainerBuilder $container)
return;
}

// register the exception controller only if Twig is enabled and required dependencies do exist
if (!class_exists('Symfony\Component\ErrorRenderer\Exception\FlattenException') || !interface_exists('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
// to be removed in 5.0
Copy link
Member

Choose a reason for hiding this comment

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

@yceruto can you please send a PR on master to cleanup this?

Copy link
Member Author

Choose a reason for hiding this comment

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

See #33476

nicolas-grekas added a commit that referenced this pull request Sep 5, 2019
This PR was merged into the 5.0-dev branch.

Discussion
----------

[TwigBundle] Remove legacy code

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | TODO

See #33271

Commits
-------

abb3258 Remove legacy code
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
This was referenced Nov 12, 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.

5 participants