hechoendrupal / drupal-console

The Drupal CLI. A tool to generate boilerplate code, interact with and debug Drupal.
http://drupalconsole.com
GNU General Public License v2.0
938 stars 557 forks source link

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

Open jameswilson opened 4 years ago

jameswilson commented 4 years ago

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.

willtate commented 3 years ago

Seeing this as well.

roborew commented 3 years ago

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.

jmuxfeldt commented 3 years ago

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

jchatard commented 3 years ago

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.

awilhelm13 commented 2 years ago

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