astrid-runtime/astrid · error
--var has an empty key (got {item:?})
Error message
--var has an empty key (got {item:?}) What it means
`from_cli` parses each `--var KEY=VALUE` item with `split_once('=')`. After splitting, if the key part is empty (e.g. `--var =value` or `--var =`), it bails with this message including the offending item in debug form. It enforces that every variable override has a non-empty key.
Source
Thrown at crates/astrid-cli/src/commands/capsule/install.rs:68
}
/// Operator input policy for a manual capsule install.
#[derive(Debug, Clone, Default)]
pub(super) struct ManualInstallOptions {
pub(super) yes: bool,
pub(super) approve_untrusted: bool,
pub(super) vars: HashMap<String, String>,
}
impl ManualInstallOptions {
fn from_cli(yes: bool, approve_untrusted: bool, items: &[String]) -> anyhow::Result<Self> {
let mut vars = HashMap::new();
for item in items {
let (key, value) = item
.split_once('=')
.ok_or_else(|| anyhow::anyhow!("--var must be KEY=VALUE (got {item:?})"))?;
if key.is_empty() {
bail!("--var has an empty key (got {item:?})");
}
if vars.insert(key.to_string(), value.to_string()).is_some() {
bail!("--var '{key}' was supplied more than once");
}
}
Ok(Self {
yes,
approve_untrusted,
vars,
})
}
}
#[derive(Clone, Copy)]
pub(crate) struct OfflineCapsuleProvenance<'a> {
pub(crate) original_source: &'a str,
pub(crate) resolved_ref: Option<&'a str>,
pub(crate) signer: Option<&'a str>,View on GitHub (pinned to affd8760f4)
Solutions
- Supply the variable as `KEY=VALUE` with a non-empty KEY: `--var MY_VAR=value`.
- Check shell quoting/expansions — an empty variable before `=` yields an empty key.
- Review the printed `{item:?}` to see the exact malformed argument the CLI received.
- Remove the offending `--var` flag if it was added by mistake.
Example fix
// before --var =value // after --var MY_KEY=value
Defensive patterns
Strategy: validation
Validate before calling
fn validate_var(item: &str) -> Result<(), String> {
match item.split_once('=') {
Some((k, _)) if !k.is_empty() => Ok(()),
_ => Err(format!("--var must be non-empty KEY=VALUE, got {item:?}")),
}
}
// validate every --var before invoking the CLI Try / catch
match result {
Err(e) if e.to_string().contains("empty key") =>
eprintln!("Fix your --var flags: every entry needs KEY=VALUE with a non-empty KEY."),
other => other.expect("install failed"),
} Prevention
- Always write --var as KEY=VALUE with a non-empty key.
- In scripts, check that key variables are non-empty before building the command.
- Quote args carefully so shell expansion cannot drop the key.
- Read the echoed {item:?} to spot the exact malformed flag.
When it happens
Trigger: Running `astrid capsule install` with `--var` whose value has no characters before `=`: `--var =foo`, `--var =`, or a shell-quoting accident that drops the key (e.g. `--var "$EMPTY"=x`).
Common situations: Scripted installs where a variable holding the key is empty; copy-pasted CLI examples with the key lost; shell expansions interpolating to `=value`.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- --var has an invalid key (got {key:?})
- --var has an empty key (got {item:?})
- --var must be KEY=VALUE (got {item:?})
- --retain-entries must be at least 1
- --retain-bytes must be greater than 0
AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09).
Data as JSON: /api/errors/c25a437db3a8adc0.
Report an issue: GitHub.