Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 3ab777c

Browse files
committed
Catch and guard against Integration errors
To be able to record client side metrics, we need to modify analytics.js-integration to start propagate errors to analytics.js-core (https://paper.dropbox.com/doc/Analytics.js-Metrics-SDD-1hAD90lqGS4aZxHAHYPu7#:h2=analytics.js-integration) so that analytics.js-core can record metrics. Currently analytics.js-integration is responsible for guarding when an integration method throws an error. Before changing the behaviour in analytics.js-integration, we need to make sure analytics.js-core guards against errors in integrations.
1 parent 886693a commit 3ab777c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/analytics.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,11 @@ Analytics.prototype._invoke = function(method, facade) {
615615
if (failedInitializations.indexOf(name) >= 0) {
616616
self.log('Skipping invokation of .%s method of %s integration. Integation failed to initialize properly.', method, name);
617617
} else {
618-
integration.invoke.call(integration, method, facade);
618+
try {
619+
integration.invoke.call(integration, method, facade);
620+
} catch (e) {
621+
self.log('Error invoking .%s method of %s integration: %o', method, name, e);
622+
}
619623
}
620624
}, this._integrations);
621625

test/analytics.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ describe('Analytics', function() {
322322
assert(!Test.prototype.invoke.called);
323323
});
324324

325+
it('should not crash when invoking integration fails', function() {
326+
Test.prototype.invoke = function() { throw new Error('Uh oh!'); };
327+
analytics.track('Test Event');
328+
});
329+
325330
it('should support .integrations to disable / select integrations', function() {
326331
var opts = { integrations: { Test: false } };
327332
analytics.identify('123', {}, opts);

0 commit comments

Comments
 (0)