X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/bilan.php?a=blobdiff_plain;f=includes%2Fexception%2FMWExceptionHandler.php;h=205ec777731883be3d01bef2bba0fc5ebad24c23;hb=55c51f36a4869614d870dac5d870638ec58a95ff;hp=a2ec391dc1a89a707f6ee5e71c3de438d826592c;hpb=56ade0650d492e01d2689dc918e7db3d56d18147;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/exception/MWExceptionHandler.php b/includes/exception/MWExceptionHandler.php index a2ec391dc1..205ec77773 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 ( wfIsCLI() ) { + register_shutdown_function( + function () { + exit( 255 ); + } + ); + } + } + /** * Exception handler which simulates the appropriate catch() handling: * @@ -260,7 +279,7 @@ class MWExceptionHandler { // HHVM: Class undefined: foo // PHP5: Class 'foo' not found if ( preg_match( "/Class (undefined: \w+|'\w+' not found)/", $msg ) ) { - // @codingStandardsIgnoreStart Generic.Files.LineLength.TooLong + // phpcs:disable Generic.Files.LineLength $msg = <<mediawiki.org for help on installing the required components. TXT; - // @codingStandardsIgnoreEnd + // phpcs:enable } // We can't just create an exception and log it as it is likely that @@ -281,7 +300,7 @@ TXT; $logger = LoggerFactory::getInstance( 'fatal' ); $logger->error( $msg, [ 'fatal_exception' => [ - 'class' => 'ErrorException', + 'class' => ErrorException::class, 'message' => "PHP Fatal Error: {$message}", 'code' => $level, 'file' => $file,