nikivdev/code · error · anyhow::Error

No env keys configured. Add cloudflare.env_keys or cloudflar

Error message

No env keys configured. Add cloudflare.env_keys or cloudflare.env_vars to flow.toml.

What it means

Raised by the env-check flow when, after collecting keys from flow.toml's `cloudflare.env_keys` and/or `cloudflare.env_vars`, the required set is empty. The check exists to verify that all configured keys are present in the cloud project environment, so with nothing configured there is nothing to validate and the CLI bails.

Source

Thrown at src/env.rs:2599

    let flow_path = find_flow_toml(&cwd)
        .ok_or_else(|| anyhow::anyhow!("flow.toml not found. Run `f init` first."))?;
    let cfg = config::load(&flow_path)?;

    let cf_cfg = cfg
        .cloudflare
        .as_ref()
        .context("No [cloudflare] section in flow.toml")?;

    let mut required = Vec::new();
    let mut seen = HashSet::new();
    for key in cf_cfg.env_keys.iter().chain(cf_cfg.env_vars.iter()) {
        if seen.insert(key.clone()) {
            required.push(key.clone());
        }
    }

    if required.is_empty() {
        bail!(
            "No env keys configured. Add cloudflare.env_keys or cloudflare.env_vars to flow.toml."
        );
    }

    println!("Checking required env vars for '{}'...", environment);
    let existing = match fetch_project_env_vars(environment, &required) {
        Ok(vars) => vars,
        Err(err) => {
            let msg = format!("{err:#}");
            if msg.contains("Project not found.") {
                println!("  (project not found yet; will create on first set)");
                HashMap::new()
            } else {
                return Err(err);
            }
        }
    };
    let var_keys: HashSet<String> = cf_cfg.env_vars.iter().cloned().collect();

View on GitHub (pinned to a747e741ae)

Solutions

  1. Add `cloudflare.env_keys = ["KEY_A", "KEY_B"]` (or `cloudflare.env_vars`) to flow.toml and re-run the check.
  2. Uncomment or restore the env_keys/env_vars section if it was removed or commented out.
  3. Confirm you are checking the intended project/environment — one whose flow.toml actually declares env keys.

Example fix

# before (flow.toml)
[cloudflare]
# env_keys = []
# after
[cloudflare]
env_keys = ["API_KEY", "DB_URL"]
Defensive patterns

Strategy: validation

Validate before calling

// Parse flow.toml and verify env keys are declared before running the check:
let cfg: TomlValue = toml::from_str(&fs::read_to_string("flow.toml")?)?;
let keys = cfg.get("cloudflare")
    .and_then(|c| c.get("env_keys").or_else(|| c.get("env_vars")));
if keys.map(|k| k.as_array().map_or(true, |a| a.is_empty())).unwrap_or(true) {
    bail!("flow.toml has no cloudflare.env_keys/env_vars configured");
}

Prevention

When it happens

Trigger: Running the env-check command against a project whose flow.toml lacks both `cloudflare.env_keys` and `cloudflare.env_vars` sections, or where both are present but empty/deduplicated to nothing.

Common situations: Fresh projects whose flow.toml was scaffolded without env config; renamed config sections after a version change; commented-out env_keys block; checking the wrong project whose toml has no env settings.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/08058a45462f801d. Report an issue: GitHub.