2018-08-24 00:34:37 +00:00
|
|
|
( function ( M, requestIdleCallback, track, config, trackSubscribe, user, experiments ) {
|
|
|
|
requestIdleCallback( 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 ) {
|
2019-02-22 22:15:53 +00:00
|
|
|
var suffix,
|
|
|
|
errorSamplingRate = config.get( 'wgMinervaErrorLogSamplingRate', 0 ),
|
2018-08-24 00:34:37 +00:00
|
|
|
sessionToken = user.sessionId(),
|
|
|
|
EVENT_CLIENT_ERROR_LOG = 'wikimedia.event.WebClientError',
|
|
|
|
page = M.getCurrentPage(),
|
2019-02-07 16:34:18 +00:00
|
|
|
util = M.require( 'mobile.startup' ).util,
|
2018-08-24 00:34:37 +00:00
|
|
|
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: page.getRevisionId()
|
|
|
|
};
|
2019-02-11 18:11:16 +00:00
|
|
|
|
2018-08-24 00:34:37 +00:00
|
|
|
if ( isErrorLoggingEnabled ) {
|
|
|
|
track( EVENT_CLIENT_ERROR_LOG,
|
|
|
|
util.extend( {
|
|
|
|
userUrl: window.location.href,
|
|
|
|
errorUrl: errorUrl,
|
|
|
|
errorMessage: errorMessage,
|
2018-09-13 15:33:20 +00:00
|
|
|
// 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.
|
2018-08-24 00:34:37 +00:00
|
|
|
errorStackTrace: '',
|
|
|
|
errorLineNumber: lineNumber || 0,
|
|
|
|
errorColumnNumber: columnNumber || 0
|
|
|
|
}, DEFAULT_ERROR_DATA )
|
|
|
|
);
|
|
|
|
}
|
2019-02-11 18:11:16 +00:00
|
|
|
if ( config.get( 'wgMinervaCountErrors' ) ) {
|
2019-02-22 22:15:53 +00:00
|
|
|
suffix = user.isAnon() ? '.anon' : '.loggedin';
|
|
|
|
mw.track( 'counter.MediaWiki.minerva.WebClientError' + suffix, 1 );
|
2018-10-04 21:31:30 +00:00
|
|
|
}
|
2018-08-24 00:34:37 +00:00
|
|
|
}
|
|
|
|
// track RL exceptions
|
|
|
|
trackSubscribe( 'resourceloader.exception', function ( topic, data ) {
|
2018-09-06 20:45:43 +00:00
|
|
|
var error = data.exception;
|
|
|
|
handleError( error.message, error.lineNumber, error.columnNumber );
|
2018-08-24 00:34:37 +00:00
|
|
|
} );
|
|
|
|
// setup the global error handler
|
|
|
|
trackSubscribe( 'global.error', function ( topic, error ) {
|
|
|
|
handleError( error.errorMessage, error.lineNumber, error.columnNumber, error.url );
|
|
|
|
} );
|
|
|
|
} );
|
2018-09-13 15:33:20 +00:00
|
|
|
}(
|
|
|
|
mw.mobileFrontend,
|
|
|
|
mw.requestIdleCallback,
|
|
|
|
mw.track,
|
|
|
|
mw.config,
|
|
|
|
mw.trackSubscribe,
|
|
|
|
mw.user,
|
|
|
|
mw.experiments
|
|
|
|
) );
|