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
This commit is contained in:
Timo Tijhof 2015-09-15 04:17:47 +01:00
parent 47dda77573
commit d478ffde10

View file

@ -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();