fix(coding-agent): prevent crash on OAuth authentication failure (#849)

Detect OAuth authentication failures (expired credentials, offline) and provide helpful error message instead of crashing with generic 'No API key found' error.

Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
This commit is contained in:
Dave 2026-01-19 15:59:45 +01:00 committed by GitHub
parent 98fb9f378c
commit d6bb66a494
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -641,7 +641,18 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
}
const key = await modelRegistry.getApiKeyForProvider(resolvedProvider);
if (!key) {
throw new Error(`No API key found for provider "${resolvedProvider}"`);
const isOAuth = modelRegistry.isUsingOAuth(currentModel);
if (isOAuth) {
throw new Error(
`Authentication failed for "${currentModel.provider}". ` +
`Credentials may have expired or network is unavailable. ` +
`Run '/login ${currentModel.provider}' to re-authenticate.`,
);
}
throw new Error(
`No API key found for "${currentModel.provider}". ` +
`Set an API key environment variable or run '/login ${currentModel.provider}'.`,
);
}
return key;
},