Skip to content

Commit aea1f71

Browse files
committed
fix: add try catch for loading
1 parent 7850337 commit aea1f71

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,24 @@ export class LoggingAndTelemetry implements MongoshLoggingAndTelemetry {
137137

138138
private async setupTelemetry(): Promise<void> {
139139
if (!this.deviceId) {
140-
// eslint-disable-next-line @typescript-eslint/no-var-requires
141-
const getMachineId = require('native-machine-id').getMachineId;
142-
this.deviceId = await getDeviceId({
143-
getMachineId: () => getMachineId({ raw: true }),
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,
152-
});
140+
try {
141+
// eslint-disable-next-line @typescript-eslint/no-var-requires
142+
const getMachineId = require('native-machine-id').getMachineId;
143+
this.deviceId = await getDeviceId({
144+
getMachineId: () => getMachineId({ raw: true }),
145+
onError: (reason, error) => {
146+
if (reason === 'abort') {
147+
return;
148+
}
149+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
150+
this.bus.emit('mongosh:error', error, 'telemetry');
151+
},
152+
abortSignal: this.telemetrySetupAbort.signal,
153+
});
154+
} catch (error) {
155+
this.deviceId = 'unknown';
156+
this.bus.emit('mongosh:error', error as Error, 'telemetry');
157+
}
153158
}
154159

155160
this.runAndClearPendingTelemetryEvents();

0 commit comments

Comments
 (0)