From fa37f572c941d385606699cc81b28f6e66ee7e25 Mon Sep 17 00:00:00 2001 From: Garrett Campbell Date: Wed, 8 Mar 2023 12:31:38 -0500 Subject: [PATCH 1/3] add logger message for if the serial monitor api was not retreived --- src/serialmonitor/serialMonitor.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/serialmonitor/serialMonitor.ts b/src/serialmonitor/serialMonitor.ts index 2dc847b4..0cf5111a 100644 --- a/src/serialmonitor/serialMonitor.ts +++ b/src/serialmonitor/serialMonitor.ts @@ -61,6 +61,10 @@ export class SerialMonitor implements vscode.Disposable { }); this.serialMonitorApi = await getSerialMonitorApi(Version.latest, extensionContext); + + if (this.serialMonitorApi === undefined) { + Logger.error("Serial Monitor API was not retrieved. You may not have the most recent version of the Serial Monitor extension installed.") + } } public get initialized(): boolean { From 1e9eb8fc60c9f04df71d742fdf515f91570af202 Mon Sep 17 00:00:00 2001 From: Garrett Campbell Date: Wed, 8 Mar 2023 12:36:09 -0500 Subject: [PATCH 2/3] add checks for undefined serial monitor api --- src/serialmonitor/serialMonitor.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/serialmonitor/serialMonitor.ts b/src/serialmonitor/serialMonitor.ts index 0cf5111a..6d5c5728 100644 --- a/src/serialmonitor/serialMonitor.ts +++ b/src/serialmonitor/serialMonitor.ts @@ -62,9 +62,7 @@ export class SerialMonitor implements vscode.Disposable { this.serialMonitorApi = await getSerialMonitorApi(Version.latest, extensionContext); - if (this.serialMonitorApi === undefined) { - Logger.error("Serial Monitor API was not retrieved. You may not have the most recent version of the Serial Monitor extension installed.") - } + this.checkForUndefinedSerialMonitorApi(); } public get initialized(): boolean { @@ -72,6 +70,8 @@ export class SerialMonitor implements vscode.Disposable { } public async selectSerialPort(): Promise { + this.checkForUndefinedSerialMonitorApi(true); + const ports = await this.serialMonitorApi.listAvailablePorts(); if (!ports.length) { vscode.window.showInformationMessage("No serial port is available."); @@ -117,6 +117,8 @@ export class SerialMonitor implements vscode.Disposable { } public async openSerialMonitor(restore: boolean = false): Promise { + this.checkForUndefinedSerialMonitorApi(true); + if (!this.currentPort) { const ans = await vscode.window.showInformationMessage("No serial port was selected, please select a serial port first", "Select", "Cancel"); if (ans === "Select") { @@ -155,6 +157,8 @@ export class SerialMonitor implements vscode.Disposable { } public async closeSerialMonitor(port?: string): Promise { + this.checkForUndefinedSerialMonitorApi(true); + const portToClose = port ?? this.currentPort; let closed = false; if (portToClose) { @@ -169,6 +173,16 @@ export class SerialMonitor implements vscode.Disposable { this.serialMonitorApi.dispose(); } + private checkForUndefinedSerialMonitorApi(showError: boolean = false): void { + const errorString = "Serial Monitor API was not retrieved. You may not have the most recent version of the Serial Monitor extension installed."; + if (this.serialMonitorApi === undefined) { + Logger.error(errorString) + if (showError) { + vscode.window.showErrorMessage(errorString); + } + } + } + private updatePortListStatus(port?: string) { const dc = DeviceContext.getInstance(); if (port) { From 832bafb80f1e14f9013408941aa97cfc7eea2834 Mon Sep 17 00:00:00 2001 From: Garrett Campbell Date: Wed, 8 Mar 2023 13:54:30 -0500 Subject: [PATCH 3/3] update error --- src/serialmonitor/serialMonitor.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/serialmonitor/serialMonitor.ts b/src/serialmonitor/serialMonitor.ts index 6d5c5728..64f2ecb1 100644 --- a/src/serialmonitor/serialMonitor.ts +++ b/src/serialmonitor/serialMonitor.ts @@ -176,9 +176,10 @@ export class SerialMonitor implements vscode.Disposable { private checkForUndefinedSerialMonitorApi(showError: boolean = false): void { const errorString = "Serial Monitor API was not retrieved. You may not have the most recent version of the Serial Monitor extension installed."; if (this.serialMonitorApi === undefined) { - Logger.error(errorString) if (showError) { - vscode.window.showErrorMessage(errorString); + Logger.notifyUserError("UndefinedSerialMonitorApi", new Error(errorString)); + } else { + Logger.traceError("UndefinedSerialMonitorApi", new Error(errorString)); } } }