From: Marius Hoch Date: Wed, 4 Oct 2017 16:10:27 +0000 (+0200) Subject: CLI: Make sure we don't exit with 0 when an exception is encountered X-Git-Tag: 1.31.0-rc.0~1868^2 X-Git-Url: https://git.cyclocoop.org/%2C?a=commitdiff_plain;h=ecb5408a33d22dcee15bccecb43faf91d943c87a;p=lhc%2Fweb%2Fwiklou.git CLI: Make sure we don't exit with 0 when an exception is encountered I registered the additional shutdown function for CLI only as it shouldn't have effect otherwise. Bug: T177414 Change-Id: I440d294eef5e307743cfc7f5ab3b531e8c973873 --- diff --git a/includes/exception/MWExceptionHandler.php b/includes/exception/MWExceptionHandler.php index a2ec391dc1..9b591918d4 100644 --- a/includes/exception/MWExceptionHandler.php +++ b/includes/exception/MWExceptionHandler.php @@ -51,7 +51,7 @@ class MWExceptionHandler { * Install handlers with PHP. */ public static function installHandler() { - set_exception_handler( 'MWExceptionHandler::handleException' ); + set_exception_handler( 'MWExceptionHandler::handleUncaughtException' ); set_error_handler( 'MWExceptionHandler::handleError' ); // Reserve 16k of memory so we can report OOM fatals @@ -111,6 +111,25 @@ class MWExceptionHandler { self::logException( $e, self::CAUGHT_BY_HANDLER ); } + /** + * Callback to use with PHP's set_exception_handler. + * + * @since 1.31 + * @param Exception|Throwable $e + */ + public static function handleUncaughtException( $e ) { + self::handleException( $e ); + + // Make sure we don't claim success on exit for CLI scripts (T177414) + if ( PHP_SAPI === 'cli' ) { + register_shutdown_function( + function () { + exit( 255 ); + } + ); + } + } + /** * Exception handler which simulates the appropriate catch() handling: *