Don't send 'terminated' on 'disconnect' (arduino/arduino-pro-ide#183)

This commit is contained in:
Miro Spönemann 2020-01-22 13:43:56 +01:00
parent 576f96a502
commit 828379cdc9
2 changed files with 7 additions and 5 deletions

View File

@ -40,6 +40,8 @@ export abstract class AbstractServer extends EventEmitter {
protected launchReject?: (error: any) => void;
protected timer?: NodeJS.Timer;
serverErrorEmitted = false;
get isRunning(): boolean {
return !!this.process && !this.process.killed;
}
@ -98,7 +100,7 @@ export abstract class AbstractServer extends EventEmitter {
this.emit('exit', code, signal);
// Code can be undefined, null or 0 and we want to ignore those values
if (!!code) {
if (!!code && !this.serverErrorEmitted) {
this.emit('error', `GDB server stopped unexpectedly with exit code ${code}`);
}
}
@ -141,6 +143,7 @@ export abstract class AbstractServer extends EventEmitter {
if (this.serverError(data)) {
this.emit('error', data.split(EOL)[0]);
this.serverErrorEmitted = true;
}
}

View File

@ -208,9 +208,6 @@ export class CmsisDebugSession extends GDBDebugSession {
protected async disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): Promise<void> {
try {
this.stopSession();
if (!args || !args.restart) {
this.sendEvent(new TerminatedEvent());
}
this.sendResponse(response);
} catch (err) {
this.sendErrorResponse(response, 1, err.message);
@ -294,7 +291,9 @@ export class CmsisDebugSession extends GDBDebugSession {
this.gdbServer.removeListener('error', gdbServerErrorAccumulator);
this.gdbServer.on('error', message => {
logger.error(JSON.stringify(message));
this.sendEvent(new TerminatedEvent());
if (!this.gdbServer.serverErrorEmitted) {
this.sendEvent(new TerminatedEvent());
}
});
}