nikivdev/code · error · anyhow::Error

Key '{}' not found

Error message

Key '{}' not found

What it means

Raised in the `value` output format when the single requested key is not present in the fetched env-var map. The fetch succeeded, but the server has no variable under that key name, so there is no value to print.

Source

Thrown at src/env.rs:3870

    if vars.is_empty() {
        bail!("No env vars found");
    }

    match format {
        "json" => {
            let json = serde_json::to_string_pretty(&vars)?;
            println!("{}", json);
        }
        "value" => {
            if keys.len() != 1 {
                bail!("'value' format requires exactly one key");
            }
            let key = &keys[0];
            if let Some(value) = vars.get(key) {
                print!("{}", value); // No newline for piping
            } else {
                bail!("Key '{}' not found", key);
            }
        }
        "env" | _ => {
            // Default: KEY=VALUE format
            let mut sorted_keys: Vec<_> = vars.keys().collect();
            sorted_keys.sort();
            for key in sorted_keys {
                let value = &vars[key];
                // Escape for shell
                let escaped = value.replace('\\', "\\\\").replace('"', "\\\"");
                println!("{}=\"{}\"", key, escaped);
            }
        }
    }

    Ok(())
}

View on GitHub (pinned to a747e741ae)

Solutions

  1. Run `f env pull` (default format) to list available key names and copy the exact spelling.
  2. Fix the key's case/spelling in --keys to match the stored variable.
  3. Push the missing variable with `f env push` if it should exist.

Example fix

// before
f env pull --format value --keys API_URL
// after: exact remote key name
f env pull --format value --keys apiUrl
Defensive patterns

Strategy: validation

Validate before calling

# confirm the key exists before requesting its value
f env list | grep -qx "^$KEY=" || { echo "key '$KEY' not found remotely" >&2; exit 1; }
VAL=$(f env pull --format value --keys "$KEY")

Try / catch

// fail fast with the exact key named
VAL=$(f env pull --format value --keys "$KEY") \
  || { echo "could not read '$KEY'; run 'f env list' to see available keys" >&2; exit 1; }

Prevention

When it happens

Trigger: `f env pull --format value --keys KEY` where KEY differs in spelling or case from the stored variable name, or the variable was never pushed / was deleted.

Common situations: Case-mismatch (API_URL vs apiUrl); referencing a key that exists locally in .env but was never pushed; key removed remotely by a teammate.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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