drupal-console icon indicating copy to clipboard operation
drupal-console copied to clipboard

PHP Fatal Error: Duplicate key "module:download" detected at line 109 vendor/symfony/yaml/Parser.php

Open jameswilson opened this issue 3 years ago • 5 comments

Issue title

Duplicate key "module:download"

[ console ]

Problem/Motivation

Trying to use Drupal Donsole with Drupal 9, results in the following error w/ stack trace:

drupal generate:theme
PHP Fatal error:  Uncaught Symfony\Component\Yaml\Exception\ParseException: Duplicate key "module:download" detected at line 109 (near "  - modo"). in vendor/symfony/yaml/Parser.php:330
Stack trace:
#0 vendor/symfony/yaml/Parser.php(516): Symfony\Component\Yaml\Parser->doParse(Array, 0)
#1 vendor/symfony/yaml/Parser.php(312): Symfony\Component\Yaml\Parser->parseBlock(2, 'cache:rebuild:\n...', 0)
#2 vendor/symfony/yaml/Parser.php(516): Symfony\Component\Yaml\Parser->doParse('aliases:\n  cach...', 0)
#3 vendor/symfony/yaml/Parser.php(312): Symfony\Component\Yaml\Parser->parseBlock(1, 'aliases:\n  cach...', 0)
#4 vendor/symfony/yaml/Parser.php(95): Symfony\Component\Yaml\Parser->doParse('commands:\n  ali...', 0)
#5 /Users/jameswilson/App/Contrib/drupal- in vendor/symfony/yaml/Parser.php on line 330

Fatal error: Uncaught Symfony\Component\Yaml\Exception\ParseException: Duplicate key "module:download" detected at line 109 (near "  - modo"). in vendor/symfony/yaml/Parser.php:330
Stack trace:
#0 vendor/symfony/yaml/Parser.php(516): Symfony\Component\Yaml\Parser->doParse(Array, 0)
#1 vendor/symfony/yaml/Parser.php(312): Symfony\Component\Yaml\Parser->parseBlock(2, 'cache:rebuild:\n...', 0)
#2 vendor/symfony/yaml/Parser.php(516): Symfony\Component\Yaml\Parser->doParse('aliases:\n  cach...', 0)
#3 vendor/symfony/yaml/Parser.php(312): Symfony\Component\Yaml\Parser->parseBlock(1, 'aliases:\n  cach...', 0)
#4 vendor/symfony/yaml/Parser.php(95): Symfony\Component\Yaml\Parser->doParse('commands:\n  ali...', 0)
#5 /Users/jameswilson/App/Contrib/drupal- in vendor/symfony/yaml/Parser.php on line 330

Why fix this?

There are still valuable console commands that should be able to be run on Drupal 9.

How to reproduce

  1. Install Drupal 9 via composer recommended-project: composer create-project drupal/recommended-project my-project (currently, this installs to Drupal version 9.0.7)
  2. Add Drupal Console dependency to composer: cd my-project && composer require drupal/console (currently this adds console version dependency as `^1.9)
  3. Execute any drupal console command, eg vendor/bin/drupal generate:theme

Known workarounds

None.

jameswilson avatar Oct 19 '20 13:10 jameswilson

Seeing this as well.

  • Lando 3.0.21
  • Drupal 9.1
  • Drush 10.3.6
  • Drupal Console 1.9

willtate avatar Dec 09 '20 18:12 willtate

Big Sur php 7.4 D8 and D9 project, happening in all.

Also experiencing this issue with the Conosle global package, outside of a the drupal directory. So appears unrelated to the version of drupal and more related to console and the parser.yml file at line:342:

if ($allowOverwrite || !isset($data[$key])) { $data[$key] = $value; } else { throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine); }

Debugging, the value module:download is already set in the $data array to 'mod' causing the error to be thrown when a new alias is trying to override module:download to 'modo'. The original download command is set in: vendor/drupal/console/src/Command/Module/DownloadCommand.php. But searching the code base I can't find where this additional 'module:download' Command is coming from. The only way around this at moment is to comment out line 345 in vendor/symfony/yaml/Parser.php:

// throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine); Not an ideal fix but makes Drupal Console useable.

roborew avatar Feb 26 '21 14:02 roborew

I'm getting the same issue under Big Sur, Drupal 8 or 9, or just the console.phar outside a project. I also tried the bin in the vendor dir. I can confirm that commenting out line 355 of vendor/symfony/yaml/Parser.php works.

Exactly the same installation works fine under Ubuntu Linux Server 10. However, in both Linux and Big Sur, the console (version 1.9.7) is unbelievably slow. Takes 20 seconds to respond in linux, and over a minute under Big Sur (after patching under Big Sur). Something is seriously wrong.

Fatal error: Uncaught Symfony\Component\Yaml\Exception\ParseException: Duplicate key "module:download" detected at line 56 (near "module:download: modo"). in /Users/fuo/Sites/wwwroot/glyph.dr8.test/vendor/symfony/yaml/Parser.php:355 Stack trace: #0 /Users/fuo/Sites/wwwroot/glyph.dr8.test/vendor/symfony/yaml/Parser.php(531): Symfony\Component\Yaml\Parser->doParse('modo', 0) #1 /Users/fuo/Sites/wwwroot/glyph.dr8.test/vendor/symfony/yaml/Parser.php(327): Symfony\Component\Yaml\Parser->parseBlock(2, 'cache:rebuild: ...', 0) #2 /Users/fuo/Sites/wwwroot/glyph.dr8.test/vendor/symfony/yaml/Parser.php(531): Symfony\Component\Yaml\Parser->doParse('aliases:\n cach...', 0) #3 /Users/fuo/Sites/wwwroot/glyph.dr8.test/vendor/symfony/yaml/Parser.php(327): Symfony\Component\Yaml\Parser->parseBlock(1, 'aliases:\n cach...', 0) #4 /Users/fuo/Sites/wwwroot/glyph.dr8.test/vendor/symfony/yaml/Parser.php(96): Symfony\Component\Yaml\Parser->doParse('commands:\n ali...', 0) #5 /Users/fuo/Sites/wwwroot/glyph.dr8.test/vendor/symfony/yaml/Yaml.php in /Users/fuo/Sites/wwwroot/glyph.dr8.test/vendor/symfony/yaml/Parser.php on line 355

jmuxfeldt avatar Aug 01 '21 07:08 jmuxfeldt

Locate the file [project_directory]/console/aliases.yml* in your environment, open and remove one of the module:downloaddeclaration (I had two of them):

    module:download:
      - md
    ...
    module:download:  # I removed this line
      - modo          # and this one

You're good to go!

* [project_directory]: in my case is the directory which contains composer.json.

jchatard avatar Nov 16 '21 21:11 jchatard

For me this duplicated key was contained in $HOME/.console/aliases.yml, so you might also check this location

awilhelm13 avatar Dec 14 '21 11:12 awilhelm13