Skip to content

Commit ad931b9

Browse files
authored
Suppress version manager environment errors from extension telemetry (#4003)
To avoid telemetry noise from user environment issues we convert all version manager throw sites to NonReportableError. These are cases where the tool is missing, misconfigured, or the workspace lacks expected files - none of which indicate Ruby LSP bugs. Covers: shadowenv, chruby, mise, rbenv, rvm, asdf, custom, and rv.
1 parent a2a7d90 commit ad931b9

8 files changed

Lines changed: 32 additions & 20 deletions

File tree

vscode/src/ruby/asdf.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from "path";
33

44
import * as vscode from "vscode";
55

6-
import { VersionManager, ActivationResult } from "./versionManager";
6+
import { VersionManager, ActivationResult, NonReportableError } from "./versionManager";
77

88
// A tool to manage multiple runtime versions with a single CLI tool
99
//
@@ -82,7 +82,9 @@ export class Asdf extends VersionManager {
8282
this.outputChannel.info(`Using configured ASDF executable path: ${asdfPath}`);
8383
return configuredPath.fsPath;
8484
} catch (_error: any) {
85-
throw new Error(`ASDF executable configured as ${configuredPath.fsPath}, but that file doesn't exist`);
85+
throw new NonReportableError(
86+
`ASDF executable configured as ${configuredPath.fsPath}, but that file doesn't exist`,
87+
);
8688
}
8789
}
8890
}

vscode/src/ruby/chruby.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import * as vscode from "vscode";
55

66
import { WorkspaceChannel } from "../workspaceChannel";
77

8-
import { ActivationResult, MissingRubyError, VersionManager, ACTIVATION_SEPARATOR } from "./versionManager";
8+
import {
9+
ActivationResult,
10+
MissingRubyError,
11+
NonReportableError,
12+
VersionManager,
13+
ACTIVATION_SEPARATOR,
14+
} from "./versionManager";
915

1016
interface RubyVersion {
1117
engine?: string;
@@ -248,13 +254,13 @@ export class Chruby extends VersionManager {
248254
}
249255

250256
if (version === "") {
251-
throw new Error(`Ruby version file ${rubyVersionUri.fsPath} is empty`);
257+
throw new NonReportableError(`Ruby version file ${rubyVersionUri.fsPath} is empty`);
252258
}
253259

254260
const match = /((?<engine>[A-Za-z]+)-)?(?<version>\d+\.\d+(\.\d+)?(-[A-Za-z0-9]+)?)/.exec(version);
255261

256262
if (!match?.groups) {
257-
throw new Error(
263+
throw new NonReportableError(
258264
`Ruby version file ${rubyVersionUri.fsPath} contains invalid format. Expected (engine-)?version, got ${version}`,
259265
);
260266
}
@@ -433,7 +439,7 @@ export class Chruby extends VersionManager {
433439
}
434440

435441
private rubyVersionError() {
436-
return new Error(
442+
return new NonReportableError(
437443
`Cannot find .ruby-version file. Please specify the Ruby version in a
438444
.ruby-version either in ${this.bundleUri.fsPath} or in a parent directory`,
439445
);

vscode/src/ruby/custom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
22

3-
import { VersionManager, ActivationResult } from "./versionManager";
3+
import { VersionManager, ActivationResult, NonReportableError } from "./versionManager";
44

55
// Custom
66
//
@@ -24,7 +24,7 @@ export class Custom extends VersionManager {
2424
const customCommand: string | undefined = configuration.get("customRubyCommand");
2525

2626
if (customCommand === undefined) {
27-
throw new Error(
27+
throw new NonReportableError(
2828
"The customRubyCommand configuration must be set when 'custom' is selected as the version manager. \
2929
See the [README](https://shopify.github.io/ruby-lsp/version-managers.html) for instructions.",
3030
);

vscode/src/ruby/mise.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from "os";
22

33
import * as vscode from "vscode";
44

5-
import { VersionManager, ActivationResult } from "./versionManager";
5+
import { VersionManager, ActivationResult, NonReportableError } from "./versionManager";
66

77
// Mise (mise en place) is a manager for dev tools, environment variables and tasks
88
//
@@ -33,7 +33,9 @@ export class Mise extends VersionManager {
3333
await vscode.workspace.fs.stat(configuredPath);
3434
return configuredPath;
3535
} catch (_error: any) {
36-
throw new Error(`Mise executable configured as ${configuredPath.fsPath}, but that file doesn't exist`);
36+
throw new NonReportableError(
37+
`Mise executable configured as ${configuredPath.fsPath}, but that file doesn't exist`,
38+
);
3739
}
3840
}
3941

@@ -57,7 +59,7 @@ export class Mise extends VersionManager {
5759
}
5860
}
5961

60-
throw new Error(
62+
throw new NonReportableError(
6163
`The Ruby LSP version manager is configured to be Mise, but could not find Mise installation. Searched in
6264
${possiblePaths.join(", ")}`,
6365
);

vscode/src/ruby/rbenv.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
22

3-
import { VersionManager, ActivationResult } from "./versionManager";
3+
import { VersionManager, ActivationResult, NonReportableError } from "./versionManager";
44

55
// Seamlessly manage your app’s Ruby environment with rbenv.
66
//
@@ -36,7 +36,9 @@ export class Rbenv extends VersionManager {
3636

3737
return path;
3838
} catch (_error: any) {
39-
throw new Error(`The Ruby LSP version manager is configured to be rbenv, but ${path} does not exist`);
39+
throw new NonReportableError(
40+
`The Ruby LSP version manager is configured to be rbenv, but ${path} does not exist`,
41+
);
4042
}
4143
}
4244
}

vscode/src/ruby/rv.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
22

3-
import { VersionManager, ActivationResult } from "./versionManager";
3+
import { VersionManager, ActivationResult, NonReportableError } from "./versionManager";
44

55
// Manage your Ruby environment with rv
66
//
@@ -40,7 +40,7 @@ export class Rv extends VersionManager {
4040
await vscode.workspace.fs.stat(vscode.Uri.file(path));
4141
return path;
4242
} catch (_error: any) {
43-
throw new Error(`The Ruby LSP version manager is configured to be rv, but ${path} does not exist`);
43+
throw new NonReportableError(`The Ruby LSP version manager is configured to be rv, but ${path} does not exist`);
4444
}
4545
}
4646
}

vscode/src/ruby/rvm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from "os";
22

33
import * as vscode from "vscode";
44

5-
import { ActivationResult, VersionManager } from "./versionManager";
5+
import { ActivationResult, NonReportableError, VersionManager } from "./versionManager";
66

77
// Ruby enVironment Manager. It manages Ruby application environments and enables switching between them.
88
// Learn more:
@@ -43,7 +43,7 @@ export class Rvm extends VersionManager {
4343
}
4444
}
4545

46-
throw new Error(
46+
throw new NonReportableError(
4747
`Cannot find RVM installation directory. Searched in ${possiblePaths.map((uri) => uri.fsPath).join(",")}`,
4848
);
4949
}

vscode/src/ruby/shadowenv.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Shadowenv extends VersionManager {
1515
try {
1616
await vscode.workspace.fs.stat(vscode.Uri.joinPath(this.bundleUri, ".shadowenv.d"));
1717
} catch (_error: any) {
18-
throw new Error(
18+
throw new NonReportableError(
1919
"The Ruby LSP version manager is configured to be shadowenv, \
2020
but no .shadowenv.d directory was found in the workspace",
2121
);
@@ -58,15 +58,15 @@ export class Shadowenv extends VersionManager {
5858
try {
5959
await asyncExec("shadowenv --version");
6060
} catch (_error: any) {
61-
throw new Error(
61+
throw new NonReportableError(
6262
`Shadowenv executable not found. Ensure it is installed and available in the PATH.
6363
This error may happen if your shell configuration is failing to be sourced from the editor or if
6464
another extension is mutating the process PATH.`,
6565
);
6666
}
6767

6868
// If it failed for some other reason, present the error to the user
69-
throw new Error(`Failed to activate Ruby environment with Shadowenv: ${error.message}`);
69+
throw new NonReportableError(`Failed to activate Ruby environment with Shadowenv: ${error.message}`);
7070
}
7171
}
7272
}

0 commit comments

Comments
 (0)