From f1647d9e19bf6930bc50bd2e66d2929f8f771503 Mon Sep 17 00:00:00 2001 From: Marat Boshernitsan Date: Tue, 8 Jul 2025 09:37:10 -0700 Subject: Improve auth env var validation logic and messaging to detect settings that confuse GenAI SDK (#1381) Co-authored-by: Scott Densmore Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/cli/src/config/auth.test.ts | 6 +++--- packages/cli/src/config/auth.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'packages/cli/src') diff --git a/packages/cli/src/config/auth.test.ts b/packages/cli/src/config/auth.test.ts index a4c0cf25..96defb1e 100644 --- a/packages/cli/src/config/auth.test.ts +++ b/packages/cli/src/config/auth.test.ts @@ -40,7 +40,7 @@ describe('validateAuthMethod', () => { it('should return an error message if GEMINI_API_KEY is not set', () => { expect(validateAuthMethod(AuthType.USE_GEMINI)).toBe( - 'GEMINI_API_KEY environment variable not found. Add that to your .env and try again, no reload needed!', + 'GEMINI_API_KEY environment variable not found. Add that to your environment and try again (no reload needed if using .env)!', ); }); }); @@ -59,10 +59,10 @@ describe('validateAuthMethod', () => { it('should return an error message if no required environment variables are set', () => { expect(validateAuthMethod(AuthType.USE_VERTEX_AI)).toBe( - 'Must specify GOOGLE_GENAI_USE_VERTEXAI=true and either:\n' + + 'When using Vertex AI, you must specify either:\n' + '• GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION environment variables.\n' + '• GOOGLE_API_KEY environment variable (if using express mode).\n' + - 'Update your .env and try again, no reload needed!', + 'Update your environment and try again (no reload needed if using .env)!', ); }); }); diff --git a/packages/cli/src/config/auth.ts b/packages/cli/src/config/auth.ts index 0f97b4d5..91d4eee3 100644 --- a/packages/cli/src/config/auth.ts +++ b/packages/cli/src/config/auth.ts @@ -18,7 +18,7 @@ export const validateAuthMethod = (authMethod: string): string | null => { if (authMethod === AuthType.USE_GEMINI) { if (!process.env.GEMINI_API_KEY) { - return 'GEMINI_API_KEY environment variable not found. Add that to your .env and try again, no reload needed!'; + return 'GEMINI_API_KEY environment variable not found. Add that to your environment and try again (no reload needed if using .env)!'; } return null; } @@ -29,10 +29,10 @@ export const validateAuthMethod = (authMethod: string): string | null => { const hasGoogleApiKey = !!process.env.GOOGLE_API_KEY; if (!hasVertexProjectLocationConfig && !hasGoogleApiKey) { return ( - 'Must specify GOOGLE_GENAI_USE_VERTEXAI=true and either:\n' + + 'When using Vertex AI, you must specify either:\n' + '• GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION environment variables.\n' + '• GOOGLE_API_KEY environment variable (if using express mode).\n' + - 'Update your .env and try again, no reload needed!' + 'Update your environment and try again (no reload needed if using .env)!' ); } return null; -- cgit v1.2.3