microsoft / vscode-languageserver-node

Language server protocol implementation for VSCode. This allows implementing language services in JS/TS running on node.js
MIT License
1.41k stars 319 forks source link

How to handle cancelled `window/showMessageRequest` #1501

Open abhi40308 opened 1 week ago

abhi40308 commented 1 week ago

We have sentry enabled on our language-server code and its capturing an unhandled error:

Request window/showMessageRequest failed with message: Canceled
Stack Trace Screenshot 2024-06-25 at 5 28 49 PM

There are a lot of instances of this unhandled exception (as its almost always being thrown on initialisation) on sentry and we would like to handle and resolve this properly.

I have traced the request to a notification message we send from the server on connection.onDidChangeConfiguration (which also gets called on connection initialisation), using connection.window.showInformationMessage('some_message')

This is the trace on output console:

[Trace - 17:42:52] Received request 'window/showMessageRequest - (8)'.
Params: {
    "type": 3,
    "message": "DDN CLI path configured successfully.",
    "actions": []
}

I could not see any other trace with a cancelled window/showMessageRequest request. This is the only showMessageRequest that is visible in the VSCode Output channel.

I've tried to wrap the request in a try...catch but with no success, the error still bubbles up on sentry as unhandled :

     try {
        connection.window.showInformationMessage('some_message')
      } catch (err) {
        console.error(err);
      }

From stacktrace it seems like coming from the vscode-jsonrpc package, which is rejecting the promise with error. I guess some handler needs to be installed on the connection object to handle the cancelled request, but could find any resources where something similar is done. Also could not understand from the error message that who is cancelling the request, is it the client or the server.

Any help would be greatly appreciated 🙏. Thanks.

Version: "vscode-languageserver": "7.0.0"

dbaeumer commented 1 week ago

"vscode-languageserver": "7.0.0" is a fairly old version. Are you seeing the same behavior on the latest released version 9.0.1 together with the latest client.

And does this happen with VS Code as the client or another editor?