Error: Call to a member function append() on null in Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4::toPSR4()

Created on 28 April 2023, over 1 year ago
Updated 8 July 2024, 6 months ago

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.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇨🇦Canada mandclu

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

Comments & Activities

  • Issue created by @mandclu
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    242 pass
  • @mandclu opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Error: Call to a member function append() on null in Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4::toPSR4() (line 54 of [error]
    /var/www/html/vhost/drupal9/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php) #0
    /var/www/html/vhost/drupal9/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php(34):
    Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4::toPSR4()
    #1 [internal function]: Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4->Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\{closure}()
    #2 /var/www/html/vhost/drupal9/web/modules/contrib/drupalmoduleupgrader/vendor/jcnventura/pharborist/src/NodeCollection.php(669): array_walk()
    #3 /var/www/html/vhost/drupal9/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php(35): Pharborist\NodeCollection->each()
    #4 /var/www/html/vhost/drupal9/web/modules/contrib/drupalmoduleupgrader/drupalmoduleupgrader.drush.inc(352):
    Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4->convert()
    #5 /opt/drush-8.x/vendor/drush/drush/includes/command.inc(422): drush_drupalmoduleupgrader_dmu_upgrade()
    #6 /opt/drush-8.x/vendor/drush/drush/includes/command.inc(231): _drush_invoke_hooks()
    #7 /opt/drush-8.x/vendor/drush/drush/includes/command.inc(199): drush_command()
    #8 /opt/drush-8.x/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch()
    #9 /opt/drush-8.x/vendor/drush/drush/includes/preflight.inc(67): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
    #10 /opt/drush-8.x/vendor/drush/drush/drush.php(12): drush_main()
    #11 {main}.
    Error: Call to a member function append() on null in /var/www/html/vhost/drupal9/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php on line 54 #0 /var/www/html/vhost/drupal9/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php(34): Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4::toPSR4()
    #1 [internal function]: Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4->Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\{closure}()
    #2 /var/www/html/vhost/drupal9/web/modules/contrib/drupalmoduleupgrader/vendor/jcnventura/pharborist/src/NodeCollection.php(669): array_walk()
    #3 /var/www/html/vhost/drupal9/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/PSR4.php(35): Pharborist\NodeCollection->each()
    #4 /var/www/html/vhost/drupal9/web/modules/contrib/drupalmoduleupgrader/drupalmoduleupgrader.drush.inc(352): Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\PSR4->convert()

Production build 0.71.5 2024