mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-15 02:13:49 +00:00
a9d73060fa
When moving to packageFiles, the modules errorLogging and toc were not imported by init.js meaning they were not run. ResourceLoader should probably error in this situation, but until then we should fix this problem. This is a follow up to I44790dd3fc6fe42bb502d79c39c4081c223bf2b1 Bug: T212944 Change-Id: I86efb7be1c39b03f63c8f1e0b107216cd30ff6de
73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
( function ( M, track, config, trackSubscribe, user, experiments ) {
|
|
module.exports = function () {
|
|
/**
|
|
* Handle an error and log it if necessary
|
|
* @param {string} errorMessage to be logged
|
|
* @param {number} [lineNumber] of error
|
|
* @param {number} [columnNumber] of error
|
|
* @param {string} [errorUrl] to be logged
|
|
*/
|
|
function handleError( errorMessage, lineNumber, columnNumber, errorUrl ) {
|
|
var suffix,
|
|
errorSamplingRate = config.get( 'wgMinervaErrorLogSamplingRate', 0 ),
|
|
sessionToken = user.sessionId(),
|
|
EVENT_CLIENT_ERROR_LOG = 'wikimedia.event.WebClientError',
|
|
mobile = M.require( 'mobile.startup' ),
|
|
currentPage = mobile.currentPage(),
|
|
util = mobile.util,
|
|
errorExperiment = {
|
|
name: 'WebClientError',
|
|
enabled: errorSamplingRate > 0,
|
|
buckets: {
|
|
on: errorSamplingRate,
|
|
off: 1 - errorSamplingRate
|
|
}
|
|
},
|
|
isErrorLoggingEnabled = experiments.getBucket( errorExperiment, sessionToken ) === 'on',
|
|
DEFAULT_ERROR_DATA = {
|
|
sessionToken: sessionToken,
|
|
skin: config.get( 'skin' ),
|
|
wgVersion: config.get( 'wgVersion' ),
|
|
mobileMode: config.get( 'wgMFMode', 'desktop' ),
|
|
isAnon: user.isAnon(),
|
|
revision: currentPage.getRevisionId()
|
|
};
|
|
|
|
if ( isErrorLoggingEnabled ) {
|
|
track( EVENT_CLIENT_ERROR_LOG,
|
|
util.extend( {
|
|
userUrl: window.location.href,
|
|
errorUrl: errorUrl,
|
|
errorMessage: errorMessage,
|
|
// Due to concerns for the length of the stack trace and going over the
|
|
// limit for URI length this is currently set to empty string.
|
|
errorStackTrace: '',
|
|
errorLineNumber: lineNumber || 0,
|
|
errorColumnNumber: columnNumber || 0
|
|
}, DEFAULT_ERROR_DATA )
|
|
);
|
|
}
|
|
if ( config.get( 'wgMinervaCountErrors' ) ) {
|
|
suffix = user.isAnon() ? '.anon' : '.loggedin';
|
|
mw.track( 'counter.MediaWiki.minerva.WebClientError' + suffix, 1 );
|
|
}
|
|
}
|
|
// track RL exceptions
|
|
trackSubscribe( 'resourceloader.exception', function ( topic, data ) {
|
|
var error = data.exception;
|
|
handleError( error.message, error.lineNumber, error.columnNumber );
|
|
} );
|
|
// setup the global error handler
|
|
trackSubscribe( 'global.error', function ( topic, error ) {
|
|
handleError( error.errorMessage, error.lineNumber, error.columnNumber, error.url );
|
|
} );
|
|
};
|
|
}(
|
|
mw.mobileFrontend,
|
|
mw.track,
|
|
mw.config,
|
|
mw.trackSubscribe,
|
|
mw.user,
|
|
mw.experiments
|
|
) );
|