fix(litellm): add error handling in onboarding wizard

The AUTH_CHOICE_CANCELLED error was showing to users during onboarding
because the applyAuthChoice call in onboarding.ts wasn't wrapped in
error handling. This adds the same try-catch loop pattern used in
configure.gateway-auth.ts and agents.commands.add.ts to properly
handle the cancellation and re-prompt for auth method selection.
This commit is contained in:
Charles-Henri ROBICHE 2026-01-29 11:15:09 +01:00
parent ce8fd694ae
commit 327e82da5d
No known key found for this signature in database

View File

@ -21,6 +21,7 @@ import { promptRemoteGatewayConfig } from "../commands/onboard-remote.js";
import { setupSkills } from "../commands/onboard-skills.js"; import { setupSkills } from "../commands/onboard-skills.js";
import { setupInternalHooks } from "../commands/onboard-hooks.js"; import { setupInternalHooks } from "../commands/onboard-hooks.js";
import type { import type {
AuthChoice,
GatewayAuthChoice, GatewayAuthChoice,
OnboardMode, OnboardMode,
OnboardOptions, OnboardOptions,
@ -354,7 +355,11 @@ export async function runOnboardingWizard(
allowKeychainPrompt: false, allowKeychainPrompt: false,
}); });
const authChoiceFromPrompt = opts.authChoice === undefined; const authChoiceFromPrompt = opts.authChoice === undefined;
const authChoice = let authChoice: AuthChoice;
// Loop to allow retrying auth choice if user cancels during configuration
while (true) {
authChoice =
opts.authChoice ?? opts.authChoice ??
(await promptAuthChoiceGrouped({ (await promptAuthChoiceGrouped({
prompter, prompter,
@ -362,6 +367,7 @@ export async function runOnboardingWizard(
includeSkip: true, includeSkip: true,
})); }));
try {
const authResult = await applyAuthChoice({ const authResult = await applyAuthChoice({
authChoice, authChoice,
config: nextConfig, config: nextConfig,
@ -374,6 +380,18 @@ export async function runOnboardingWizard(
}, },
}); });
nextConfig = authResult.config; nextConfig = authResult.config;
break; // Success - exit the loop
} catch (error) {
// If user cancelled to go back to auth selection, loop again
if (error instanceof Error && error.message === "AUTH_CHOICE_CANCELLED") {
// Clear opts.authChoice so we prompt again
opts.authChoice = undefined;
continue;
}
// Re-throw other errors
throw error;
}
}
if (authChoiceFromPrompt) { if (authChoiceFromPrompt) {
const modelSelection = await promptDefaultModel({ const modelSelection = await promptDefaultModel({