From 9338e496c0ccc34a7b59f8914a12504b547eecec Mon Sep 17 00:00:00 2001 From: Prateek Srivastava Date: Thu, 17 May 2018 10:03:55 -0700 Subject: [PATCH] Don't swallow integration errors Same as https://github.com/segmentio/analytics.js-integration/pull/60 but for 2.x. As part of adding client side metrics, we want to propagate errors to analytics.js-core so that it can capture them. https://paper.dropbox.com/doc/Analytics.js-Metrics-SDD-1hAD90lqGS4aZxHAHYPu7#:h2=analytics.js-integration analytics.js-core has already been updated to capture errors when invoking integrations (segmentio/analytics.js-core#66). --- lib/protos.js | 11 ++--------- test/index.test.js | 6 ++++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/protos.js b/lib/protos.js index 2fdd5b4..12c885b 100644 --- a/lib/protos.js +++ b/lib/protos.js @@ -174,16 +174,9 @@ exports.invoke = function(method) { if (!this[method]) return; var args = Array.prototype.slice.call(arguments, 1); if (!this._ready) return this.queue(method, args); - var ret; - try { - this.debug('%s with %o', method, args); - ret = this[method].apply(this, args); - } catch (e) { - this.debug('error %o calling %s with %o', e, method, args); - } - - return ret; + this.debug('%s with %o', method, args); + return this[method].apply(this, args); }; /** diff --git a/test/index.test.js b/test/index.test.js index 42913ef..fcff17e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -299,10 +299,12 @@ describe('integration', function() { assert(integration.track.calledWith('event')); }); - it('should catch errors when it calls', function() { + it('should throw errors if the integration errors', function() { integration.emit('ready'); integration.initialize(); - integration.invoke('page', 'name'); + assert['throws'](function() { + integration.invoke('page', 'name'); + }, Error, 'Should not swallow exceptions'); }); it('should return the returned value', function(done) {