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

Commit 221614c

Browse files
authored
Merge pull request #66 from segmentio/catch-integration-errors
Catch and guard against Integration errors
2 parents 8153d2f + 1109064 commit 221614c

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)