aaif-goose/goose · warning

Missing required environment variables

Error message

Missing required environment variables

What it means

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.

Source

Thrown at crates/goose-cli/src/scenario_tests/scenario_runner.rs:348

        for (&var, value) in mods.iter() {
            match value {
                Some(val) => std::env::set_var(var, val),
                None => std::env::remove_var(var),
            }
        }
    }

    let missing_vars = config
        .required_env_vars
        .iter()
        .any(|var| std::env::var(var).is_err());

    if missing_vars {
        println!(
            "Skipping {} scenario - credentials not configured",
            config.name
        );
        return Err(anyhow::anyhow!("Missing required environment variables"));
    }

    Ok(original_env)
}

fn restore_environment(config: &ProviderConfig, original_env: &HashMap<&'static str, String>) {
    for (&var, value) in original_env.iter() {
        std::env::set_var(var, value);
    }
    if let Some(mods) = &config.env_modifications {
        for &var in mods.keys() {
            if !original_env.contains_key(var) {
                std::env::remove_var(var);
            }
        }
    }
}

View on GitHub (pinned to 3810898a74)

Solutions

  1. Export the missing variables (source the project's .env or set them in the CI job's secrets) before running the scenario tests.
  2. 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.
  3. In CI, mark these scenarios allowed-to-skip or gate them on secret presence.

Example fix

# before
$ cargo test -p goose-cli scenario_tests
Skipping openai scenario - credentials not configured
Error: Missing required environment variables

# after
$ set -a; source .env; set +a   # exports OPENAI_API_KEY etc.
$ cargo test -p goose-cli scenario_tests
Defensive patterns

Strategy: fallback

Validate before calling

# only run scenario tests for providers whose credentials you have
for var in OPENAI_API_KEY ANTHROPIC_API_KEY; do
    [ -n "${!var:-}" ] || echo "skip: $var unset"
done

Try / catch

match run_scenario(...).await {
    Err(e) if e.to_string() == "Missing required environment variables" => {
        Ok(()) // treat as skip: provider intentionally not configured
    }
    r => r,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of aaif-goose/goose@3810898a74 (2026-08-16). Data as JSON: /api/errors/0bd80a091a4daed8. Report an issue: GitHub.