jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/325084 )

Change subject: resourceloader: Include backtrace in formatted errors (if 
enabled)
......................................................................


resourceloader: Include backtrace in formatted errors (if enabled)

Make ResourceLoader error formatting the same as everywhere else.
Which means if wgShowExceptionDetails is enabled locally, the
trace will be included as well.

This matches logic in MWExceptionRenderer.

Also move the typical error handling used by respond() to a
utility method to reduce duplication of code and avoid mistakes.

Change-Id: If04ae99618e4a758ed0f9dd2b555496b76da29de
---
M includes/resourceloader/ResourceLoader.php
1 file changed, 26 insertions(+), 20 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/resourceloader/ResourceLoader.php 
b/includes/resourceloader/ResourceLoader.php
index d338e9b..f0b48d5 100644
--- a/includes/resourceloader/ResourceLoader.php
+++ b/includes/resourceloader/ResourceLoader.php
@@ -606,6 +606,25 @@
        }
 
        /**
+        * Add an error to the 'errors' array and log it.
+        *
+        * Should only be called from within respond().
+        *
+        * @since 1.29
+        * @param Exception $e
+        * @param string $msg
+        * @param array $context
+        */
+       protected function outputErrorAndLog( Exception $e, $msg, array 
$context = [] ) {
+               MWExceptionHandler::logException( $e );
+               $this->logger->warning(
+                       $msg,
+                       $context + [ 'exception' => $e ]
+               );
+               $this->errors[] = self::formatExceptionNoComment( $e );
+       }
+
+       /**
         * Helper method to get and combine versions of multiple modules.
         *
         * @since 1.26
@@ -624,15 +643,12 @@
                                // If modules fail to compute a version, do 
still consider the versions
                                // of other modules - don't set an empty string 
E-Tag for the whole request.
                                // See also T152266 and 
StartupModule::getModuleRegistrations().
-                               MWExceptionHandler::logException( $e );
-                               $this->logger->warning(
+                               $this->outputErrorAndLog( $e,
                                        'Calculating version for "{module}" 
failed: {exception}',
                                        [
                                                'module' => $module,
-                                               'exception' => $e,
                                        ]
                                );
-                               $this->errors[] = 
self::formatExceptionNoComment( $e );
                                return '';
                        }
                }, $moduleNames );
@@ -709,11 +725,7 @@
                        // Preload for getCombinedVersion() and for batch 
makeModuleResponse()
                        $this->preloadModuleInfo( array_keys( $modules ), 
$context );
                } catch ( Exception $e ) {
-                       MWExceptionHandler::logException( $e );
-                       $this->logger->warning( 'Preloading module info failed: 
{exception}', [
-                               'exception' => $e
-                       ] );
-                       $this->errors[] = self::formatExceptionNoComment( $e );
+                       $this->outputErrorAndLog( $e, 'Preloading module info 
failed: {exception}' );
                }
 
                // Combine versions to propagate cache invalidation
@@ -721,11 +733,7 @@
                try {
                        $versionHash = $this->getCombinedVersion( $context, 
array_keys( $modules ) );
                } catch ( Exception $e ) {
-                       MWExceptionHandler::logException( $e );
-                       $this->logger->warning( 'Calculating version hash 
failed: {exception}', [
-                               'exception' => $e
-                       ] );
-                       $this->errors[] = self::formatExceptionNoComment( $e );
+                       $this->outputErrorAndLog( $e, 'Calculating version hash 
failed: {exception}' );
                }
 
                // See RFC 2616 ยง 3.11 Entity Tags
@@ -974,7 +982,9 @@
                        return MWExceptionHandler::getPublicLogMessage( $e );
                }
 
-               return MWExceptionHandler::getLogMessage( $e );
+               return MWExceptionHandler::getLogMessage( $e ) .
+                       "\nBacktrace:\n" .
+                       MWExceptionHandler::getRedactedTraceAsString( $e );
        }
 
        /**
@@ -1075,11 +1085,7 @@
                                $out .= $strContent;
 
                        } catch ( Exception $e ) {
-                               MWExceptionHandler::logException( $e );
-                               $this->logger->warning( 'Generating module 
package failed: {exception}', [
-                                       'exception' => $e
-                               ] );
-                               $this->errors[] = 
self::formatExceptionNoComment( $e );
+                               $this->outputErrorAndLog( $e, 'Generating 
module package failed: {exception}' );
 
                                // Respond to client with error-state instead 
of module implementation
                                $states[$name] = 'error';

-- 
To view, visit https://gerrit.wikimedia.org/r/325084
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If04ae99618e4a758ed0f9dd2b555496b76da29de
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to