Skip to content

Commit

Permalink
Merge pull request #43 from OXIDprojects/hotfix/error_output
Browse files Browse the repository at this point in the history
Small fix to catch the di php-error earlier.
  • Loading branch information
TumTum authored May 6, 2019
2 parents deb4dd2 + 3f18342 commit 2fe0cac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions bin/oxrun
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ $autoloader = require_once $OXRUN_VENDOR_PATH . 'autoload.php';
$application = new \Oxrun\Application($autoloader, 'oxrun', '@package_version@');

register_shutdown_function([OxrunErrorHandling::class, 'shutdown']);
set_exception_handler([OxrunErrorHandling::class, 'handleUncaughtException']);

try {
$commandFinder = (new CommandFinder())
Expand Down
21 changes: 16 additions & 5 deletions src/Oxrun/Helper/OxrunErrorHandling.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function shutdown()
$error = error_get_last();
if (in_array($error['type'], $handledErrorTypes)) {
$consoleOutput = new ConsoleOutput();
$consoleOutput->writeln("<error>$error</error>");
$consoleOutput->writeln("<error>{$error['message']}</error>");
exit(2);
}
}
Expand All @@ -34,16 +34,27 @@ public static function handleUncaughtException($exception)
{
$consoleOutput = new ConsoleOutput();

if (basename($exception->getFile()) == basename(ContainerCollection::getContainerPath())) {
self::isContainerErrorRecreate($exception->getFile());

$consoleOutput->writeln("<error>$exception</error>");
exit(2);
}

/**
* Try to recreate container is a fatal error in OxrunCommands.php
*
* @param $exception
* @param $exit_code
*/
protected static function isContainerErrorRecreate($filename)
{
if (basename($filename) == basename(ContainerCollection::getContainerPath())) {
ContainerCollection::destroyCompiledContainer();

if (getenv('AUTORESTART') != 1) {
passthru('AUTORESTART=1 ' . implode(" ", $_SERVER['argv']), $exit_code);
exit($exit_code);
}
}

$consoleOutput->writeln("<error>$exception</error>");
exit(2);
}
}

0 comments on commit 2fe0cac

Please sign in to comment.