Skip to content

Commit 293ba1e

Browse files
committed
Merge remote-tracking branch 'ogresCE/MAGETWO-44382-cli-error-message' into PR_Branch
2 parents ddeb801 + 8553c85 commit 293ba1e

File tree

1 file changed

+53
-28
lines changed
  • lib/internal/Magento/Framework/Console

1 file changed

+53
-28
lines changed

lib/internal/Magento/Framework/Console/Cli.php

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Magento\Framework\App\Bootstrap;
1212
use Magento\Framework\Shell\ComplexParameter;
1313
use Symfony\Component\Console\Input\ArgvInput;
14+
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
1416

1517
/**
1618
* Magento2 CLI Application. This is the hood for all command line tools supported by Magento.
@@ -27,6 +29,34 @@ class Cli extends SymfonyApplication
2729
/** @var \Zend\ServiceManager\ServiceManager */
2830
private $serviceManager;
2931

32+
/**
33+
* Initialization exception
34+
*
35+
* @var \Exception
36+
*/
37+
private $initException;
38+
39+
/**
40+
* Process an error happened during initialization of commands, if any
41+
*
42+
* @param InputInterface $input
43+
* @param OutputInterface $output
44+
* @return int
45+
* @throws \Exception
46+
*/
47+
public function doRun(InputInterface $input, OutputInterface $output)
48+
{
49+
$exitCode = parent::doRun($input, $output);
50+
if ($this->initException) {
51+
$output->writeln(
52+
"<error>We're sorry, an error occurred. Try clearing the cache and code generation directories. "
53+
. "By default, they are: var/cache, var/di, var/generation, and var/page_cache.</error>"
54+
);
55+
throw $this->initException;
56+
}
57+
return $exitCode;
58+
}
59+
3060
/**
3161
* @param string $name The name of the application
3262
* @param string $version The version of the application
@@ -61,38 +91,33 @@ protected function getDefaultCommands()
6191
*/
6292
protected function getApplicationCommands()
6393
{
64-
$setupCommands = [];
65-
$modulesCommands = [];
94+
$commands = [];
95+
try {
96+
$bootstrapParam = new ComplexParameter(self::INPUT_KEY_BOOTSTRAP);
97+
$params = $bootstrapParam->mergeFromArgv($_SERVER, $_SERVER);
98+
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
99+
$bootstrap = Bootstrap::create(BP, $params);
100+
$objectManager = $bootstrap->getObjectManager();
101+
/** @var \Magento\Setup\Model\ObjectManagerProvider $omProvider */
102+
$omProvider = $this->serviceManager->get('Magento\Setup\Model\ObjectManagerProvider');
103+
$omProvider->setObjectManager($objectManager);
66104

67-
$bootstrapParam = new ComplexParameter(self::INPUT_KEY_BOOTSTRAP);
68-
$params = $bootstrapParam->mergeFromArgv($_SERVER, $_SERVER);
69-
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
70-
$bootstrap = Bootstrap::create(BP, $params);
71-
$objectManager = $bootstrap->getObjectManager();
72-
/** @var \Magento\Setup\Model\ObjectManagerProvider $omProvider */
73-
$omProvider = $this->serviceManager->get('Magento\Setup\Model\ObjectManagerProvider');
74-
$omProvider->setObjectManager($objectManager);
105+
if (class_exists('Magento\Setup\Console\CommandList')) {
106+
$setupCommandList = new \Magento\Setup\Console\CommandList($this->serviceManager);
107+
$commands = array_merge($commands, $setupCommandList->getCommands());
108+
}
75109

76-
if (class_exists('Magento\Setup\Console\CommandList')) {
77-
$setupCommandList = new \Magento\Setup\Console\CommandList($this->serviceManager);
78-
$setupCommands = $setupCommandList->getCommands();
79-
}
110+
if ($objectManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) {
111+
/** @var \Magento\Framework\Console\CommandList $commandList */
112+
$commandList = $objectManager->create('Magento\Framework\Console\CommandList');
113+
$commands = array_merge($commands, $commandList->getCommands());
114+
}
80115

81-
if ($objectManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) {
82-
/** @var \Magento\Framework\Console\CommandList $commandList */
83-
$commandList = $objectManager->create('Magento\Framework\Console\CommandList');
84-
$modulesCommands = $commandList->getCommands();
116+
$commands = array_merge($commands, $this->getVendorCommands($objectManager));
117+
} catch (\Exception $e) {
118+
$this->initException = $e;
85119
}
86-
87-
$vendorCommands = $this->getVendorCommands($objectManager);
88-
89-
$commandsList = array_merge(
90-
$setupCommands,
91-
$modulesCommands,
92-
$vendorCommands
93-
);
94-
95-
return $commandsList;
120+
return $commands;
96121
}
97122

98123
/**

0 commit comments

Comments
 (0)