The following implementation:
|
public send(command: string, args?: any): Promise<DebugProtocol.Response> { |
|
|
|
return new Promise((completeDispatch, errorDispatch) => { |
|
this.doSend(command, args, (result: DebugProtocol.Response) => { |
|
if (result.success) { |
|
completeDispatch(result); |
|
} else { |
|
errorDispatch(new Error(result.message)); |
|
} |
|
}); |
|
}); |
|
} |
is not async itself and returns the promise immediately without awaiting it. Consequently, if the promise gets rejected with an error, the stack trace in the error does not include either
send or its caller. This unnecessarily complicates debugging of e.g. async unit tests that
await send() and receive an unexpected error response.
Instead, the callback for doSend should capture the raw response in a wrapper promise, and then send should await that promise and translate it to a throw.
The following implementation:
vscode-debugadapter-node/testSupport/src/protocolClient.ts
Lines 69 to 80 in 1621133
is not async itself and returns the promise immediately without awaiting it. Consequently, if the promise gets rejected with an error, the stack trace in the error does not include either
sendor its caller. This unnecessarily complicates debugging of e.g. async unit tests thatawait send()and receive an unexpected error response.Instead, the callback for
doSendshould capture the raw response in a wrapper promise, and thensendshould await that promise and translate it to athrow.