{"record":{"id":"0bd80a091a4daed8","repo":"aaif-goose/goose","slug":"missing-required-environment-variables","errorCode":null,"errorMessage":"Missing required environment variables","messagePattern":"Missing required environment variables","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/goose-cli/src/scenario_tests/scenario_runner.rs","lineNumber":348,"sourceCode":"        for (&var, value) in mods.iter() {\n            match value {\n                Some(val) => std::env::set_var(var, val),\n                None => std::env::remove_var(var),\n            }\n        }\n    }\n\n    let missing_vars = config\n        .required_env_vars\n        .iter()\n        .any(|var| std::env::var(var).is_err());\n\n    if missing_vars {\n        println!(\n            \"Skipping {} scenario - credentials not configured\",\n            config.name\n        );\n        return Err(anyhow::anyhow!(\"Missing required environment variables\"));\n    }\n\n    Ok(original_env)\n}\n\nfn restore_environment(config: &ProviderConfig, original_env: &HashMap<&'static str, String>) {\n    for (&var, value) in original_env.iter() {\n        std::env::set_var(var, value);\n    }\n    if let Some(mods) = &config.env_modifications {\n        for &var in mods.keys() {\n            if !original_env.contains_key(var) {\n                std::env::remove_var(var);\n            }\n        }\n    }\n}\n","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/aaif-goose/goose/blob/3810898a7447ec3299be72e223d3570a7aabf0ab/crates/goose-cli/src/scenario_tests/scenario_runner.rs#L330-L366","documentation":"setup_environment found at least one of the provider's required_env_vars missing from the process environment, so the scenario cannot run without credentials. The runner prints 'Skipping <provider> scenario - credentials not configured' and returns this error as the skip signal — semantically a skip, not a hard failure of the code under test.","triggerScenarios":"Running scenario tests where a provider config declares required_env_vars (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, DATABRICKS_HOST) that are not exported in the shell running cargo test.","commonSituations":"Fresh dev machines without the .env sourced; CI workflows where secrets for optional providers are not configured; running the full matrix when you only have one vendor's key.","solutions":["Export the missing variables (source the project's .env or set them in the CI job's secrets) before running the scenario tests.","If you intentionally lack a vendor's credentials, restrict the run with GOOSE_TEST_PROVIDER=<provider> or add the provider to the scenario's skip list.","In CI, mark these scenarios allowed-to-skip or gate them on secret presence."],"exampleFix":"# before\n$ cargo test -p goose-cli scenario_tests\nSkipping openai scenario - credentials not configured\nError: Missing required environment variables\n\n# after\n$ set -a; source .env; set +a   # exports OPENAI_API_KEY etc.\n$ cargo test -p goose-cli scenario_tests","handlingStrategy":"fallback","validationCode":"# only run scenario tests for providers whose credentials you have\nfor var in OPENAI_API_KEY ANTHROPIC_API_KEY; do\n    [ -n \"${!var:-}\" ] || echo \"skip: $var unset\"\ndone","typeGuard":null,"tryCatchPattern":"match run_scenario(...).await {\n    Err(e) if e.to_string() == \"Missing required environment variables\" => {\n        Ok(()) // treat as skip: provider intentionally not configured\n    }\n    r => r,\n}","preventionTips":["Source the project .env before running scenario tests.","In CI, gate optional-provider scenarios on secret presence instead of letting them error.","Use GOOSE_TEST_PROVIDER to run only what you have keys for."],"tags":["testing","env-vars","credentials","skip"],"backgroundTag":null,"analyzedSha":"3810898a7447ec3299be72e223d3570a7aabf0ab","analyzedAt":"2026-08-16T10:14:26.282Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}