Symfony Router fatal error
Problem/Motivation
There are certain scenarios in which the following error is produced after clearing cache using drush:
PHP Fatal error: Uncaught TypeError: Argument 2 passed to Symfony\Component\Routing\RouteCollection::add() must be an instance of Symfony\Component\Routing\Route, bool given, called in /app/web/core/lib/Drupal/Core/Routing/RouteProvider.php on line 380 and defined in /app/vendor/symfony/routing/RouteCollection.php:76
Stack trace:
#0 /app/web/core/lib/Drupal/Core/Routing/RouteProvider.php(380): Symfony\Component\Routing\RouteCollection->add('entity.comment....', false)
#1 /app/web/core/lib/Drupal/Core/Routing/RouteProvider.php(332): Drupal\Core\Routing\RouteProvider->getRoutesByPath('/comment/%/edit')
#2 /app/web/modules/contrib/devel/src/Routing/RouteSubscriber.php(177): Drupal\Core\Routing\RouteProvider->getRoutesByPattern('/comment/{comme...')
#3 /app/web/modules/contrib/devel/src/Routing/RouteSubscriber.php(87): Drupal\devel\Routing\RouteSubscriber->getRouteParameters(Object(Drupal\Core\Entity\ContentEntityType), 'edit-form')
#4 /app/web/modules/contrib/devel/src/Routing/RouteSubscriber.php(53): Drupal\devel\Routing\RouteS in /app/vendor/symfony/routing/RouteCollection.php on line 76
If you look at the numerals #2, #3, #4 in the Stack trace, the Devel Route Subscriber is involved. There is a forum topic in the Drupal community about this.
The most generic facts that lead to the occurrence of this issue are:
- The Devel module is enabled
- Clear cache using
drush cr
In my case, my local environment runs using Lando. When the environment is updated using lando pull and, after that, I clear cache, the issue occurs.
Others developers have informed about the occurrence of the issue after upgrading modules via Composer.
Identified workaround:
- Uninstall the Devel module (
drush pmu devel) - Clear cache (
drush cr) - Install the Devel module again (
lando drush en devel)
Related links
https://www.drupal.org/forum/support/post-installation/2020-07-01/drupal-9-after-deployment-and-clearing-cache-site-went https://drupal.stackexchange.com/questions/313173/symfony-routing-error