mediawiki-skins-MinervaNeue/resources/skins.minerva.scripts/errorLogging.js

74 lines
2.4 KiB
JavaScript
Raw Normal View History

( 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',
Make Minerva use new PageHTMLParser.js and refactored Page.js In I02f8645aac1d7b081eaba8f2ac92a2ef51f78182, Page.js was made into a model and its html parsing responsibilities were moved to PageHTMLParser. Additionally, a singleton for the current page (currentPage.js) and a singleton for the curent page html parser (currentPageHTMLParser.js) were introduced to replace the usage of M.getCurrentPage(). This commit refactors Minerva to make use of these changes. Notable changes: * 🐛 The event bus singleton was added to references.js since it previously relied on an instance of Skin to listen for the `references-loaded` event. However, this event is emitted on the event bus singleton. * Additionally, I didn't see a reason why the `references-loaded` event needed to also pass the current page instance when the only file listening to it is references.js (which already has the current page instance) so I removed that and the convoluted passing of page.js within the file. I assumed this logic was unecessary. * The call to drawer.showReferences in references.js now was made to pass the currentPage instance as well as the currentPageHTMLParser. This is to prepare for I6e858bbe73f83166476b5b2c0fdac1cca7404246 where the getReferences() interface for ReferencesMobileViewGateway.js and ReferencesHtmlScraperGateway.js is refactored to accept both of these instances. Additionally, references.js was refactored to support event delegation which gets rid of some parsing/setup logic. Bug: T193077 Depends-On: I02f8645aac1d7b081eaba8f2ac92a2ef51f78182 Change-Id: I2f32dbcc4ebaa4bebb297cda1ecce3457922b343
2019-07-11 00:56:04 +00:00
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(),
Make Minerva use new PageHTMLParser.js and refactored Page.js In I02f8645aac1d7b081eaba8f2ac92a2ef51f78182, Page.js was made into a model and its html parsing responsibilities were moved to PageHTMLParser. Additionally, a singleton for the current page (currentPage.js) and a singleton for the curent page html parser (currentPageHTMLParser.js) were introduced to replace the usage of M.getCurrentPage(). This commit refactors Minerva to make use of these changes. Notable changes: * 🐛 The event bus singleton was added to references.js since it previously relied on an instance of Skin to listen for the `references-loaded` event. However, this event is emitted on the event bus singleton. * Additionally, I didn't see a reason why the `references-loaded` event needed to also pass the current page instance when the only file listening to it is references.js (which already has the current page instance) so I removed that and the convoluted passing of page.js within the file. I assumed this logic was unecessary. * The call to drawer.showReferences in references.js now was made to pass the currentPage instance as well as the currentPageHTMLParser. This is to prepare for I6e858bbe73f83166476b5b2c0fdac1cca7404246 where the getReferences() interface for ReferencesMobileViewGateway.js and ReferencesHtmlScraperGateway.js is refactored to accept both of these instances. Additionally, references.js was refactored to support event delegation which gets rid of some parsing/setup logic. Bug: T193077 Depends-On: I02f8645aac1d7b081eaba8f2ac92a2ef51f78182 Change-Id: I2f32dbcc4ebaa4bebb297cda1ecce3457922b343
2019-07-11 00:56:04 +00:00
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 );
} );
};
}(
// eslint-disable-next-line no-restricted-properties
mw.mobileFrontend,
mw.track,
mw.config,
mw.trackSubscribe,
mw.user,
mw.experiments
) );