paknahad / jsonapi-bundle

the fastest way to generate API based on jsonapi.org using woohoolabs/yin
MIT License
70 stars 25 forks source link

Argument 1 passed to PsrHttpFactory::createRequest() must be an instance of Request, null given #87

Open nelson6e65 opened 2 years ago

nelson6e65 commented 2 years ago

Hi. IDK if put this here or in paknahad/jsonapi-bundle, because this happens when using this extension.

I get this error (when authenticating using NelmioApiDocs or via Postman) when I use a custom Finder or paknahad/jsonapi-querifier-bundle:

[critical] Uncaught Error: Argument 1 passed to Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory::createRequest() must be an instance of Symfony\Component\HttpFoundation\Request, null given, called in ./vendor/paknahad/jsonapi-bundle/src/Factory/JsonApiFactory.php on line 45

When APP_DEBUG is set to true, this break the JSON response with the warning as plain text, so only works with APP_DEBUG=false.

Seems to be related with the requestStack, like an issue in https://github.com/AdactiveSAS/saml2-bridge-bundle/issues/28

https://github.com/paknahad/jsonapi-bundle/blob/98c75e1337f9043aeafcd3dbf032243b7d59abbf/src/Factory/JsonApiFactory.php#L41-L46

https://github.com/AdactiveSAS/saml2-bridge-bundle/blob/a517b096de30416a53d5f7dc3f24a6947e743e2b/src/Entity/HostedEntities.php#L141

Maybe my config is wrong?

My services.yaml config is:

services:
  paknahad_json_api.helper_filter.finder:
    class: Paknahad\JsonApiQuerifierBundle\Finder\Querifier
    public: false
    tags:
      - { name: paknahad.json_api.finder }

Am I missing something?

nelson6e65 commented 2 years ago
error.html ```html Argument 1 passed to Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory::createRequest() must be an instance of Symfony\Component\HttpFoundation\Request, null given, called in /var/www/app/vendor/paknahad/jsonapi-bundle/src/Factory/JsonApiFactory.php on line 44 (500 Internal Server Error)

Symfony Exception

Argument 1 passed to Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory::createRequest() must be an instance of Symfony\Component\HttpFoundation\Request, null given, called in /var/www/app/vendor/paknahad/jsonapi-bundle/src/Factory/JsonApiFactory.php on line 44

Exception

TypeError

  1.     }
  2.     /**
  3.      * {@inheritdoc}
  4.      */
  5.     public function createRequest(Request $symfonyRequest)
  6.     {
  7.         $uri $symfonyRequest->server->get('QUERY_STRING''');
  8.         $uri $symfonyRequest->getSchemeAndHttpHost().$symfonyRequest->getBaseUrl().$symfonyRequest->getPathInfo().('' !== $uri '?'.$uri '');
  9.         $request $this->serverRequestFactory->createServerRequest(
  1.     }
  2.     public function create(): JsonApi
  3.     {
  4.         $jsonApiRequest = new JsonApiRequest(
  5.             $this->psrFactory->createRequest($this->requestStack->getCurrentRequest()),
  6.             $this->exceptionFactory
  7.         );
  8.         return new JsonApi($jsonApiRequest$this->psrFactory->createResponse(new Response()), $this->exceptionFactory$this->serializer);
  9.     }
  1.         include_once \dirname(__DIR__4).'/vendor/woohoolabs/yin/src/JsonApi/Exception/ExceptionFactoryInterface.php';
  2.         include_once \dirname(__DIR__4).'/vendor/woohoolabs/yin/src/JsonApi/Exception/DefaultExceptionFactory.php';
  3.         include_once \dirname(__DIR__4).'/vendor/woohoolabs/yin/src/JsonApi/Serializer/SerializerInterface.php';
  4.         include_once \dirname(__DIR__4).'/vendor/woohoolabs/yin/src/JsonApi/Serializer/JsonSerializer.php';
  5.         return $container->privates['WoohooLabs\\Yin\\JsonApi\\JsonApi'] = (new \Paknahad\JsonApiBundle\Factory\JsonApiFactory(($container->privates['Symfony\\Bridge\\PsrHttpMessage\\Factory\\PsrHttpFactory'] ?? $container->load('getPsrHttpFactoryService')), ($container->services['request_stack'] ?? ($container->services['request_stack'] = new \Symfony\Component\HttpFoundation\RequestStack())), new \WoohooLabs\Yin\JsonApi\Exception\DefaultExceptionFactory(), new \WoohooLabs\Yin\JsonApi\Serializer\JsonSerializer()))->create();
  6.     }
  7. }
  1.     }
  2.     protected function load($file$lazyLoad true)
  3.     {
  4.         if (class_exists($class __NAMESPACE__.'\\'.$filefalse)) {
  5.             return $class::do($this$lazyLoad);
  6.         }
  7.         if ('.' === $file[-4]) {
  8.             $class substr($class0, -4);
  9.         } else {
  1.         include_once \dirname(__DIR__4).'/vendor/paknahad/jsonapi-bundle/src/EventSubscriber/JsonApiErrorHandlerEvent.php';
  2.         include_once \dirname(__DIR__4).'/src/Utils/JsonApi/Events/JsonApiErrorHandlerEvent.php';
  3.         include_once \dirname(__DIR__4).'/vendor/symfony/psr-http-message-bridge/HttpFoundationFactoryInterface.php';
  4.         include_once \dirname(__DIR__4).'/vendor/symfony/psr-http-message-bridge/Factory/HttpFoundationFactory.php';
  5.         return $container->privates['App\\Utils\\JsonApi\\Events\\JsonApiErrorHandlerEvent'] = new \App\Utils\JsonApi\Events\JsonApiErrorHandlerEvent('dev'true, ($container->privates['WoohooLabs\\Yin\\JsonApi\\JsonApi'] ?? $container->load('getJsonApiService')), ($container->privates['sensio_framework_extra.psr7.http_foundation_factory'] ?? ($container->privates['sensio_framework_extra.psr7.http_foundation_factory'] = new \Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory())));
  6.     }
  7. }
  1.     }
  2.     protected function load($file$lazyLoad true)
  3.     {
  4.         if (class_exists($class __NAMESPACE__.'\\'.$filefalse)) {
  5.             return $class::do($this$lazyLoad);
  6.         }
  7.         if ('.' === $file[-4]) {
  8.             $class substr($class0, -4);
  9.         } else {
  1.         }, => 'onKernelResponse'], 0);
  2.         $instance->addListener('kernel.response', [=> function () {
  3.             return ($this->privates['nelmio_cors.cacheable_response_vary_listener'] ?? ($this->privates['nelmio_cors.cacheable_response_vary_listener'] = new \Nelmio\CorsBundle\EventListener\CacheableResponseVaryListener()));
  4.         }, => 'onResponse'], 0);
  5.         $instance->addListener('kernel.exception', [=> function () {
  6.             return ($this->privates['App\\Utils\\JsonApi\\Events\\JsonApiErrorHandlerEvent'] ?? $this->load('getJsonApiErrorHandlerEventService'));
  7.         }, => 'onKernelException'], 0);
  8.         $instance->addListener('kernel.exception', [=> function () {
  9.             return ($this->privates['jsonapi.error.handler.event'] ?? $this->load('getJsonapi_Error_Handler_EventService'));
  10.         }, => 'onKernelException'], 0);
  11.         $instance->addListener('kernel.response', [=> function () {
in /var/www/app/vendor/symfony/event-dispatcher/EventDispatcher.php -> ContainerZrIxhJE\{closure} (line 267)
  1.             foreach ($listeners as &$listener) {
  2.                 $closure = &$this->optimized[$eventName][];
  3.                 if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure && >= \count($listener)) {
  4.                     $closure = static function (...$args) use (&$listener, &$closure) {
  5.                         if ($listener[0] instanceof \Closure) {
  6.                             $listener[0] = $listener[0]();
  7.                             $listener[1] = $listener[1] ?? '__invoke';
  8.                         }
  9.                         ($closure = \Closure::fromCallable($listener))(...$args);
  10.                     };
  11.                 } else {
in /var/www/app/vendor/symfony/event-dispatcher/EventDispatcher.php :: Symfony\Component\EventDispatcher\{closure} (line 230)
  1.         foreach ($listeners as $listener) {
  2.             if ($stoppable && $event->isPropagationStopped()) {
  3.                 break;
  4.             }
  5.             $listener($event$eventName$this);
  6.         }
  7.     }
  8.     /**
  9.      * Sorts the internal list of listeners for the given event by priority.
  1.         } else {
  2.             $listeners $this->getListeners($eventName);
  3.         }
  4.         if ($listeners) {
  5.             $this->callListeners($listeners$eventName$event);
  6.         }
  7.         return $event;
  8.     }
  1.         try {
  2.             $this->beforeDispatch($eventName$event);
  3.             try {
  4.                 $e $this->stopwatch->start($eventName'section');
  5.                 try {
  6.                     $this->dispatcher->dispatch($event$eventName);
  7.                 } finally {
  8.                     if ($e->isStarted()) {
  9.                         $e->stop();
  10.                     }
  11.                 }
  1.      * @throws \Exception
  2.      */
  3.     private function handleThrowable(\Throwable $eRequest $requestint $type): Response
  4.     {
  5.         $event = new ExceptionEvent($this$request$type$e);
  6.         $this->dispatcher->dispatch($eventKernelEvents::EXCEPTION);
  7.         // a listener might have replaced the exception
  8.         $e $event->getThrowable();
  9.         if (!$event->hasResponse()) {
  1.     {
  2.         if (!$request $request ?: $this->requestStack->getMainRequest()) {
  3.             throw $exception;
  4.         }
  5.         $response $this->handleThrowable($exception$requestself::MAIN_REQUEST);
  6.         $response->sendHeaders();
  7.         $response->sendContent();
  8.         $this->terminate($request$response);
  1.                         if ($hasRun) {
  2.                             throw $e;
  3.                         }
  4.                         $hasRun true;
  5.                         $kernel->terminateWithException($e$request);
  6.                     };
  7.                 }
  8.             } elseif ($event instanceof ConsoleEvent && $app $event->getCommand()->getApplication()) {
  9.                 $output $event->getOutput();
  10.                 if ($output instanceof ConsoleOutputInterface) {
in /var/www/app/vendor/symfony/error-handler/ErrorHandler.php :: Symfony\Component\HttpKernel\EventListener\{closure} (line 607)
  1.             $this->exceptionHandler null;
  2.         }
  3.         try {
  4.             if (null !== $exceptionHandler) {
  5.                 return $exceptionHandler($exception);
  6.             }
  7.             $handlerException $handlerException ?: $exception;
  8.         } catch (\Throwable $handlerException) {
  9.         }
  10.         if ($exception === $handlerException && null === $this->exceptionHandler) {
ErrorHandler->handleException(object(TypeError))

Stack Trace

TypeError
TypeError:
Argument 1 passed to Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory::createRequest() must be an instance of Symfony\Component\HttpFoundation\Request, null given, called in /var/www/app/vendor/paknahad/jsonapi-bundle/src/Factory/JsonApiFactory.php on line 44

  at /var/www/app/vendor/symfony/psr-http-message-bridge/Factory/PsrHttpFactory.php:49
  at Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory->createRequest(null)
     (/var/www/app/vendor/paknahad/jsonapi-bundle/src/Factory/JsonApiFactory.php:44)
  at Paknahad\JsonApiBundle\Factory\JsonApiFactory->create()
     (/var/www/app/var/cache/dev/ContainerZrIxhJE/getJsonApiService.php:27)
  at ContainerZrIxhJE\getJsonApiService::do(object(App_KernelDevDebugContainer), true)
     (/var/www/app/var/cache/dev/ContainerZrIxhJE/App_KernelDevDebugContainer.php:477)
  at ContainerZrIxhJE\App_KernelDevDebugContainer->load('getJsonApiService')
     (/var/www/app/var/cache/dev/ContainerZrIxhJE/getJsonApiErrorHandlerEventService.php:25)
  at ContainerZrIxhJE\getJsonApiErrorHandlerEventService::do(object(App_KernelDevDebugContainer), true)
     (/var/www/app/var/cache/dev/ContainerZrIxhJE/App_KernelDevDebugContainer.php:477)
  at ContainerZrIxhJE\App_KernelDevDebugContainer->load('getJsonApiErrorHandlerEventService')
     (/var/www/app/var/cache/dev/ContainerZrIxhJE/App_KernelDevDebugContainer.php:894)
  at ContainerZrIxhJE\App_KernelDevDebugContainer->ContainerZrIxhJE\{closure}()
     (/var/www/app/vendor/symfony/event-dispatcher/EventDispatcher.php:267)
  at Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}(object(ExceptionEvent), 'kernel.exception', object(EventDispatcher))
     (/var/www/app/vendor/symfony/event-dispatcher/EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(Closure), object(Closure), object(Closure), object(Closure), object(Closure), object(Closure)), 'kernel.exception', object(ExceptionEvent))
     (/var/www/app/vendor/symfony/event-dispatcher/EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(ExceptionEvent), 'kernel.exception')
     (/var/www/app/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:154)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(ExceptionEvent), 'kernel.exception')
     (/var/www/app/vendor/symfony/http-kernel/HttpKernel.php:213)
  at Symfony\Component\HttpKernel\HttpKernel->handleThrowable(object(TypeError), object(Request), 1)
     (/var/www/app/vendor/symfony/http-kernel/HttpKernel.php:106)
  at Symfony\Component\HttpKernel\HttpKernel->terminateWithException(object(TypeError), object(Request))
     (/var/www/app/vendor/symfony/http-kernel/EventListener/DebugHandlersListener.php:131)
  at Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::Symfony\Component\HttpKernel\EventListener\{closure}(object(TypeError))
     (/var/www/app/vendor/symfony/error-handler/ErrorHandler.php:607)
  at Symfony\Component\ErrorHandler\ErrorHandler->handleException(object(TypeError))                
```