mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-05-24 17:32:14 +02:00
[Nostromo] Add Exception Listener for uncaught exceptions in Command, wrap Bin in exception for early errors.
This commit is contained in:
parent
2c5e44ab1e
commit
886b7edcf6
11
bin/mage
11
bin/mage
|
@ -10,6 +10,11 @@ if (file_exists(__DIR__ . '/../../../autoload.php')) {
|
||||||
|
|
||||||
use Mage\MageApplication;
|
use Mage\MageApplication;
|
||||||
|
|
||||||
$mage = new MageApplication();
|
try {
|
||||||
$mage->configure('.mage.yml');
|
$mage = new MageApplication();
|
||||||
$mage->run();
|
$mage->configure('.mage.yml');
|
||||||
|
$mage->run();
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
printf('Error: %s' . PHP_EOL, $exception->getMessage());
|
||||||
|
exit(9);
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,9 @@ use Symfony\Component\Finder\Finder;
|
||||||
use Symfony\Component\Finder\SplFileInfo;
|
use Symfony\Component\Finder\SplFileInfo;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler\StreamHandler;
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||||
|
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
|
||||||
|
use Symfony\Component\Console\ConsoleEvents;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
use Mage\Runtime\Exception\RuntimeException;
|
use Mage\Runtime\Exception\RuntimeException;
|
||||||
|
@ -31,6 +34,22 @@ class MageApplication extends Application
|
||||||
{
|
{
|
||||||
protected $runtime;
|
protected $runtime;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$dispatcher = new EventDispatcher();
|
||||||
|
|
||||||
|
$dispatcher->addListener(ConsoleEvents::EXCEPTION, function (ConsoleExceptionEvent $event) {
|
||||||
|
$output = $event->getOutput();
|
||||||
|
$command = $event->getCommand();
|
||||||
|
$output->writeln(sprintf('Oops, exception thrown while running command <info>%s</info>', $command->getName()));
|
||||||
|
$exitCode = $event->getExitCode();
|
||||||
|
$event->setException(new \LogicException('Caught exception', $exitCode, $event->getException()));
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->setDispatcher($dispatcher);
|
||||||
|
parent::__construct('Magallanes', Mage::VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the Magallanes Application
|
* Configure the Magallanes Application
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue