From f9777016a7cbc849c1f1537824bdf5ad94428847 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 9 Jan 2023 16:14:33 +0000 Subject: [PATCH] Acknowledge that telemetryListener may be undefined --- extensions/ql-vscode/src/commandRunner.ts | 4 ++-- extensions/ql-vscode/src/telemetry.ts | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/extensions/ql-vscode/src/commandRunner.ts b/extensions/ql-vscode/src/commandRunner.ts index 8b9fa1013..c2eb180c8 100644 --- a/extensions/ql-vscode/src/commandRunner.ts +++ b/extensions/ql-vscode/src/commandRunner.ts @@ -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( return undefined; } finally { const executionTime = Date.now() - startTime; - telemetryListener.sendCommandUsage(commandId, executionTime, error); + telemetryListener?.sendCommandUsage(commandId, executionTime, error); } }); } diff --git a/extensions/ql-vscode/src/telemetry.ts b/extensions/ql-vscode/src/telemetry.ts index 0b86eb15a..5d1bc5a45 100644 --- a/extensions/ql-vscode/src/telemetry.ts +++ b/extensions/ql-vscode/src/telemetry.ts @@ -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, ctx: ExtensionContext, ): Promise { + if (telemetryListener !== undefined) { + throw new Error("Telemetry is already initialized"); + } telemetryListener = new TelemetryListener( extension.id, extension.packageJSON.version,