Problem/Motivation
When trying to run drush dmu-upgrade
I encountered this fatal error:
[error] Error: Call to a member function append() on null in Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4::toPSR4() (line 54 of /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php) #0 /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php(34): Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4::toPSR4(Object(Drupal\drupalmoduleupgrader\Target), Object(Pharborist\Objects\ClassNode))
#1 [internal function]: Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4->Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\{closure}(Object(Pharborist\Objects\ClassNode), 0)
#2 /var/www/html/vendor/jcnventura/pharborist/src/NodeCollection.php(669): array_walk(Array, Object(Closure))
#3 /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php(35): Pharborist\NodeCollection->each(Object(Closure))
#4 /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Commands/DrupalmoduleupgraderCommands.php(188): Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4->convert(Object(Drupal\drupalmoduleupgrader\Target))
#5 [internal function]: Drupal\drupalmoduleupgrader\Commands\DrupalmoduleupgraderCommands->upgrade('partial_date', Array)
#6 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#7 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#8 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#9 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(390): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 /var/www/html/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/html/vendor/symfony/console/Application.php(1039): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/html/vendor/symfony/console/Application.php(275): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/html/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(124): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(51): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/html/vendor/drush/drush/drush.php(77): Drush\Runtime\Runtime->run(Array)
#17 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
#18 /var/www/html/vendor/bin/drush(120): include('/var/www/html/v...')
#19 {main}.
Error: Call to a member function append() on null in /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php on line 54 #0 /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php(34): Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4::toPSR4(Object(Drupal\drupalmoduleupgrader\Target), Object(Pharborist\Objects\ClassNode))
#1 [internal function]: Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4->Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\{closure}(Object(Pharborist\Objects\ClassNode), 0)
#2 /var/www/html/vendor/jcnventura/pharborist/src/NodeCollection.php(669): array_walk(Array, Object(Closure))
#3 /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php(35): Pharborist\NodeCollection->each(Object(Closure))
#4 /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Commands/DrupalmoduleupgraderCommands.php(188): Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4->convert(Object(Drupal\drupalmoduleupgrader\Target))
#5 [internal function]: Drupal\drupalmoduleupgrader\Commands\DrupalmoduleupgraderCommands->upgrade('partial_date', Array)
#6 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#7 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#8 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#9 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(390): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 /var/www/html/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/html/vendor/symfony/console/Application.php(1039): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/html/vendor/symfony/console/Application.php(275): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/html/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(124): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(51): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/html/vendor/drush/drush/drush.php(77): Drush\Runtime\Runtime->run(Array)
#17 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
#18 /var/www/html/vendor/bin/drush(120): include('/var/www/html/v...')
#19 {main}
Error: Call to a member function append() on null in Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4::toPSR4() (line 54 of /var/www/html/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php).
[warning] Drush command terminated abnormally.
Failed to run drush dmu-upgrade partial_date: exit status 1
Steps to reproduce
Download and attempt to upgrade the partial_date module.
Proposed resolution
Add code to check that the returned namespace is not null before attempting to use the append method. This would be easier in PHP 8 using the null safe operator, but for backwards compatibility use the longer way to achieve this.