mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01: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
					
				
							
								
								
									
										5
									
								
								bin/mage
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								bin/mage
									
									
									
									
									
								
							@ -10,6 +10,11 @@ if (file_exists(__DIR__ . '/../../../autoload.php')) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use Mage\MageApplication;
 | 
					use Mage\MageApplication;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try {
 | 
				
			||||||
    $mage = new MageApplication();
 | 
					    $mage = new MageApplication();
 | 
				
			||||||
    $mage->configure('.mage.yml');
 | 
					    $mage->configure('.mage.yml');
 | 
				
			||||||
    $mage->run();
 | 
					    $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 New Issue
	
	Block a user