nikivdev/code · error · anyhow::Error
'value' format requires exactly one key
Error message
'value' format requires exactly one key
What it means
Raised by the `value` output format handler, which prints a single raw value (no newline) for piping into other commands. Because raw-value output is only meaningful for exactly one variable, the command enforces that exactly one key was requested and bails otherwise.
Source
Thrown at src/env.rs:3864
let target = if personal {
resolve_personal_target()?
} else {
resolve_env_target()?
};
let vars = fetch_env_vars(&target, environment, keys, !personal)?;
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);
}View on GitHub (pinned to a747e741ae)
Solutions
- Pass exactly one key: `f env pull --format value --keys DATABASE_URL`.
- Use `--format env` or `--format json` when you need multiple or all variables.
- Shell-evaluate the result when piping: `export $(f env pull --format value --keys KEY)`.
Example fix
// before f env pull --format value --keys A,B // after (one key per invocation) export A=$(f env pull --format value --keys A) export B=$(f env pull --format value --keys B)
Defensive patterns
Strategy: validation
Validate before calling
# ensure exactly one key is passed before invoking value format
KEYS="a"
count=$(echo "$KEYS" | awk -F, '{print NF}')
[ "$count" -eq 1 ] || { echo "--format value needs exactly one --keys entry" >&2; exit 1; }
f env pull --format value --keys "$KEYS" Try / catch
// wrapper enforcing the invariant
function env_value() {
[ "$#" -eq 1 ] || { echo "usage: env_value <single-key>" >&2; return 2; }
f env pull --format value --keys "$1"
} Prevention
- Use `--format env` or `--format json` when you need more than one variable.
- Wrap the value-format call in a shell function that asserts a single argument.
- Never call value format without an explicit --keys flag.
When it happens
Trigger: Running e.g. `f env pull --format value` with zero keys (no --keys flag) or with two or more keys in --keys.
Common situations: Forgetting --keys when piping (`f env pull --format value | ...`); listing multiple keys assuming value format prints them all.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- sessions requires a specific provider (claude or codex)
- continue requires a specific provider (claude or codex)
- ai not found in PATH
- --all cannot be combined with HASH. Use `f commit-queue appr
- --path cannot be used with --no-commit or --hash
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/6db72e19f7190526.
Report an issue: GitHub.