Skip to content

Error handler unable to intercept and suppress error notification #1608

Description

@rcjsuen

let handlerResult: CloseHandlerResult = { action: CloseAction.DoNotRestart };
if (this.$state !== ClientState.Stopping) {
try {
handlerResult = await this._clientOptions.errorHandler!.closed();
} catch (error) {
// Ignore errors coming from the error handler.
}
}
this._connection = undefined;
if (handlerResult.action === CloseAction.DoNotRestart) {
this.error(handlerResult.message ?? 'Connection to server got closed. Server will not be restarted.', undefined, handlerResult.handled === true ? false : 'force');

I am developing a language server with an external dependency so I want to start/stop it myself. Unfortunately, if the dependency goes missing then the "Connection to server got closed. Server will not be restarted." message will appear if this.$state === ClientState.Stopping because I can't use the this._clientOptions.errorHandler to try to suppress it. Now when the dependency comes back the language server will restart even though the notification claimed that it "will not be restarted".

Essentially, I do not want the vscode-languageclient to popup any errors about the server being dead because I want to control everything myself but I can't avoid this particular notification (there may be others I have not encountered yet...?) because of this if statement.

Activity

  1. dbaeumer commented on Feb 5, 2025

    @dbaeumer
    Member

    Changing this might be a surprise for users that hook their own error handler. One idea would be to hide this behind a flag.

  2. added
    help wantedIssues identified as good community contribution opportunities
    feature-requestRequest for new features or functionality
    on Feb 5, 2025
  3. dbaeumer commented on Feb 5, 2025

    @dbaeumer
    Member

    PR as always welcome.

  4. rcjsuen commented on Feb 6, 2025

    @rcjsuen
    ContributorAuthor

    Changing this might be a surprise for users that hook their own error handler. One idea would be to hide this behind a flag.

    Hi Dirk Bäumer (@dbaeumer), for my clarity, could you rephrase what you mean by "hide this behind a flag"? Did you just mean adding adding a new boolean property to LanguageClientOptions in client/src/common/client.ts to control the new behaviour?

  5. dbaeumer commented on Feb 10, 2025

    @dbaeumer
    Member

    Did you just mean adding adding a new boolean property to LanguageClientOptions in client/src/common/client.ts to control the new behaviour?

    Yes, that is exactly what I had in mind.

  6. noeldevelops commented on May 16, 2025

    @noeldevelops

    We are also encountering this issue in implementing a language client for our extension.

    Our language server connects over websocket and we expect occasional closures, which we handle & then reconnect. But it seems we cannot prevent the error message notification that says "Restarting server failed", even though our server restarts ok in the background and is continuing to provide intellisense in the editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestRequest for new features or functionalityhelp wantedIssues identified as good community contribution opportunities

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions