From 65ace7c5a7d5af5c16c1e6d19084f0a4b7de3335 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 24 Nov 2016 12:28:40 +0100 Subject: [PATCH] handle errors in apps while registering commands Signed-off-by: Robin Appelman --- console.php | 2 +- lib/private/Console/Application.php | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/console.php b/console.php index c368a28cac0..fb410ee6983 100644 --- a/console.php +++ b/console.php @@ -85,7 +85,7 @@ try { echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL; } - $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest()); + $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest(), \OC::$server->getLogger()); $application->loadCommands(new ArgvInput(), new ConsoleOutput()); $application->run(); } catch (Exception $ex) { diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index cd76b43f095..f7806ba01a7 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -31,6 +31,7 @@ use OC_App; use OCP\AppFramework\QueryException; use OCP\Console\ConsoleEvent; use OCP\IConfig; +use OCP\ILogger; use OCP\IRequest; use Symfony\Component\Console\Application as SymfonyApplication; use Symfony\Component\Console\Input\InputInterface; @@ -45,18 +46,22 @@ class Application { private $dispatcher; /** @var IRequest */ private $request; + /** @var ILogger */ + private $logger; /** * @param IConfig $config * @param EventDispatcherInterface $dispatcher * @param IRequest $request + * @param ILogger $logger */ - public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request) { + public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request, ILogger $logger) { $defaults = \OC::$server->getThemingDefaults(); $this->config = $config; $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); $this->dispatcher = $dispatcher; $this->request = $request; + $this->logger = $logger; } /** @@ -110,7 +115,11 @@ class Application { \OC_App::registerAutoloading($app, $appPath); $file = $appPath . '/appinfo/register_command.php'; if (file_exists($file)) { - require $file; + try { + require $file; + } catch (\Exception $e) { + $this->logger->logException($e); + } } } } -- 2.39.5