Fatal error with Drush 13 due to MarkdownCommands replacing logger

Created on 25 October 2024, 3 months ago

Problem/Motivation

Basically, MarkdownCommands causes this fatal error with Drush 13:

ambientimpact:~/.../Omnipedia/Web$ ddev drush status
AssertionError: Instead of using replacing Drush's logger, use $this->add() on DrushLoggerManager to add a custom logger. See https://github.com/drush-ops/drush/pull/5022 in /var/www/html/vendor/drush/drush/src/Commands/DrushCommands.php on line 76 #0 /var/www/html/vendor/drush/drush/src/Commands/DrushCommands.php(76): assert()
#1 /var/www/html/vendor/drush/drush/src/Runtime/ServiceManager.php(480): Drush\Commands\DrushCommands->logger()
#2 /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php(282): Drush\Runtime\ServiceManager->inflect()
#3 /var/www/html/vendor/drush/drush/src/Boot/DrupalBoot8.php(218): Drush\Boot\DrupalBoot8->addDrupalModuleDrushCommands()
#4 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(211): Drush\Boot\DrupalBoot8->bootstrapDrupalFull()
#5 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(397): Drush\Boot\BootstrapManager->doBootstrap()
#6 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(332): Drush\Boot\BootstrapManager->bootstrapMax()
#7 /var/www/html/vendor/drush/drush/src/Boot/BootstrapManager.php(304): Drush\Boot\BootstrapManager->bootstrapToPhaseIndex()
#8 /var/www/html/vendor/drush/drush/src/Boot/BootstrapHook.php(36): Drush\Boot\BootstrapManager->bootstrapToPhase()
#9 /var/www/html/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php(44): Drush\Boot\BootstrapHook->initialize()
#10 /var/www/html/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php(36): Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->doInitializeHook()
#11 /var/www/html/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php(29): Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->callInitializeHook()
#12 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(145): Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->initialize()
#13 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(376): Consolidation\AnnotatedCommand\CommandProcessor->initializeHook()
#14 /var/www/html/vendor/symfony/console/Command/Command.php(292): Consolidation\AnnotatedCommand\AnnotatedCommand->initialize()
#15 /var/www/html/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run()
#16 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
#17 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
#18 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run()
#19 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun()
#20 /var/www/html/vendor/drush/drush/drush.php(140): Drush\Runtime\Runtime->run()
#21 /var/www/html/vendor/bin/drush.php(119): include('...')
#22 {main}
AssertionError: Instead of using replacing Drush's logger, use $this->add() on DrushLoggerManager to add a custom logger. See https://github.com/drush-ops/drush/pull/5022 in assert() (line 76 of /var/www/html/vendor/drush/drush/src/Commands/DrushCommands.php).
 [warning] Drush command terminated abnormally.
Failed to run drush status: exit status 1

Steps to reproduce

Run drush status or any other Drush command; get above error.

Proposed resolution

It took a while to locate exactly what command was triggering the error until I found that MarkdownCommands does indeed override the logger in its constructor: $this->logger = $logger; - given that the entire class was apparently deprecated in 8.x-2.0 and was intended to be removed in 3.0.0, the easiest thing would be to remove it, unless it breaks anything. If it must be kept for now, we should wrap the assignment in a check for the logger() existing on $this and not assign it if it's present:

// Don't replace Drush's logger because it'll cause a fatal error on Drush
// 13 and newer.
//
// @see https://github.com/drush-ops/drush/pull/5022
if (!method_exists($this, 'logger')) {
  $this->logger = $logger;
}

Remaining tasks

Do the thing.

User interface changes

None.

API changes

Drush command removed.

Data model changes

None?

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇨🇦Canada ambient.impact Toronto

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024