Acknowledge that telemetryListener may be undefined

This commit is contained in:
Robert 2023-01-09 16:14:33 +00:00
Родитель 8346eda8b8
Коммит f9777016a7
2 изменённых файлов: 6 добавлений и 3 удалений

Просмотреть файл

@ -147,7 +147,7 @@ export function commandRunner(
return undefined;
} finally {
const executionTime = Date.now() - startTime;
telemetryListener.sendCommandUsage(commandId, executionTime, error);
telemetryListener?.sendCommandUsage(commandId, executionTime, error);
}
});
}
@ -201,7 +201,7 @@ export function commandRunnerWithProgress<R>(
return undefined;
} finally {
const executionTime = Date.now() - startTime;
telemetryListener.sendCommandUsage(commandId, executionTime, error);
telemetryListener?.sendCommandUsage(commandId, executionTime, error);
}
});
}

Просмотреть файл

@ -227,12 +227,15 @@ export class TelemetryListener extends ConfigListener {
/**
* The global Telemetry instance
*/
export let telemetryListener: TelemetryListener;
export let telemetryListener: TelemetryListener | undefined;
export async function initializeTelemetry(
extension: Extension<any>,
ctx: ExtensionContext,
): Promise<void> {
if (telemetryListener !== undefined) {
throw new Error("Telemetry is already initialized");
}
telemetryListener = new TelemetryListener(
extension.id,
extension.packageJSON.version,