microsoft / vscode-debugadapter-node

Debug adapter protocol and implementation for VS Code.
Other
271 stars 77 forks source link

fix: sendError() doesn't throw an error anymore when no format is specified #274

Open joss-enet opened 1 year ago

joss-enet commented 1 year ago

As an example, the following code would send an error:

class CustomDebugSession extends DebugSession {
  protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void {
    this.sendErrorResponse(response, 100);
  }
}

The error in question: Uncaught Error Error: TypeError: Cannot read properties of undefined (reading 'replace')

This is due to the method sendErrorResponse() calling formatPII() even though no format is passed to the former. The solution adopted was to assign an empty string as the format if none was passed as an argument. Another solution could be to make the format argument mandatory.

connor4312 commented 1 year ago

DAP specifies the format is required. So I think the method signature should change to be an overload:

protected sendErrorResponse(response: DebugProtocol.Response, message: DebugProtocol.Message)
protected sendErrorResponse(response: DebugProtocol.Response, code: number, format: string, variables?: Record<string, any>, dest: ErrorDestination = ErrorDestination.User)
protected sendErrorResponse(response: DebugProtocol.Response, codeOrMessage: number | DebugProtocol.Message, format?: string, variables?: any, dest: ErrorDestination = ErrorDestination.User) {
...
}

thoughts @roblourens?

roblourens commented 1 year ago

Agree