Make MWExceptionHandler work with PHP7's exception changes
authorjeroendedauw <jeroendedauw@gmail.com>
Mon, 7 Sep 2015 18:37:57 +0000 (20:37 +0200)
committerJeroen De Dauw <jeroendedauw@gmail.com>
Wed, 16 Sep 2015 11:22:38 +0000 (11:22 +0000)
See https://wiki.php.net/rfc/throwable-interface

Bug: T107933
Change-Id: I703c8710c8adeff14c1cbaab89f5688f6cb96c24

includes/exception/MWExceptionHandler.php

index d4a240f..d25f1a8 100644 (file)
@@ -56,9 +56,9 @@ class MWExceptionHandler {
 
        /**
         * Report an exception to the user
 
        /**
         * Report an exception to the user
-        * @param Exception $e
+        * @param Exception|Throwable $e
         */
         */
-       protected static function report( Exception $e ) {
+       protected static function report( $e ) {
                global $wgShowExceptionDetails;
 
                $cmdLine = MWException::isCommandLine();
                global $wgShowExceptionDetails;
 
                $cmdLine = MWException::isCommandLine();
@@ -132,9 +132,9 @@ class MWExceptionHandler {
         * transaction could be aborted properly.
         *
         * @since 1.23
         * transaction could be aborted properly.
         *
         * @since 1.23
-        * @param Exception $e
+        * @param Exception|Throwable $e
         */
         */
-       public static function rollbackMasterChangesAndLog( Exception $e ) {
+       public static function rollbackMasterChangesAndLog( $e ) {
                $factory = wfGetLBFactory();
                if ( $factory->hasMasterChanges() ) {
                        $logger = LoggerFactory::getInstance( 'Bug56269' );
                $factory = wfGetLBFactory();
                if ( $factory->hasMasterChanges() ) {
                        $logger = LoggerFactory::getInstance( 'Bug56269' );
@@ -159,9 +159,9 @@ class MWExceptionHandler {
         *   }
         *
         * @since 1.25
         *   }
         *
         * @since 1.25
-        * @param Exception $e
+        * @param Exception|Throwable $e
         */
         */
-       public static function handleException( Exception $e ) {
+       public static function handleException( $e ) {
                try {
                        // Rollback DBs to avoid transaction notices. This may fail
                        // to rollback some DB due to connection issues or exceptions.
                try {
                        // Rollback DBs to avoid transaction notices. This may fail
                        // to rollback some DB due to connection issues or exceptions.
@@ -350,11 +350,11 @@ TXT;
         * Like Exception::getTraceAsString, but replaces argument values with
         * argument type or class name.
         *
         * Like Exception::getTraceAsString, but replaces argument values with
         * argument type or class name.
         *
-        * @param Exception $e
+        * @param Exception|Throwable $e
         * @return string
         * @see prettyPrintTrace()
         */
         * @return string
         * @see prettyPrintTrace()
         */
-       public static function getRedactedTraceAsString( Exception $e ) {
+       public static function getRedactedTraceAsString( $e ) {
                return self::prettyPrintTrace( self::getRedactedTrace( $e ) );
        }
 
                return self::prettyPrintTrace( self::getRedactedTrace( $e ) );
        }
 
@@ -407,10 +407,10 @@ TXT;
         * or its type (if the element is a PHP primitive).
         *
         * @since 1.22
         * or its type (if the element is a PHP primitive).
         *
         * @since 1.22
-        * @param Exception $e
+        * @param Exception|Throwable $e
         * @return array
         */
         * @return array
         */
-       public static function getRedactedTrace( Exception $e ) {
+       public static function getRedactedTrace( $e ) {
                return static::redactTrace( $e->getTrace() );
        }
 
                return static::redactTrace( $e->getTrace() );
        }
 
@@ -442,10 +442,10 @@ TXT;
         * $wgShowExceptionDetails is set to false), to the entry in the debug log.
         *
         * @since 1.22
         * $wgShowExceptionDetails is set to false), to the entry in the debug log.
         *
         * @since 1.22
-        * @param Exception $e
+        * @param Exception|Throwable $e
         * @return string
         */
         * @return string
         */
-       public static function getLogId( Exception $e ) {
+       public static function getLogId( $e ) {
                if ( !isset( $e->_mwLogId ) ) {
                        $e->_mwLogId = wfRandomString( 8 );
                }
                if ( !isset( $e->_mwLogId ) ) {
                        $e->_mwLogId = wfRandomString( 8 );
                }
@@ -471,10 +471,10 @@ TXT;
         * Get a message formatting the exception message and its origin.
         *
         * @since 1.22
         * Get a message formatting the exception message and its origin.
         *
         * @since 1.22
-        * @param Exception $e
+        * @param Exception|Throwable $e
         * @return string
         */
         * @return string
         */
-       public static function getLogMessage( Exception $e ) {
+       public static function getLogMessage( $e ) {
                $id = self::getLogId( $e );
                $type = get_class( $e );
                $file = $e->getFile();
                $id = self::getLogId( $e );
                $type = get_class( $e );
                $file = $e->getFile();
@@ -492,10 +492,10 @@ TXT;
         * exception that can be used to augment a log message sent to a PSR-3
         * logger.
         *
         * exception that can be used to augment a log message sent to a PSR-3
         * logger.
         *
-        * @param Exception $e
+        * @param Exception|Throwable $e
         * @return array
         */
         * @return array
         */
-       public static function getLogContext( Exception $e ) {
+       public static function getLogContext( $e ) {
                return array(
                        'exception' => $e,
                        'exception_id' => static::getLogId( $e ),
                return array(
                        'exception' => $e,
                        'exception_id' => static::getLogId( $e ),
@@ -509,11 +509,11 @@ TXT;
         * backtrace) derived from the given exception. The backtrace information
         * will be redacted as per getRedactedTraceAsArray().
         *
         * backtrace) derived from the given exception. The backtrace information
         * will be redacted as per getRedactedTraceAsArray().
         *
-        * @param Exception $e
+        * @param Exception|Throwable $e
         * @return array
         * @since 1.26
         */
         * @return array
         * @since 1.26
         */
-       public static function getStructuredExceptionData( Exception $e ) {
+       public static function getStructuredExceptionData( $e ) {
                global $wgLogExceptionBacktrace;
                $data = array(
                        'id' => self::getLogId( $e ),
                global $wgLogExceptionBacktrace;
                $data = array(
                        'id' => self::getLogId( $e ),
@@ -592,12 +592,12 @@ TXT;
         * @endcode
         *
         * @since 1.23
         * @endcode
         *
         * @since 1.23
-        * @param Exception $e
+        * @param Exception|Throwable $e
         * @param bool $pretty Add non-significant whitespace to improve readability (default: false).
         * @param int $escaping Bitfield consisting of FormatJson::.*_OK class constants.
         * @return string|false JSON string if successful; false upon failure
         */
         * @param bool $pretty Add non-significant whitespace to improve readability (default: false).
         * @param int $escaping Bitfield consisting of FormatJson::.*_OK class constants.
         * @return string|false JSON string if successful; false upon failure
         */
-       public static function jsonSerializeException( Exception $e, $pretty = false, $escaping = 0 ) {
+       public static function jsonSerializeException( $e, $pretty = false, $escaping = 0 ) {
                $data = self::getStructuredExceptionData( $e );
                return FormatJson::encode( $data, $pretty, $escaping );
        }
                $data = self::getStructuredExceptionData( $e );
                return FormatJson::encode( $data, $pretty, $escaping );
        }
@@ -609,9 +609,9 @@ TXT;
         * it is also used to handle PHP exceptions or exceptions from other libraries.
         *
         * @since 1.22
         * it is also used to handle PHP exceptions or exceptions from other libraries.
         *
         * @since 1.22
-        * @param Exception $e
+        * @param Exception|Throwable $e
         */
         */
-       public static function logException( Exception $e ) {
+       public static function logException( $e ) {
                if ( !( $e instanceof MWException ) || $e->isLoggable() ) {
                        $logger = LoggerFactory::getInstance( 'exception' );
                        $logger->error(
                if ( !( $e instanceof MWException ) || $e->isLoggable() ) {
                        $logger = LoggerFactory::getInstance( 'exception' );
                        $logger->error(