From 7a72b16e0f4c3ef1f0befc330458e8eadd5f32b9 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 13 Feb 2019 01:45:56 +0000 Subject: [PATCH] resourceloader: Ignore warnings in JSMinPlus parser It's old and unmaintained. The only thing we care about is if it was able to parse the script and if not, what its error is. Its return value or broken inner workings are insignificant at this point and only cause noise. Bug: T77169 Change-Id: Ie357ccfcc6141f894b452eb3996e168c1526990f --- .../resourceloader/ResourceLoaderModule.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index ae79dda520..b39262527c 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -956,16 +956,25 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { $cache::TTL_WEEK, function () use ( $contents, $fileName ) { $parser = self::javaScriptParser(); + $err = null; try { + Wikimedia\suppressWarnings(); $parser->parse( $contents, $fileName, 1 ); - $result = $contents; } catch ( Exception $e ) { - // We'll save this to cache to avoid having to re-validate broken JS - $err = $e->getMessage(); - $result = "mw.log.error(" . - Xml::encodeJsVar( "JavaScript parse error: $err" ) . ");"; + $err = $e; + } finally { + Wikimedia\restoreWarnings(); } - return $result; + if ( $err ) { + // Send the error to the browser console client-side. + // By returning this as replacement for the actual script, + // we ensure modules are safe to load in a batch request, + // without causing other unrelated modules to break. + return 'mw.log.error(' . + Xml::encodeJsVar( 'JavaScript parse error: ' . $err->getMessage() ) . + ');'; + } + return $contents; } ); } -- 2.20.1