Symfony Exception

TypeError

HTTP 500 Internal Server Error

App\Model\Library::getBookBySlug(): Return value must be of type App\Model\Book, null returned

Exception

TypeError

  1.             if ($book->slug == $slug) {
  2.                 $chosen $book;
  3.                 break;
  4.             }
  5.         }
  6.         return $chosen;
  7.     }
  8.     /**
  9.      * Gives an array of book objects which match a given category
  10.      *
Library->getBookBySlug() in src/Model/Library.php (line 268)
  1.      *
  2.      * @return array
  3.      */
  4.     public function getObjectsByIdentifier($identifier): array {
  5.         $parts self::parseIdentifier($identifier);
  6.         $book $this->getBookBySlug($parts['bookSlug']);
  7.         $language $book->getLanguageByCode($parts['languageCode']);
  8.         $version $language->getVersionByDescriptor($parts['versionDescriptor']);
  9.         return [
  10.             'book' => $book,
  11.             'language' => $language,
Library->getObjectsByIdentifier() in src/Utils/Redirecter.php (line 56)
  1.      * @param string $requestUri
  2.      *
  3.      * @return null|string
  4.      */
  5.     private function lookupVersionRedirect($requestUri): ?string {
  6.         $objects $this->library->getObjectsByIdentifier($requestUri);
  7.         $requestParts Library::parseIdentifier($requestUri);
  8.         /* @var \App\Model\Version $version */
  9.         $version $objects['version'];
  10.         if (!$version) {
  11.             return null;
Redirecter->lookupVersionRedirect() in src/Utils/Redirecter.php (line 43)
  1.     public function lookupRedirect($requestUri): ?string {
  2.         // Give up right away if the request contains two dots (for security)
  3.         if (strstr($requestUri'..')) {
  4.             return null;
  5.         }
  6.         return $this->lookupVersionRedirect($requestUri) ?? $this->lookupPageRedirect($requestUri);
  7.     }
  8.     /**
  9.      * Try to find a redirect for the page by looking to see if the version
  10.      * supplied in the request is actually one of the redirects for the versions
Redirecter->lookupRedirect() in src/EventSubscriber/ExceptionSubscriber.php (line 26)
  1.     public function onExceptionEvent(ExceptionEvent $event): void {
  2.         $exception $event->getThrowable();
  3.         if ($exception instanceof NotFoundHttpException) {
  4.             $requestUri $event->getRequest()->getRequestUri();
  5.             $redirect $this->redirecter->lookupRedirect($requestUri);
  6.             if ($redirect) {
  7.                 $response = new RedirectResponse($redirect);
  8.                 $event->setResponse($response);
  9.             } else {
  10.                 throw new NotFoundHttpException(
  1.         $this->called true;
  2.         $this->priority $dispatcher->getListenerPriority($eventName$this->listener);
  3.         $e $this->stopwatch->start($this->name'event_listener');
  4.         ($this->optimizedListener ?? $this->listener)($event$eventName$dispatcher);
  5.         if ($e->isStarted()) {
  6.             $e->stop();
  7.         }
  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()) {
in vendor/symfony/http-kernel/HttpKernel.php -> handleThrowable (line 85)
  1.                 $this->finishRequest($request$type);
  2.                 throw $e;
  3.             }
  4.             return $this->handleThrowable($e$request$type);
  5.         }
  6.     }
  7.     /**
  8.      * {@inheritdoc}
  1.         $this->boot();
  2.         ++$this->requestStackSize;
  3.         $this->resetServices true;
  4.         try {
  5.             return $this->getHttpKernel()->handle($request$type$catch);
  6.         } finally {
  7.             --$this->requestStackSize;
  8.         }
  9.     }
  1.         $this->request $request;
  2.     }
  3.     public function run(): int
  4.     {
  5.         $response $this->kernel->handle($this->request);
  6.         $response->send();
  7.         if ($this->kernel instanceof TerminableInterface) {
  8.             $this->kernel->terminate($this->request$response);
  9.         }
in vendor/autoload_runtime.php -> run (line 29)
  1. $app $app(...$args);
  2. exit(
  3.     $runtime
  4.         ->getRunner($app)
  5.         ->run()
  6. );
require_once('/var/www/civicrm-docs/vendor/autoload_runtime.php') in public/index.php (line 5)
  1. <?php
  2. use App\Kernel;
  3. require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
  4. return function (array $context) {
  5.     return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
  6. };

Logs

No log messages

Stack Trace

TypeError
TypeError:
App\Model\Library::getBookBySlug(): Return value must be of type App\Model\Book, null returned

  at src/Model/Library.php:101
  at App\Model\Library->getBookBySlug()
     (src/Model/Library.php:268)
  at App\Model\Library->getObjectsByIdentifier()
     (src/Utils/Redirecter.php:56)
  at App\Utils\Redirecter->lookupVersionRedirect()
     (src/Utils/Redirecter.php:43)
  at App\Utils\Redirecter->lookupRedirect()
     (src/EventSubscriber/ExceptionSubscriber.php:26)
  at App\EventSubscriber\ExceptionSubscriber->onExceptionEvent()
     (vendor/symfony/event-dispatcher/Debug/WrappedListener.php:111)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke()
     (vendor/symfony/event-dispatcher/EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
     (vendor/symfony/event-dispatcher/EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
     (vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:152)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch()
     (vendor/symfony/http-kernel/HttpKernel.php:213)
  at Symfony\Component\HttpKernel\HttpKernel->handleThrowable()
     (vendor/symfony/http-kernel/HttpKernel.php:85)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (vendor/symfony/http-kernel/Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:29)
  at require_once('/var/www/civicrm-docs/vendor/autoload_runtime.php')
     (public/index.php:5)