Skip to content

Commit

Permalink
Report Ruby activation errors to telemetry (#2767)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Oct 24, 2024
1 parent 2f2f87d commit d348a6f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
7 changes: 7 additions & 0 deletions vscode/src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ export class Ruby implements RubyInterface {
private readonly context: vscode.ExtensionContext;
private readonly customBundleGemfile?: string;
private readonly outputChannel: WorkspaceChannel;
private readonly telemetry: vscode.TelemetryLogger;

constructor(
context: vscode.ExtensionContext,
workspaceFolder: vscode.WorkspaceFolder,
outputChannel: WorkspaceChannel,
telemetry: vscode.TelemetryLogger,
) {
this.context = context;
this.workspaceFolder = workspaceFolder;
this.outputChannel = outputChannel;
this.telemetry = telemetry;

const customBundleGemfile: string = vscode.workspace
.getConfiguration("rubyLsp")
Expand Down Expand Up @@ -125,6 +128,10 @@ export class Ruby implements RubyInterface {
try {
await this.runManagerActivation();
} catch (error: any) {
this.telemetry.logError(error, {
versionManager: this.versionManager.identifier,
});

// If an error occurred and a global Ruby path is configured, then we can try to fallback to that
const globalRubyPath = vscode.workspace
.getConfiguration("rubyLsp")
Expand Down
7 changes: 6 additions & 1 deletion vscode/src/test/suite/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ async function launchClient(workspaceUri: vscode.Uri) {
}
}

const ruby = new Ruby(context, workspaceFolder, outputChannel);
const ruby = new Ruby(
context,
workspaceFolder,
outputChannel,
FAKE_TELEMETRY,
);
await ruby.activateRuby();
ruby.env.RUBY_LSP_BYPASS_TYPECHECKER = "true";

Expand Down
9 changes: 8 additions & 1 deletion vscode/src/test/suite/debugger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { WorkspaceChannel } from "../../workspaceChannel";
import { LOG_CHANNEL, asyncExec } from "../../common";
import { RUBY_VERSION } from "../rubyVersion";

import { FAKE_TELEMETRY } from "./fakeTelemetry";

suite("Debugger", () => {
test("Provide debug configurations returns the default configs", () => {
const context = { subscriptions: [] } as unknown as vscode.ExtensionContext;
Expand Down Expand Up @@ -203,7 +205,12 @@ suite("Debugger", () => {
name: path.basename(tmpPath),
index: 0,
};
const ruby = new Ruby(context, workspaceFolder, outputChannel);
const ruby = new Ruby(
context,
workspaceFolder,
outputChannel,
FAKE_TELEMETRY,
);
await ruby.activateRuby();

try {
Expand Down
23 changes: 20 additions & 3 deletions vscode/src/test/suite/ruby.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { LOG_CHANNEL } from "../../common";
import * as common from "../../common";
import { ACTIVATION_SEPARATOR } from "../../ruby/versionManager";

import { FAKE_TELEMETRY } from "./fakeTelemetry";

suite("Ruby environment activation", () => {
const workspacePath = path.dirname(
path.dirname(path.dirname(path.dirname(__dirname))),
Expand Down Expand Up @@ -48,7 +50,12 @@ suite("Ruby environment activation", () => {
},
} as unknown as vscode.WorkspaceConfiguration);

const ruby = new Ruby(context, workspaceFolder, outputChannel);
const ruby = new Ruby(
context,
workspaceFolder,
outputChannel,
FAKE_TELEMETRY,
);
await ruby.activateRuby();

assert.ok(ruby.rubyVersion, "Expected Ruby version to be set");
Expand Down Expand Up @@ -80,7 +87,12 @@ suite("Ruby environment activation", () => {
},
} as unknown as vscode.WorkspaceConfiguration);

const ruby = new Ruby(context, workspaceFolder, outputChannel);
const ruby = new Ruby(
context,
workspaceFolder,
outputChannel,
FAKE_TELEMETRY,
);

process.env.VERBOSE = "1";
process.env.DEBUG = "WARN";
Expand Down Expand Up @@ -123,7 +135,12 @@ suite("Ruby environment activation", () => {
stderr: `${ACTIVATION_SEPARATOR}${JSON.stringify(envStub)}${ACTIVATION_SEPARATOR}`,
});

const ruby = new Ruby(context, workspaceFolder, outputChannel);
const ruby = new Ruby(
context,
workspaceFolder,
outputChannel,
FAKE_TELEMETRY,
);
await ruby.activateRuby();
execStub.restore();
configStub.restore();
Expand Down
7 changes: 6 additions & 1 deletion vscode/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ export class Workspace implements WorkspaceInterface {
LOG_CHANNEL,
);
this.telemetry = telemetry;
this.ruby = new Ruby(context, workspaceFolder, this.outputChannel);
this.ruby = new Ruby(
context,
workspaceFolder,
this.outputChannel,
telemetry,
);
this.createTestItems = createTestItems;
this.isMainWorkspace = isMainWorkspace;
this.virtualDocuments = virtualDocuments;
Expand Down

0 comments on commit d348a6f

Please sign in to comment.