From d478ffde100563abaddbfcb69dd9ad40f7def8d9 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 15 Sep 2015 04:17:47 +0100 Subject: [PATCH] resourceloader: Log load.php exceptions to JavaScript console * Use implode() instead of foreach concat. * Use two new lines instead of just one since the exception message with stacktrace spans multiple lines (makes it easier to distinguish when there are indeed exceptions from multiple sources). * Output a single comment instead of one for each. * If context is a JavaScript response, also include a console.error call with the erro message. To try out: * Break a file module descriptor in Resources.php by e.g. making a typo in one of the scripts arrays. * View a page on-wiki that uses the module (e.g. jquery.accessKeyLabel is loaded on most pages). * Observe error in the console. Bug: T110659 Change-Id: I4272795f1fab96a2effe2a6c068a56421adaa512 --- includes/resourceloader/ResourceLoader.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index b8ec63bb29..fa0f23d680 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -747,18 +747,18 @@ class ResourceLoader implements LoggerAwareInterface { if ( $context->getImageObj() && $this->errors ) { // We can't show both the error messages and the response when it's an image. - $errorText = ''; - foreach ( $this->errors as $error ) { - $errorText .= $error . "\n"; - } - $response = $errorText; + $response = implode( "\n\n", $this->errors ); } elseif ( $this->errors ) { - // Prepend comments indicating errors - $errorText = ''; - foreach ( $this->errors as $error ) { - $errorText .= self::makeComment( $error ); + $errorText = implode( "\n\n", $this->errors ); + $errorResponse = self::makeComment( $errorText ); + if ( $context->shouldIncludeScripts() ) { + $errorResponse .= 'if (window.console && console.error) {' + . Xml::encodeJsCall( 'console.error', array( $errorText ) ) + . "}\n"; } - $response = $errorText . $response; + + // Prepend error info to the response + $response = $errorResponse . $response; } $this->errors = array(); -- 2.20.1