FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.79k stars 702 forks source link

FatalThrowableError exception when clearing cache on prod #1637

Closed juillerat closed 4 years ago

juillerat commented 7 years ago

Hi, I get this exception when clearing cache on production environment

[Symfony\Component\Debug\Exception\FatalThrowableError]                                                                  
Type error: Argument 1 passed to FOS\RestBundle\Request\ParamReader::getParamsFromAnnotationArray() must be of the type  
 array, null given, called in /var/www/infoflora/symfony/vendor/friendsofsymfony/rest-bundle/Request/ParamReader.php on  
 line 60
Exception trace:
 () at /app/vendor/friendsofsymfony/rest-bundle/Request/ParamReader.php:80
 FOS\RestBundle\Request\ParamReader->getParamsFromAnnotationArray() at /app/vendor/friendsofsymfony/rest-bundle/Request/ParamReader.php:60
 FOS\RestBundle\Request\ParamReader->getParamsFromMethod() at /app/vendor/friendsofsymfony/rest-bundle/Routing/Loader/Reader/RestActionReader.php:472
 FOS\RestBundle\Routing\Loader\Reader\RestActionReader->getMethodArguments() at /app/vendor/friendsofsymfony/rest-bundle/Routing/Loader/Reader/RestActionReader.php:261
 FOS\RestBundle\Routing\Loader\Reader\RestActionReader->read() at /app/vendor/friendsofsymfony/rest-bundle/Routing/Loader/Reader/RestControllerReader.php:102
 FOS\RestBundle\Routing\Loader\Reader\RestControllerReader->read() at /app/vendor/friendsofsymfony/rest-bundle/Routing/Loader/RestRouteLoader.php:74
 FOS\RestBundle\Routing\Loader\RestRouteLoader->load() at /app/vendor/friendsofsymfony/rest-bundle/Routing/Loader/RestRouteProcessor.php:58
 FOS\RestBundle\Routing\Loader\RestRouteProcessor->importResource() at /app/vendor/friendsofsymfony/rest-bundle/Routing/Loader/RestYamlCollectionLoader.php:106
 FOS\RestBundle\Routing\Loader\RestYamlCollectionLoader->load() at /app/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php:103
 Symfony\Component\Config\Loader\FileLoader->import() at /app/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php:145
 Symfony\Component\Routing\Loader\YamlFileLoader->parseImport() at /app/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php:83
 Symfony\Component\Routing\Loader\YamlFileLoader->load() at /app/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/DelegatingLoader.php:45
 Symfony\Component\Config\Loader\DelegatingLoader->load() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php:72
 Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader->load() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php:54
 Symfony\Bundle\FrameworkBundle\Routing\Router->getRouteCollection() at /app/vendor/symfony/symfony/src/Symfony/Component/Routing/Router.php:371
 Symfony\Component\Routing\Router->getMatcherDumperInstance() at /app/vendor/symfony/symfony/src/Symfony/Component/Routing/Router.php:293
 Symfony\Component\Routing\Router->Symfony\Component\Routing\{closure}() at n/a:n/a
 call_user_func() at /app/vendor/symfony/symfony/src/Symfony/Component/Config/ResourceCheckerConfigCacheFactory.php:46
 Symfony\Component\Config\ResourceCheckerConfigCacheFactory->cache() at /app/vendor/symfony/symfony/src/Symfony/Component/Routing/Router.php:306
 Symfony\Component\Routing\Router->getMatcher() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php:70
 Symfony\Bundle\FrameworkBundle\Routing\Router->warmUp() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/RouterCacheWarmer.php:45
 Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer->warmUp() at /app/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:48
 Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:144
 Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:96
 Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:852
 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:191
 Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /app/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:122
 Symfony\Component\Console\Application->run() at /app/bin/console:28

This exception appears with FosRestBundle 1.8, 2.0., 2.1. and Symfony 3.2.1. With Symfony 3.2.0, everything is working as expected. Best regards, Philippe

xabbuh commented 7 years ago

@juillerat Thank you for your report. Would you be able to provide a small reproducable example?

GuilhemN commented 7 years ago

Whatever happens it must be a bug in another library, Reader::getMethodAnnotations() must return an array. It seems that in your case it returns null. Maybe we should look if doctrine/annotations recently introduced a bc break.

lsmith77 commented 7 years ago

due to the close timing of the bug reports .. is the there a relation to https://github.com/FriendsOfSymfony/FOSRestBundle/issues/1636 ?

juillerat commented 7 years ago

The Reader::getMethodAnnotations() returns effectively null because the annotations doesn't get cached for some reasons: $this->fetchFromCache($cacheKey, $class) returns null. This happens when methods have this annotation: @View(statusCode=Response::HTTP_NO_CONTENT) even if Response is declared with use Symfony\Component\HttpFoundation\Response;. It works with @View(statusCode=204)

chosroes commented 7 years ago

@juillerat I don't have this annotation but the error is nevertheless present But I use some like that @QueryParam(map=true, name="sort", requirements=@Sort, allowBlank=false, default={Sort::DEFAULT_FIELD : Sort::DEFAULT_ORDER})

chosroes commented 7 years ago

When I don't use --optimize-autoloader on composer install it's ok, otherwise not.

GuilhemN commented 7 years ago

@chosroes I think you should submit an issue on doctrine/annotations, from what you say, it seems to be caused by constants.

Tobion commented 4 years ago

Closing as there is no activity.