From 2202dbbfabca7d36eb3e662fbbf3dfe31321efc9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Wed, 14 Jan 2015 07:09:41 +0000 Subject: [PATCH] Allow subscribing to module loading exceptions Provide access via mw.track to module loading errors which are otherwise swallowed by mw.loader. Bug: T513 Bug: T85263 Change-Id: Ifc13c207af36dc56be931a3b140063354513a4ec --- resources/src/mediawiki/mediawiki.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index 90b8503266..2e78c1c7cd 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -668,6 +668,23 @@ */ loader: ( function () { + /** + * Fired via mw.track on various resource loading errors. + * + * @event resourceloader_exception + * @param {Error|Mixed} e The error that was thrown. Almost always an Error + * object, but in theory module code could manually throw something else, and that + * might also end up here. + * @param {string} [module] Name of the module which caused the error. Omitted if the + * error is not module-related or the module cannot be easily identified due to + * batched handling. + * @param {string} source Source of the error. Possible values: + * - style: stylesheet error (only affects old IE where a special style loading method + * is used) + * - load-callback: exception thrown by user callback + * - module-execute: exception thrown by module code + */ + /** * Mapping of registered modules. * @@ -852,6 +869,7 @@ styleEl.styleSheet.cssText += cssText; } catch ( e ) { log( 'Stylesheet error', e ); + mw.track( 'resourceloader.exception', { exception: e, source: 'stylesheet' } ); } } else { styleEl.appendChild( document.createTextNode( cssText ) ); @@ -1115,6 +1133,8 @@ // A user-defined callback raised an exception. // Swallow it to protect our state machine! log( 'Exception thrown by user callback', e ); + mw.track( 'resourceloader.exception', + { exception: e, module: module, source: 'load-callback' } ); } } } @@ -1242,6 +1262,7 @@ // and not in debug mode, such as when a symbol that should be global isn't exported log( 'Exception thrown by ' + module, e ); registry[module].state = 'error'; + mw.track( 'resourceloader.exception', { exception: e, module: module, source: 'module-execute' } ); handlePending( module ); } } -- 2.20.1