Gergő Tisza has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/200834

Change subject: Record javascript errors to funnel log stream
......................................................................

Record javascript errors to funnel log stream

Records to UploadWizardExceptionFlowEvent schema.

Bug: T94428
Change-Id: I9f99763fec791b00957a3b217d83ee48bf21bb6d
---
M .jshintrc
M UploadWizard.php
M UploadWizardHooks.php
M resources/uw.EventFlowLogger.js
M tests/qunit/uw.EventFlowLogger.test.js
5 files changed, 72 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/34/200834/1

diff --git a/.jshintrc b/.jshintrc
index 4d3b65f..5747107 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -39,6 +39,7 @@
                "mw",
                "jQuery",
                "OO",
-               "QUnit"
+               "QUnit",
+               "sinon"
        ]
 }
diff --git a/UploadWizard.php b/UploadWizard.php
index 3f3e8ef..8b02a40 100644
--- a/UploadWizard.php
+++ b/UploadWizard.php
@@ -153,6 +153,7 @@
 $wgEventLoggingSchemas[ 'UploadWizardStep' ] = 8851805;
 $wgEventLoggingSchemas[ 'UploadWizardFlowEvent' ] = 11562780;
 $wgEventLoggingSchemas[ 'UploadWizardErrorFlowEvent' ] = 9924376;
+$wgEventLoggingSchemas[ 'UploadWizardExceptionFlowEvent' ] = 11717009;
 $wgEventLoggingSchemas[ 'UploadWizardUploadFlowEvent' ] = 9651951;
 
 // Campaign hook handlers
diff --git a/UploadWizardHooks.php b/UploadWizardHooks.php
index 5fe44fc..b7c5bde 100644
--- a/UploadWizardHooks.php
+++ b/UploadWizardHooks.php
@@ -755,6 +755,7 @@
                                'schema.UploadWizardStep',
                                'schema.UploadWizardFlowEvent',
                                'schema.UploadWizardErrorFlowEvent',
+                               'schema.UploadWizardExceptionFlowEvent',
                                'schema.UploadWizardUploadFlowEvent',
                        );
                }
diff --git a/resources/uw.EventFlowLogger.js b/resources/uw.EventFlowLogger.js
index 18e5d4b..5915330 100644
--- a/resources/uw.EventFlowLogger.js
+++ b/resources/uw.EventFlowLogger.js
@@ -109,6 +109,31 @@
        };
 
        /**
+        * Sets up logging for global javascript errors.
+        */
+       EFLP.installExceptionLogger = function () {
+               function toNumber( val ) {
+                       var num = parseInt( val, 10 );
+                       if ( isNaN( num ) ) {
+                               return undefined;
+                       }
+                       return num;
+               }
+
+               var self = this;
+
+               mw.trackSubscribe( 'global.error', function ( topic, data ) {
+                       self.log( 'UploadWizardExceptionFlowEvent', {
+                               message: data.errorMessage,
+                               url: data.url,
+                               line: toNumber( data.lineNumber ),
+                               column: toNumber( data.columnNumber ),
+                               stack: undefined // T91347
+                       } );
+               } );
+       };
+
+       /**
         * Logs an upload event.
         * @param {string} name Event name. Recognized names:
         *  - upload-started
@@ -138,4 +163,5 @@
 
        // FIXME
        uw.eventFlowLogger = new EventFlowLogger( mw.eventLog );
+       uw.eventFlowLogger.installExceptionLogger();
 }( mediaWiki, mediaWiki.uploadWizard ) );
diff --git a/tests/qunit/uw.EventFlowLogger.test.js 
b/tests/qunit/uw.EventFlowLogger.test.js
index 3ab1214..f5cface 100644
--- a/tests/qunit/uw.EventFlowLogger.test.js
+++ b/tests/qunit/uw.EventFlowLogger.test.js
@@ -27,4 +27,46 @@
                logger.logEvent( 'baz' );
                assert.ok( eventLog.logEvent.calledThrice, 'all steps were 
logged' );
        } );
+
+       QUnit.test( 'installExceptionLogger', 3, function () {
+               var eventLog = { logEvent: this.sandbox.stub() },
+                       logger = new uw.EventFlowLogger( eventLog );
+
+               this.sandbox.stub( mw, 'trackSubscribe' );
+
+               logger.installExceptionLogger();
+
+               sinon.assert.calledWith( mw.trackSubscribe, 'global.error', 
sinon.match.typeOf( 'function' ) );
+               mw.trackSubscribe.firstCall.args[1]( 'global.error', {
+                       errorMessage: 'Foo',
+                       url: 'http://example.com/bar.js',
+                       lineNumber: 123,
+                       columnNumber: '45',
+                       errorObject: { stack: 'foo() at bar.js#123' }
+               } );
+               sinon.assert.calledWith( eventLog.logEvent, 
'UploadWizardExceptionFlowEvent', {
+                       flowId: sinon.match.defined,
+                       message: 'Foo',
+                       url: 'http://example.com/bar.js',
+                       line: 123,
+                       column: 45,
+                       stack: undefined
+               } );
+               eventLog.logEvent.reset();
+               mw.trackSubscribe.firstCall.args[1]( 'global.error', {
+                       errorMessage: 'Foo',
+                       url: 'http://example.com/bar.js',
+                       lineNumber: undefined,
+                       columnNumber: null,
+                       errorObject: undefined
+               } );
+               sinon.assert.calledWith( eventLog.logEvent, 
'UploadWizardExceptionFlowEvent', {
+                       flowId: sinon.match.defined,
+                       message: 'Foo',
+                       url: 'http://example.com/bar.js',
+                       line: undefined,
+                       column: undefined,
+                       stack: undefined
+               } );
+       } );
 } ( mediaWiki, mediaWiki.uploadWizard ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/200834
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f99763fec791b00957a3b217d83ee48bf21bb6d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to