Error: Call to a member function hasOption()

Created on 18 October 2022, over 1 year ago
Updated 12 June 2023, about 1 year ago

Problem/Motivation

I get this error when running cron. I'm not entirely sure if this is a new problem, or since I upgraded to 9.4.8.

[error]  Error: Call to a member function hasOption() on null in entity_display_mode_check_route_is_valid() (line 136 of /app/web/modules/contrib/entity_display_mode/entity_display_mode.module) #0 /app/web/modules/contrib/entity_display_mode/entity_display_mode.module(38): entity_display_mode_check_route_is_valid()
#1 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(562): entity_display_mode_entity_view_mode_alter('search_index', Object(Drupal\node\Entity\Node), Array)
#2 /app/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(180): Drupal\Core\Extension\ModuleHandler->alter('entity_view_mod...', 'search_index', Object(Drupal\node\Entity\Node), Array)
#3 /app/web/core/modules/node/src/NodeViewBuilder.php(61): Drupal\Core\Entity\EntityViewBuilder->getBuildDefaults(Object(Drupal\node\Entity\Node), 'search_index')
#4 /app/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(157): Drupal\node\NodeViewBuilder->getBuildDefaults(Object(Drupal\node\Entity\Node), 'search_index')
#5 /app/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(123): Drupal\Core\Entity\EntityViewBuilder->viewMultiple(Array, 'search_index', 'en')
#6 /app/web/modules/contrib/search_api/src/Plugin/search_api/datasource/ContentEntity.php(1010): Drupal\Core\Entity\EntityViewBuilder->view(Object(Drupal\node\Entity\Node), 'search_index', 'en')
#7 /app/web/modules/contrib/search_api/src/Plugin/search_api/processor/RenderedItem.php(288): Drupal\search_api\Plugin\search_api\datasource\ContentEntity->viewItem(Object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter), 'search_index')
#8 /app/web/modules/contrib/search_api/src/Item/Item.php(282): Drupal\search_api\Plugin\search_api\processor\RenderedItem->addFieldValues(Object(Drupal\search_api\Item\Item))
#9 /app/web/modules/contrib/search_api/src/Entity/Index.php(976): Drupal\search_api\Item\Item->getFields()
#10 /app/web/modules/contrib/search_api/src/Entity/Index.php(930): Drupal\search_api\Entity\Index->indexSpecificItems(Array)
#11 /app/web/modules/contrib/search_api/search_api.module(116): Drupal\search_api\Entity\Index->indexItems(50)
#12 /app/web/core/lib/Drupal/Core/Cron.php(249): search_api_cron()
#13 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(405): Drupal\Core\Cron->Drupal\Core\{closure}(Object(Closure), 'search_api')
#14 /app/web/core/lib/Drupal/Core/Cron.php(257): Drupal\Core\Extension\ModuleHandler->invokeAllWith('cron', Object(Closure))
#15 /app/web/core/lib/Drupal/Core/Cron.php(136): Drupal\Core\Cron->invokeCronHandlers()
#16 /app/web/core/lib/Drupal/Core/ProxyClass/Cron.php(75): Drupal\Core\Cron->run()
#17 /app/vendor/drush/drush/src/Drupal/Commands/core/DrupalCommands.php(59): Drupal\Core\ProxyClass\Cron->run()
#18 [internal function]: Drush\Drupal\Commands\core\DrupalCommands->cron(Array)
#19 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#20 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#21 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#22 /app/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(350): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#23 /app/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /app/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /app/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /app/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 /app/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 /app/vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#29 /app/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#30 /app/vendor/drush/drush/drush(4): require('/app/vendor/dru...')
#31 /app/vendor/bin/drush(97): include('/app/vendor/dru...')
#32 {main}.

Steps to reproduce

I believe when you have search API enabled and you use entity_display_mode on a content type that's being indexed during cron, the call to $route->getRouteObject() will be NULL.

I found a similar issue here:
#3104980: layout_builder_system_breadcrumb_alter doesn't check for a null route object β†’

Proposed resolution

It looks like the fix is to just make sure ->getRouteObject isn't null. The official Drupal\Core\Routing\RouteMatchInterface::getRouteObject() also seems to indicate this could return NULL.

Remaining tasks

Testing

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States asherry

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024