Skip to content

TwigBundle error controller issue with Symfony 4.4 #34631

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
XWB opened this issue Nov 26, 2019 · 6 comments
Closed

TwigBundle error controller issue with Symfony 4.4 #34631

XWB opened this issue Nov 26, 2019 · 6 comments

Comments

@XWB
Copy link
Contributor

XWB commented Nov 26, 2019

Symfony version(s) affected: 4.4.0

Description
I'm upgrading to Symfony 4.4 and going through the following steps:

  • Deprecated twig.exception_controller configuration option, set it to "null" and use framework.error_controller instead.

First I set twig.exception_controller to null:

twig:
    exception_controller: null

Next I need to set framework.error_controller. The default value is twig.controller.exception::showAction as can be seen in https://github.com/symfony/twig-bundle/blob/4.4/DependencyInjection/Configuration.php#L41

framework:
    error_controller: 'twig.controller.exception::showAction'

This results in the following error:

Argument 2 passed to Symfony\Bundle\TwigBundle\Controller\ExceptionController::showAction() must be an instance of Symfony\Component\Debug\Exception\FlattenException, instance of TypeError given, called in vendor/symfony/http-kernel/HttpKernel.php on line 146

How to reproduce
See above.

@XWB XWB changed the title TwigBundle configuration issue with Symfony 4.4 TwigBundle error controller issue with Symfony 4.4 Nov 26, 2019
@yceruto
Copy link
Member

yceruto commented Nov 26, 2019

This twig.controller.exception::showAction is the default value for twig.exception_controller option, which is being deprecated too.

After migrating to the new framework.error_controller option, this is the new default ErrorController.

You still can typehint the FlattenException, but make sure it comes from ErrorHandler\FlattenException instead.

@yceruto
Copy link
Member

yceruto commented Nov 26, 2019

Btw, if you don't have a custom error controller, you don't need this step:

framework:
    error_controller: 'twig.controller.exception::showAction'

@XWB
Copy link
Contributor Author

XWB commented Nov 26, 2019

@yceruto I don't have a custom error controller, but without twig.controller.exception::showAction the custom _error pages do not work:

twig:
    exception_controller: null
_errors:
    resource: '@TwigBundle/Resources/config/routing/errors.xml'
    prefix: /_error

/_error/404
/_error/500

Results in:

Unable to find the controller for path "/_error/404". The route is wrongly configured.

@yceruto
Copy link
Member

yceruto commented Nov 26, 2019

it should be '@FrameworkBundle/Resources/config/routing/errors.xml' instead

@XWB
Copy link
Contributor Author

XWB commented Nov 26, 2019

Thank you @yceruto, that did the trick.

The change to @FrameworkBundle/Resources/config/routing/errors.xml' is not listed in the upgrade note and https://symfony.com/doc/current/controller/error_pages.html has not been updated either.

image

Hence I got stuck :)

@yceruto
Copy link
Member

yceruto commented Nov 26, 2019

Yep, wip symfony/symfony-docs#12687

@XWB XWB closed this as completed Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants