When I want to enable exception handlers, I get the following exception :
The service "fos_rest.exception.twig_controller" has a dependency on a non-existent service "templating.engine.twig".
Try adding exception_controller: 'fos_rest.exception.controller:showAction' line to your config
fos_rest:
exception:
enabled: true
exception_controller: 'fos_rest.exception.controller:showAction'
If you do not define exception controller and have TwigBundle enabled fos_rest.exception.twig_controller:showAction will be used`
https://github.com/FriendsOfSymfony/FOSRestBundle/blob/80a41f571250ad4c14f7e36c267eb968575884d8/DependencyInjection/FOSRestExtension.php#L331
@ramoshka I'm seeing this error with the following config:
exception:
enabled: true
exception_controller: 'AppBundle\Port\Rest\RequestValidation\RequestValidationExceptionListener::render'
It's on 3.4 though, should I open a new issue?
I guess both issues have the same cause. So no need for a new issue IMO.
Having the same issue with Symfony 4 and Flex.
Check your bundles registration order. Try to load FOSRestBundle after the TwigBundle:
<?php
// bundles.php
return [
// ...
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
FOS\RestBundle\FOSRestBundle::class => ['all' => true],
];
It relates to the compiler pass:
namespace FOS\RestBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Remove the 'fos_rest.exception.twig_controller' service if twig is enabled.
*
* @internal
*/
final class TwigExceptionPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->has('templating.engine.twig')) {
$container->removeDefinition('fos_rest.exception.twig_controller');
}
}
}
If you really need to usefos_rest.exception.twig_controller, than install symfony/templating
and activate twig engine in the framework configuration:
framework:
templating:
engines: twig
Given that the templating engine is no longer installed and enabled by default, why not modify the TwigExceptionPass to just check for the twig service instead of templating.engine.twig? Seem like it should still work. You lose the old style twig template path support but that should not be a problem.
I have the same problem. Fix is available in #1945. Would be nice if it would get merged.
Most helpful comment
Check your bundles registration order. Try to load
FOSRestBundleafter theTwigBundle:It relates to the compiler pass:
If you really need to use
fos_rest.exception.twig_controller, than installsymfony/templatingand activate
twigengine in the framework configuration: