Skip to content

Commit 4948401

Browse files
committed
src/goDebugFactory.ts: send terminated event on server start error
If there was an error starting or connecting to the server, we need to send a terminated event and error to the client to ensure that the client knows there is no debug process running. Fixes #1413 Change-Id: I4aa5166fd126f5546bb43fb3ad563fc9f9ca93b7 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/309809 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent 6f9c0eb commit 4948401

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/goDebugFactory.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,19 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
173173
if (!this.connected) {
174174
this.connected = this.startAndConnectToServer();
175175
}
176-
await this.connected;
177-
super.sendMessageToServer(message);
176+
try {
177+
await this.connected;
178+
super.sendMessageToServer(message);
179+
} catch (err) {
180+
// If there was an error connecting, show an error message
181+
// and send a terminated event, since we cannot start.
182+
if (err) {
183+
const errMsg = `connect to server error: ${err}`;
184+
this.sendMessageToClient(new OutputEvent(errMsg));
185+
vscode.window.showErrorMessage(errMsg);
186+
}
187+
this.sendMessageToClient(new TerminatedEvent());
188+
}
178189
}
179190

180191
async dispose() {
@@ -185,6 +196,9 @@ export class DelveDAPOutputAdapter extends ProxyDebugAdapter {
185196
}
186197
this.connected = undefined;
187198
const dlvDapServer = this.dlvDapServer;
199+
if (!dlvDapServer) {
200+
return;
201+
}
188202
if (dlvDapServer.exitCode !== null) {
189203
console.log(`dlv dap process(${dlvDapServer.pid}) exited ${dlvDapServer.exitCode}`);
190204
return;

0 commit comments

Comments
 (0)