magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

Clarify error message on CLI tool failure #2300

Closed dmitrii-fediuk closed 8 years ago

dmitrii-fediuk commented 8 years ago

If an extension has no etc/module.xml file then bin/magento fails with a cryptic message «There are no commands defined». I propose to show a more clear message instead.

davidalger commented 8 years ago

@dfediuk Please provide clearer details with steps to reproduce the noted error message. The below is what I get when I remove a module's etc/module.xml file and then run bin/magento. You can see that it plainly states what the problem is. This is running agains 2.0.0-rc:

dalger:08:17 PM:/sites/m2dev.dev (develop) $ git reset --hard
HEAD is now at 22629ab MAGETWO-45012: Magento 2.0.0-rc Publication
dalger:08:17 PM:/sites/m2dev.dev (develop) $ bin/magento | tail -n6
 setup:static-content:deploy               Deploys static view files
 setup:store-config:set                    Installs the store configuration
 setup:uninstall                           Uninstalls the Magento application
 setup:upgrade                             Upgrades the Magento application, DB data, and schema
theme
 theme:uninstall                           Uninstalls theme
dalger:08:17 PM:/sites/m2dev.dev (develop) $ rm app/code/Magento/Rule/etc/module.xml 
dalger:08:17 PM:/sites/m2dev.dev (develop *) $ rm -rf var/{cache,di,generation,page_cache}/
dalger:08:17 PM:/sites/m2dev.dev (develop *) $ bin/magento
Magento CLI version 2.0.0-rc

Usage:
 command [options] [arguments]

Options:
 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question

Available commands:
 help   Displays help for a command
 list   Lists commands
We're sorry, an error occurred. Try clearing the cache and code generation directories. By default, they are: var/cache, var/di, var/generation, and var/page_cache.

  [Zend\ServiceManager\Exception\ServiceNotCreatedException]                                                                                              
  An abstract factory could not create an instance of magentosetupconsolecommandconfigsetcommand(alias: Magento\Setup\Console\Command\ConfigSetCommand).  

  [Zend\ServiceManager\Exception\ServiceNotCreatedException]                                                     
  An exception was raised while creating "Magento\Setup\Console\Command\ConfigSetCommand"; no instance returned  

  [Magento\Framework\Exception\FileSystemException]                                                                                                                              
  Cannot read contents from file "/Volumes/Server/sites/m2dev.dev/app/code/Magento/Rule/etc/module.xml" Warning!file_get_contents(/Volumes/Server/sites/m2dev.dev/app/code/Mage  
  nto/Rule/etc/module.xml): failed to open stream: No such file or directory                                                                                                     

dalger:08:17 PM:/sites/m2dev.dev (develop *) $ 
dmitrii-fediuk commented 8 years ago

The problem is reproduced with a new module installation. The following line raises the exception An abstract factory could not create an instance of magentosetupconsolecommandconfigsetcommand(alias: Magento\Setup\Console\Command\ConfigSetCommand).: https://github.com/magento/magento2/blob/22629abe10f9c640fe47b6081d57fedccdea8e0f/setup/src/Magento/Setup/Console/CommandList.php#L89

So the $commands array is empty. I recommend to wrap the line with try.. catch and do some exception handling there.

For now the exception is catched here: https://github.com/magento/magento2/blob/22629abe10f9c640fe47b6081d57fedccdea8e0f/lib/internal/Magento/Framework/Console/Cli.php#L118 And it is never shown to the user: the system just says: There are no commands defined in the "setup" namespace.

mazhalai commented 8 years ago

@dfediuk we changed the behavior to be consistent with Symfony's verbosity settings. Please use the verbosity settings are described here to see more details of the errors

davidalger commented 8 years ago

@dfediuk Can you let us know if the output with a higher verbosity setting is acceptable or not so we can either close this out or determine any further action?

dmitrii-fediuk commented 8 years ago

The verbosity settings do not help to diagnose the problem:

$ bin/magento setup:upgrade -vv

  [InvalidArgumentException]
  There are no commands defined in the "setup" namespace.

Exception trace:
 () at vendor\symfony\console\Symfony\Component\Console\Application.php:501
 Symfony\Component\Console\Application->findNamespace() at vendor\symfony\console\Symfony\Component\Console\Application.php:535
 Symfony\Component\Console\Application->find() at vendor\symfony\console\Symfony\Component\Console\Application.php:192
 Symfony\Component\Console\Application->doRun() at lib\internal\Magento\Framework\Console\Cli.php:49
 Magento\Framework\Console\Cli->doRun() at vendor\symfony\console\Symfony\Component\Console\Application.php:126
 Symfony\Component\Console\Application->run() at bin\magento:25
dmitrii-fediuk commented 8 years ago

A similar problem: https://github.com/magento/magento2/issues/2335

dmitrii-fediuk commented 8 years ago

I am pretty sure the Magento should be clear: "The Xxx_Yyy modules's etc/module.xml file is absent". Or "The Xxx_Yyy modules's composer.json file has the syntax error: <...>".

nkarthickannan commented 8 years ago

@dfediuk

I was also facing the similar issue. Issuing sudo chmod -R 777 * in my Ubuntu system solves this issue. It seems Magento is not able to create classes under var/generation directory. I am not sure what directory permission should be given to avoid this problem

woei66 commented 8 years ago

for my experience, when I faced this kind of problem, I will execute the CLI by root permission first to generate the result and using below command to figure out which files are changed/modified: find ./ -mmin -60 this command can help you find out which files or directories are changed in the last 60 minutes and you will know which directories without right permission

benmarks commented 8 years ago

:+1: for better error output / handling.

ktomk commented 8 years ago

If an extension has no etc/module.xml file

Isn't this (etc/module.xml) one of the two files an extension must have to qualify as one? (the other file is registration.php.)

So the report might be bogus:

Perhaps detailed steps on how to reproduce this issue should be given so that it can be elaborated if this is a concrete issue or not.

mazhalai commented 8 years ago

@mage2pro @ktomk is this still an issue?

mazhalai commented 8 years ago

We have added extra logging and return codes for all CLI commands which can be verified in 2.1.0-rc1. Please open a new issue if problems persist. Closing this issue.

armand93420 commented 7 years ago

composer update resolve this problem (If you are using Composer)