Skip to content

Commit

Permalink
Check if error data is present before using it (#2293)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Jul 11, 2024
1 parent acc460d commit 37ec812
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
46 changes: 23 additions & 23 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,29 +339,29 @@ export default class Client extends LanguageClient implements ClientInterface {
await vscode.window.showErrorMessage(
`Ruby LSP error ${error.data.errorClass}: ${error.data.errorMessage}\n\n${error.data.backtrace}`,
);
} else if (
error.data.errorMessage &&
error.data.errorClass &&
error.data.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(
error.data.backtrace
.split("\n")
.map((line: string) => line.replace(os.homedir(), "~"))
.join("\n"),
) as any;

this.telemetry.logError(
{
message: error.data.errorMessage,
name: error.data.errorClass,
stack,
},
{ ...error.data, serverVersion: this.serverVersion },
);
} 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 },
);
}
}

throw error;
Expand Down
2 changes: 2 additions & 0 deletions vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export async function activate(context: vscode.ExtensionContext) {
}

const logger = await createLogger(context);
context.subscriptions.push(logger);

extension = new RubyLsp(context, logger);
await extension.activate();
}
Expand Down

0 comments on commit 37ec812

Please sign in to comment.