Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 78209ee

Browse files
Merge pull request #1618 from microsoft/dev/gcampbell/OutputLoggerMessage
Add helpful error messages related to serial monitor api
2 parents 5f2cf62 + 832bafb commit 78209ee

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/serialmonitor/serialMonitor.ts

+19
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ export class SerialMonitor implements vscode.Disposable {
6161
});
6262

6363
this.serialMonitorApi = await getSerialMonitorApi(Version.latest, extensionContext);
64+
65+
this.checkForUndefinedSerialMonitorApi();
6466
}
6567

6668
public get initialized(): boolean {
6769
return !!this.extensionContext;
6870
}
6971

7072
public async selectSerialPort(): Promise<string | undefined> {
73+
this.checkForUndefinedSerialMonitorApi(true);
74+
7175
const ports = await this.serialMonitorApi.listAvailablePorts();
7276
if (!ports.length) {
7377
vscode.window.showInformationMessage("No serial port is available.");
@@ -113,6 +117,8 @@ export class SerialMonitor implements vscode.Disposable {
113117
}
114118

115119
public async openSerialMonitor(restore: boolean = false): Promise<void> {
120+
this.checkForUndefinedSerialMonitorApi(true);
121+
116122
if (!this.currentPort) {
117123
const ans = await vscode.window.showInformationMessage("No serial port was selected, please select a serial port first", "Select", "Cancel");
118124
if (ans === "Select") {
@@ -151,6 +157,8 @@ export class SerialMonitor implements vscode.Disposable {
151157
}
152158

153159
public async closeSerialMonitor(port?: string): Promise<boolean> {
160+
this.checkForUndefinedSerialMonitorApi(true);
161+
154162
const portToClose = port ?? this.currentPort;
155163
let closed = false;
156164
if (portToClose) {
@@ -165,6 +173,17 @@ export class SerialMonitor implements vscode.Disposable {
165173
this.serialMonitorApi.dispose();
166174
}
167175

176+
private checkForUndefinedSerialMonitorApi(showError: boolean = false): void {
177+
const errorString = "Serial Monitor API was not retrieved. You may not have the most recent version of the Serial Monitor extension installed.";
178+
if (this.serialMonitorApi === undefined) {
179+
if (showError) {
180+
Logger.notifyUserError("UndefinedSerialMonitorApi", new Error(errorString));
181+
} else {
182+
Logger.traceError("UndefinedSerialMonitorApi", new Error(errorString));
183+
}
184+
}
185+
}
186+
168187
private updatePortListStatus(port?: string) {
169188
const dc = DeviceContext.getInstance();
170189
if (port) {

0 commit comments

Comments
 (0)