-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix Wrong Exception on Cli run when Command Not found #40063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.4-develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,6 +62,13 @@ class Cli extends Console\Application | |||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| private $initException; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * GetCommands exception. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * @var \Exception | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| private $getCommandsException; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * @var ObjectManagerInterface | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
|
|
@@ -111,7 +118,7 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') | |||||||||||||||||||||||
| $this->setCommandLoader($this->getCommandLoader()); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * @inheritdoc | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * @throws \Exception The exception in case of unexpected error | ||||||||||||||||||||||||
|
|
@@ -123,8 +130,28 @@ public function doRun(Console\Input\InputInterface $input, Console\Output\Output | |||||||||||||||||||||||
| $exitCode = parent::doRun($input, $output); | ||||||||||||||||||||||||
| } catch (\Exception $e) { | ||||||||||||||||||||||||
| $errorMessage = $e->getMessage() . PHP_EOL . $e->getTraceAsString(); | ||||||||||||||||||||||||
| $this->logger->error($errorMessage); | ||||||||||||||||||||||||
| $this->initException = $e; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if ($this->getCommandsException) { | ||||||||||||||||||||||||
| // No need to concatenate the exception message because it's already included in the $e->previous | ||||||||||||||||||||||||
| // Example of the final exception : | ||||||||||||||||||||||||
| // Exception during console commands initialization: Class "Vendor\Migration\Console\Command\ImportOrdersCommand" does not exist | ||||||||||||||||||||||||
| // code: 0 | ||||||||||||||||||||||||
| // file: "./vendor/magento/framework/Console/Cli.php" | ||||||||||||||||||||||||
| // line: 131 | ||||||||||||||||||||||||
| // -previous: Symfony\Component\Console\Exception\NamespaceNotFoundException^ {#3199 | ||||||||||||||||||||||||
| // #message: """ | ||||||||||||||||||||||||
| // There are no commands defined in the "c" namespace.\n | ||||||||||||||||||||||||
| // \n | ||||||||||||||||||||||||
| // Did you mean one of these?\n | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| $combinedErrorMessage = "Exception during console commands initialization: " . | ||||||||||||||||||||||||
| $this->getCommandsException->getMessage() . PHP_EOL; | ||||||||||||||||||||||||
|
Comment on lines
+147
to
+148
|
||||||||||||||||||||||||
| $combinedErrorMessage = "Exception during console commands initialization: " . | |
| $this->getCommandsException->getMessage() . PHP_EOL; | |
| $combinedErrorMessage = sprintf( | |
| 'Exception during console commands initialization: %s%s', | |
| $this->getCommandsException->getMessage(), | |
| PHP_EOL | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain, why this change is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From reply in #40063 (comment):
We don't need these lines; it is probably due to a merge issue. You can
follow the logic. These lines don't change logic, just were touched by the
commit
These lines were added, so let's remove them if we don't need them
Copilot
AI
Jul 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setup command initialization has been moved outside the deployment config check, which changes the execution order. This should be documented or the reasoning should be clearer, as it may affect command availability in different deployment states.
| if (class_exists(\Magento\Setup\Console\CommandList::class)) { | |
| $setupCommandList = new \Magento\Setup\Console\CommandList($this->serviceManager); | |
| $commands = array_merge($commands, $setupCommandList->getCommands()); | |
| } | |
| if ($this->objectManager->get(DeploymentConfig::class)->isAvailable()) { | |
| if ($this->objectManager->get(DeploymentConfig::class)->isAvailable()) { | |
| if (class_exists(\Magento\Setup\Console\CommandList::class)) { | |
| $setupCommandList = new \Magento\Setup\Console\CommandList($this->serviceManager); | |
| $commands = array_merge($commands, $setupCommandList->getCommands()); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docblock comment 'GetCommands exception' should be more descriptive. Consider: 'Exception thrown during command list initialization.'