Improve auth env var validation logic and messaging to detect settings that confuse GenAI SDK (#1381)

Co-authored-by: Scott Densmore <scottdensmore@mac.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
Marat Boshernitsan
2025-07-08 09:37:10 -07:00
committed by GitHub
parent 5c759d48c7
commit f1647d9e19
8 changed files with 175 additions and 30 deletions

View File

@@ -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)!',
);
});
});

View File

@@ -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;