Skip to content

Commit 7850337

Browse files
committed
fix: don't log an error if aborting device ID resolution
1 parent 00b572c commit 7850337

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/logging/src/logging-and-telemetry.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class LoggingAndTelemetry implements MongoshLoggingAndTelemetry {
9696
/** @internal Used for awaiting the telemetry setup in tests. */
9797
public setupTelemetryPromise: Promise<void> = Promise.resolve();
9898

99-
private readonly telemetrySetup: AbortController = new AbortController();
99+
private readonly telemetrySetupAbort: AbortController = new AbortController();
100100

101101
constructor({
102102
bus,
@@ -132,7 +132,7 @@ export class LoggingAndTelemetry implements MongoshLoggingAndTelemetry {
132132

133133
// Abort setup, which will cause the device ID to be set to 'unknown'
134134
// and run any remaining telemetry events
135-
this.telemetrySetup.abort();
135+
this.telemetrySetupAbort.abort();
136136
}
137137

138138
private async setupTelemetry(): Promise<void> {
@@ -141,9 +141,14 @@ export class LoggingAndTelemetry implements MongoshLoggingAndTelemetry {
141141
const getMachineId = require('native-machine-id').getMachineId;
142142
this.deviceId = await getDeviceId({
143143
getMachineId: () => getMachineId({ raw: true }),
144-
onError: (_, error) =>
145-
this.bus.emit('mongosh:error', error, 'telemetry'),
146-
abortSignal: this.telemetrySetup.signal,
144+
onError: (reason, error) => {
145+
if (reason === 'abort') {
146+
return;
147+
}
148+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
149+
this.bus.emit('mongosh:error', error, 'telemetry');
150+
},
151+
abortSignal: this.telemetrySetupAbort.signal,
147152
});
148153
}
149154

0 commit comments

Comments
 (0)