Show error when GEMINI_API_KEY is not set (#52)

Also fix the bug where the API key is used accidentally as the model name.
This commit is contained in:
Jaana Dogan 2025-04-18 19:26:16 -07:00 committed by GitHub
parent 4354458cad
commit 65e8e3ed1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 2 deletions

View File

@ -39,10 +39,17 @@ export class Config {
export function loadConfig(): Config {
loadEnvironment();
if (!process.env.GEMINI_API_KEY) {
console.log(
'GEMINI_API_KEY is not set. See https://ai.google.dev/gemini-api/docs/api-key to obtain one. ' +
'Please set it in your .env file or as an environment variable.',
);
process.exit(1);
}
const argv = parseArguments();
return new Config(
process.env.GEMINI_API_KEY || '',
argv.model || process.env.GEMINI_API_KEY || DEFAULT_GEMINI_MODEL,
process.env.GEMINI_API_KEY,
argv.model || DEFAULT_GEMINI_MODEL,
argv.target_dir || process.cwd(),
);
}