From 999d0568fab9c4da2ae0978c4344bf76fe2cb27e Mon Sep 17 00:00:00 2001 From: Brandon Keiji Date: Fri, 18 Apr 2025 10:25:32 -0700 Subject: Refactor: Update API key missing message with link (#23) --- packages/cli/src/config/env.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'packages/cli/src') diff --git a/packages/cli/src/config/env.ts b/packages/cli/src/config/env.ts index ad535b80..51fc0a9c 100644 --- a/packages/cli/src/config/env.ts +++ b/packages/cli/src/config/env.ts @@ -24,17 +24,15 @@ export function loadEnvironment(): void { // Start searching from the current working directory by default const envFilePath = findEnvFile(process.cwd()); - if (!envFilePath) { - return; + if (envFilePath) { + dotenv.config({ path: envFilePath }); } - dotenv.config({ path: envFilePath }); - - if (!process.env.GEMINI_API_KEY) { + if (!process.env.GEMINI_API_KEY?.length) { console.error( - 'Error: GEMINI_API_KEY environment variable is not set in the loaded .env file.', + 'Error: GEMINI_API_KEY environment variable is not set. Please visit https://ai.google.dev/gemini-api/docs/api-key to set up a new one.', ); - process.exit(1); + process.exit(0); } } @@ -43,7 +41,7 @@ export function getApiKey(): string { const apiKey = process.env.GEMINI_API_KEY; if (!apiKey) { throw new Error( - 'GEMINI_API_KEY is missing. Ensure loadEnvironment() was called successfully.', + 'GEMINI_API_KEY environment variable is not set. Please visit https://ai.google.dev/gemini-api/docs/api-key to set up a new one.', ); } return apiKey; -- cgit v1.2.3