Merge "Avoid double-rendering on late exceptions"
[lhc/web/wiklou.git] / includes / exception / MWExceptionHandler.php
index 26960ff..63adc29 100644 (file)
@@ -33,10 +33,10 @@ class MWExceptionHandler {
        /**
         * @var array $fatalErrorTypes
         */
-       protected static $fatalErrorTypes = array(
+       protected static $fatalErrorTypes = [
                E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR,
                /* HHVM's FATAL_ERROR level */ 16777217,
-       );
+       ];
        /**
         * @var bool $handledFatalCallback
         */
@@ -143,7 +143,7 @@ class MWExceptionHandler {
                                self::getLogMessage( $e ),
                                self::getLogContext( $e )
                        );
-                       $factory->rollbackMasterChanges();
+                       $factory->rollbackMasterChanges( __METHOD__ );
                }
        }
 
@@ -246,7 +246,6 @@ class MWExceptionHandler {
                return false;
        }
 
-
        /**
         * Dual purpose callback used as both a set_error_handler() callback and
         * a registered shutdown function. Receive a callback from the interpreter
@@ -327,17 +326,17 @@ TXT;
                // log.
                $trace = $trace ?: debug_backtrace();
                $logger = LoggerFactory::getInstance( 'fatal' );
-               $logger->error( $msg, array(
-                       'exception' => array(
+               $logger->error( $msg, [
+                       'exception' => [
                                'class' => 'ErrorException',
                                'message' => "PHP Fatal Error: {$message}",
                                'code' => $level,
                                'file' => $file,
                                'line' => $line,
                                'trace' => static::redactTrace( $trace ),
-                       ),
+                       ],
                        'exception_id' => wfRandomString( 8 ),
-               ) );
+               ] );
 
                // Remember call so we don't double process via HHVM's fatal
                // notifications and the shutdown hook behavior
@@ -446,14 +445,13 @@ TXT;
         * $wgShowExceptionDetails is set to false), to the entry in the debug log.
         *
         * @since 1.22
+        * @deprecated since 1.27: Exception IDs are synonymous with request IDs.
         * @param Exception|Throwable $e
         * @return string
         */
        public static function getLogId( $e ) {
-               if ( !isset( $e->_mwLogId ) ) {
-                       $e->_mwLogId = wfRandomString( 8 );
-               }
-               return $e->_mwLogId;
+               wfDeprecated( __METHOD__, '1.27' );
+               return WebRequest::getRequestId();
        }
 
        /**
@@ -479,7 +477,7 @@ TXT;
         * @return string
         */
        public static function getLogMessage( $e ) {
-               $id = self::getLogId( $e );
+               $id = WebRequest::getRequestId();
                $type = get_class( $e );
                $file = $e->getFile();
                $line = $e->getLine();
@@ -490,9 +488,9 @@ TXT;
        }
 
        public static function getPublicLogMessage( Exception $e ) {
-               $logId = self::getLogId( $e );
+               $reqId = WebRequest::getRequestId();
                $type = get_class( $e );
-               return '[' . $logId . '] '
+               return '[' . $reqId . '] '
                        . gmdate( 'Y-m-d H:i:s' ) . ': '
                        . 'Fatal exception of type ' . $type;
        }
@@ -508,10 +506,10 @@ TXT;
         * @return array
         */
        public static function getLogContext( $e ) {
-               return array(
+               return [
                        'exception' => $e,
-                       'exception_id' => static::getLogId( $e ),
-               );
+                       'exception_id' => WebRequest::getRequestId(),
+               ];
        }
 
        /**
@@ -527,15 +525,15 @@ TXT;
         */
        public static function getStructuredExceptionData( $e ) {
                global $wgLogExceptionBacktrace;
-               $data = array(
-                       'id' => self::getLogId( $e ),
+               $data = [
+                       'id' => WebRequest::getRequestId(),
                        'type' => get_class( $e ),
                        'file' => $e->getFile(),
                        'line' => $e->getLine(),
                        'message' => $e->getMessage(),
                        'code' => $e->getCode(),
                        'url' => self::getURL() ?: null,
-               );
+               ];
 
                if ( $e instanceof ErrorException &&
                        ( error_reporting() & $e->getSeverity() ) === 0
@@ -634,10 +632,10 @@ TXT;
                        $json = self::jsonSerializeException( $e, false, FormatJson::ALL_OK );
                        if ( $json !== false ) {
                                $logger = LoggerFactory::getInstance( 'exception-json' );
-                               $logger->error( $json, array( 'private' => true ) );
+                               $logger->error( $json, [ 'private' => true ] );
                        }
 
-                       Hooks::run( 'LogException', array( $e, false ) );
+                       Hooks::run( 'LogException', [ $e, false ] );
                }
        }
 
@@ -665,9 +663,9 @@ TXT;
                $json = self::jsonSerializeException( $e, false, FormatJson::ALL_OK );
                if ( $json !== false ) {
                        $logger = LoggerFactory::getInstance( "{$channel}-json" );
-                       $logger->error( $json, array( 'private' => true ) );
+                       $logger->error( $json, [ 'private' => true ] );
                }
 
-               Hooks::run( 'LogException', array( $e, $suppressed ) );
+               Hooks::run( 'LogException', [ $e, $suppressed ] );
        }
 }