Fatal error: Uncaught TypeError: Drupal\Core\Extension\ThemeHandler::addTheme()

Created on 3 January 2025, 17 days ago

Problem/Motivation

Follow up from 🐛 Fatal error: Uncaught TypeError: Drupal\Core\Extension\ThemeHandler::addTheme() Active

Fatal error: Uncaught TypeError: Drupal\Core\Extension\ThemeHandler::addTheme(): Argument #1 ($theme) must be of type Drupal\Core\Extension\Extension, null given, called in /home/ide/project/docroot/core/lib/Drupal/Core/Extension/ThemeHandler.php on line 74 and defined in /home/ide/project/docroot/core/lib/Drupal/Core/Extension/ThemeHandler.php:84
Stack trace:
#0 /home/ide/project/docroot/core/lib/Drupal/Core/Extension/ThemeHandler.php(74): Drupal\Core\Extension\ThemeHandler->addTheme()
#1 /home/ide/project/docroot/core/lib/Drupal/Core/Template/Loader/FilesystemLoader.php(46): Drupal\Core\Extension\ThemeHandler->listInfo()
#2 /home/ide/project/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(261): Drupal\Core\Template\Loader\FilesystemLoader->__construct()
#3 /home/ide/project/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(179): Drupal\Component\DependencyInjection\Container->createService()
#4 /home/ide/project/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(438): Drupal\Component\DependencyInjection\Container->get()
#5 /home/ide/project/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(275): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters()
#6 /home/ide/project/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(179): Drupal\Component\DependencyInjection\Container->createService()
#7 /home/ide/project/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(438): Drupal\Component\DependencyInjection\Container->get()
#8 /home/ide/project/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(239): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters()
#9 /home/ide/project/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(179): Drupal\Component\DependencyInjection\Container->createService()
#10 /home/ide/project/docroot/core/lib/Drupal.php(197): Drupal\Component\DependencyInjection\Container->get()
#11 /home/ide/project/docroot/core/includes/common.inc(457): Drupal::service()
#12 /home/ide/project/docroot/core/includes/utility.inc(41): drupal_flush_all_caches()
#13 /home/ide/project/vendor/drush/drush/src/Commands/core/CacheRebuildCommands.php(60): drupal_rebuild()
#14 [internal function]: Drush\Commands\core\CacheRebuildCommands->rebuild()
#15 /home/ide/project/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array()
#16 /home/ide/project/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
#17 /home/ide/project/vendor/consolidation/annotated-command/src/CommandProcessor.php(175): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
#18 /home/ide/project/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(387): Consolidation\AnnotatedCommand\CommandProcessor->process()
#19 /home/ide/project/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
#20 /home/ide/project/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run()
#21 /home/ide/project/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
#22 /home/ide/project/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
#23 /home/ide/project/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run()
#24 /home/ide/project/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun()
#25 /home/ide/project/vendor/drush/drush/drush.php(140): Drush\Runtime\Runtime->run()
#26 /home/ide/project/vendor/bin/drush.php(119): include('...')
#27 {main}
thrown in /home/ide/project/docroot/core/lib/Drupal/Core/Extension/ThemeHandler.php on line 84

Steps to reproduce

On a local project I experienced this.
1. On main branch make sure everything is up to date
2. switch to a new feature branch where I'm developing a new theme
3. Install theme.
4. Switch back to main
5. Drush is now stuck in a fatal error. Even switching back to feature branch doesn't help

Proposed resolution

TBD

Remaining tasks

Determine best approach

User interface changes

N/A

Introduced terminology

N/A

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

theme system

Created by

🇺🇸United States smustgrave

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

Comments & Activities

  • Issue created by @smustgrave
  • 🇬🇧United Kingdom catch

    Per the other issue, we need clear steps to reproduce here.

  • 🇮🇳India mdsohaib4242

    This error occurs when Drupal is unable to correctly load a theme extension due to a missing or misconfigured theme. It seems that when you switch between branches, the system might be losing track of the theme information, causing the addTheme() method to receive a null value instead of a valid theme object.

    Since Drush is stuck try to delete the cache tables directly from the database

    DELETE FROM cache;
    DELETE FROM cache_config;
    DELETE FROM cache_data;
    

    If the theme was added via the drupal_themes table, ensure that the theme is still registered in the system after switching branches. You can manually add the theme or clear its configuration from the database or rebuild the theme registry manually.

    drush config:import
    
  • 🇳🇿New Zealand quietone

    A few additions to the issue summary and this should have a title update before a commit. The title is current the same as the originating issue.

Production build 0.71.5 2024