Skip to content

Commit b8d79c5

Browse files
authored
fix: analytics send failure error (#347)
Wrap analytics so failure to send doesn't trigger a failure.
1 parent 657bcc7 commit b8d79c5

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## UNRELEASED
44

5-
- Add your updates here :)
5+
- fix: analytics send failure error
66

77
## [14.0.0] 2023-12-16
88

docs/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## UNRELEASED
44

5-
- Add your updates here :)
5+
- fix: analytics send failure error
66

77
## [14.0.0] 2023-12-16
88

lib/analytics.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@ async function recordAnonymousEvent(eventType, data) {
2929
const linterEvent = buildLinterEvent(eventType, data);
3030
events.push(linterEvent);
3131
events.push(...(await buildFileStatsEvents(linterEvent, data)));
32-
const amplitudeProm = amplitudeClient.track(events);
33-
debug("Analytics sent: " + eventType + " " + JSON.stringify(events));
34-
return amplitudeProm;
32+
return (async resolve => {
33+
// Failing to send analytics isn't fatal.
34+
try {
35+
await amplitudeClient.track(events);
36+
debug(`Analytics sent type: ${eventType} ${JSON.stringify(events)}`);
37+
} catch (err) {
38+
debug(`Analytics send failed type: ${eventType} ${JSON.stringify(events)} ${err}`);
39+
} finally {
40+
resolve();
41+
}
42+
})();
3543
}
3644

3745
// Build payload for main linter event

0 commit comments

Comments
 (0)