Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescue NonExistingDocumentError in base server #2331

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ruby_lsp/base_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def start

# We don't want to try to parse documents on text synchronization notifications
@store.get(parsed_uri).parse unless method.start_with?("textDocument/did")
rescue Errno::ENOENT
rescue Store::NonExistingDocumentError
# If we receive a request for a file that no longer exists, we don't want to fail
end
end
Expand Down
58 changes: 30 additions & 28 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,35 +338,37 @@ export default class Client extends LanguageClient implements ClientInterface {
this.logResponseTime(bench.duration, request);
return result;
} catch (error: any) {
if (
this.baseFolder === "ruby-lsp" ||
this.baseFolder === "ruby-lsp-rails"
) {
await vscode.window.showErrorMessage(
`Ruby LSP error ${error.data.errorClass}: ${error.data.errorMessage}\n\n${error.data.backtrace}`,
);
} else if (error.data) {
const { errorMessage, errorClass, backtrace } = error.data;

if (errorMessage && errorClass && backtrace) {
// Sanitize the backtrace coming from the server to remove the user's home directory from it, then mark it as
// a trusted value. Otherwise the VS Code telemetry logger redacts the entire backtrace and we are unable to
// see where in the server the error occurred
const stack = new vscode.TelemetryTrustedValue(
backtrace
.split("\n")
.map((line: string) => line.replace(os.homedir(), "~"))
.join("\n"),
) as any;

this.telemetry.logError(
{
message: errorMessage,
name: errorClass,
stack,
},
{ ...error.data, serverVersion: this.serverVersion },
if (error.data) {
if (
this.baseFolder === "ruby-lsp" ||
this.baseFolder === "ruby-lsp-rails"
) {
await vscode.window.showErrorMessage(
`Ruby LSP error ${error.data.errorClass}: ${error.data.errorMessage}\n\n${error.data.backtrace}`,
);
} else {
const { errorMessage, errorClass, backtrace } = error.data;

if (errorMessage && errorClass && backtrace) {
// Sanitize the backtrace coming from the server to remove the user's home directory from it, then mark it
// as a trusted value. Otherwise the VS Code telemetry logger redacts the entire backtrace and we are unable
// to see where in the server the error occurred
const stack = new vscode.TelemetryTrustedValue(
backtrace
.split("\n")
.map((line: string) => line.replace(os.homedir(), "~"))
.join("\n"),
) as any;

this.telemetry.logError(
{
message: errorMessage,
name: errorClass,
stack,
},
{ ...error.data, serverVersion: this.serverVersion },
);
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions vscode/src/test/suite/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,4 +692,20 @@ suite("Client", () => {
/lib\/ruby\/\d\.\d\.\d\/\*\*\/\*/,
);
});

test("requests for non existing documents do not crash the server", async () => {
await assert.rejects(
async () =>
client.sendRequest("textDocument/documentSymbol", {
textDocument: {
uri: documentUri.toString(),
},
}),
(error: any) => {
assert.strictEqual(error.data, null);
assert.strictEqual(error.code, -32602);
return true;
},
);
}).timeout(20000);
});
Loading