Skip to content

Commit

Permalink
Merge pull request #24075 from owncloud/no-html-on-cli
Browse files Browse the repository at this point in the history
In case of fatal php errors and other unhandled exceptions no html er…
  • Loading branch information
LukasReschke committed Apr 20, 2016
2 parents ae27583 + c609abf commit afad27f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 8 additions & 3 deletions console.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
return;
}

function exceptionHandler($exception) {
echo "An unhandled exception has been thrown:" . PHP_EOL;
echo $exception;
exit(1);
}
try {
require_once 'lib/base.php';

Expand All @@ -53,6 +58,8 @@
exit(0);
}

set_exception_handler('exceptionHandler');

if (!OC_Util::runningOnWindows()) {
if (!function_exists('posix_getuid')) {
echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
Expand Down Expand Up @@ -87,7 +94,5 @@
$application->loadCommands(new ArgvInput(), new ConsoleOutput());
$application->run();
} catch (Exception $ex) {
echo "An unhandled exception has been thrown:" . PHP_EOL;
echo $ex;
exit(1);
exceptionHandler($ex);
}
11 changes: 3 additions & 8 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,14 +545,9 @@ public static function init() {
OC_Util::isSetLocaleWorking();

if (!defined('PHPUNIT_RUN')) {
$logger = \OC::$server->getLogger();
OC\Log\ErrorHandler::setLogger($logger);
if (\OC::$server->getConfig()->getSystemValue('debug', false)) {
OC\Log\ErrorHandler::register(true);
set_exception_handler(array('OC_Template', 'printExceptionErrorPage'));
} else {
OC\Log\ErrorHandler::register();
}
OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger());
$debug = \OC::$server->getConfig()->getSystemValue('debug', false);
OC\Log\ErrorHandler::register($debug);
}

// register the stream wrappers
Expand Down
3 changes: 3 additions & 0 deletions lib/private/log/errorhandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public static function register($debug=false) {

if ($debug) {
set_error_handler(array($handler, 'onAll'), E_ALL);
if (\OC::$CLI) {
set_exception_handler(array('OC_Template', 'printExceptionErrorPage'));
}
} else {
set_error_handler(array($handler, 'onError'));
}
Expand Down

0 comments on commit afad27f

Please sign in to comment.