Skip to content

Commit 4485199

Browse files
committed
Make sure Auto doesn't behave as None and fail for developers
This situation can only happen if discoverVersionManager() fails to detect any version manager and leaves identifier as 'auto', which should never happen since `None` is the fallback. This is just an additional safety check to catch bugs early.
1 parent 9f265bd commit 4485199

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

vscode/src/ruby.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ interface ManagerClass {
4545
detect: (workspaceFolder: vscode.WorkspaceFolder, outputChannel: WorkspaceChannel) => Promise<DetectionResult>;
4646
}
4747

48-
const VERSION_MANAGERS: Record<ManagerIdentifier, ManagerClass> = {
48+
const VERSION_MANAGERS: Record<ManagerIdentifier, ManagerClass | undefined> = {
4949
[ManagerIdentifier.Shadowenv]: Shadowenv,
5050
[ManagerIdentifier.Asdf]: Asdf,
5151
[ManagerIdentifier.Chruby]: Chruby,
@@ -55,8 +55,8 @@ const VERSION_MANAGERS: Record<ManagerIdentifier, ManagerClass> = {
5555
[ManagerIdentifier.Mise]: Mise,
5656
[ManagerIdentifier.RubyInstaller]: RubyInstaller,
5757
[ManagerIdentifier.Custom]: Custom,
58-
[ManagerIdentifier.Auto]: None, // Auto is handled specially
5958
[ManagerIdentifier.None]: None, // None is last as the fallback
59+
[ManagerIdentifier.Auto]: undefined, // Auto is handled specially
6060
};
6161

6262
export class Ruby implements RubyInterface {
@@ -294,6 +294,15 @@ export class Ruby implements RubyInterface {
294294

295295
private async runManagerActivation() {
296296
const ManagerClass = VERSION_MANAGERS[this.versionManager.identifier];
297+
298+
if (!ManagerClass) {
299+
throw new Error(
300+
`BUG: No ManagerClass found for identifier '${this.versionManager.identifier}'. ` +
301+
`This indicates either: (1) discoverVersionManager() failed to detect any version manager and left identifier as 'auto', ` +
302+
`or (2) a new ManagerIdentifier enum value was added without updating VERSION_MANAGERS.`,
303+
);
304+
}
305+
297306
const manager = new ManagerClass(
298307
this.workspaceFolder,
299308
this.outputChannel,

0 commit comments

Comments
 (0)