Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
update based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Barosan committed Mar 5, 2019
1 parent c7de2a6 commit 37e4203
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class Delve {
logError('Process exiting with code: ' + code);
if (this.onclose) { this.onclose(code); }
});
this.debugProcess.on('error', function(err) {
this.debugProcess.on('error', function (err) {
reject(err);
});
resolve();
Expand Down Expand Up @@ -465,7 +465,7 @@ class Delve {
logError('Process exiting with code: ' + code);
if (this.onclose) { this.onclose(code); }
});
this.debugProcess.on('error', function(err) {
this.debugProcess.on('error', function (err) {
reject(err);
});
});
Expand Down Expand Up @@ -504,45 +504,44 @@ class Delve {
log('HaltRequest');

return new Promise(async resolve => {
const timeoutToken: NodeJS.Timer = this.debugProcess && setTimeout(() => {
log('Killing debug process manually as we could not halt and detach delve in time');
const timeoutToken: NodeJS.Timer = !this.isRemoteDebugging() && setTimeout(() => {
log('Killing debug process manually as we could not halt delve in time');
killTree(this.debugProcess.pid);
resolve();
}, 1000);

let errMsg;
try {
await this.callPromise('Command', [{ name: 'halt' }]);
}
catch (err) {
const errMsg = err ? err.toString() : '';
} catch (err) {
log('HaltResponse');
errMsg = err ? err.toString() : '';
log(`Failed to halt - ${errMsg}`);
}
clearTimeout(timeoutToken);

log('HaltResponse');
if (this.debugProcess) {
if (this.shouldDetach(errMsg)) {
log('DetachRequest');
try {
await this.callPromise('Detach', [this.isApiV1 ? true : { Kill: true }]);
clearTimeout(timeoutToken);
}
catch (err) {
} catch (err) {
log('DetachResponse');
logError(`The timeout will kill the debug process manually as we failed to detach - ${(err.toString() || '')}`);
}
return resolve();
} else {
log('RestartRequest');
try {
await this.callPromise('Restart', this.isApiV1 ? [] : [{ position: '', resetArgs: false, newArgs: [] }]);
}
catch (err) {
log('RestartResponse');
logError(`Failed to restart - ${(err || '').toString()}`);
}
return resolve();
}
return resolve();
});
}

private isRemoteDebugging() {
return !this.debugProcess;
}
private targetHasExited(errMsg: string) {
return errMsg.endsWith('has exited with status 0');
}
private shouldDetach(errMsg: string) {
return !errMsg || this.targetHasExited(errMsg);
}
}

class GoDebugSession extends LoggingDebugSession {
Expand Down

0 comments on commit 37e4203

Please sign in to comment.