astrid-runtime/astrid · error

--var has an empty key (got {item:?})

Error message

--var has an empty key (got {item:?})

What it means

The --var option accepts KEY=VALUE pairs; an entry whose '=' prefix yields an empty key (e.g. '=value' or '=') is rejected. Empty keys cannot be resolved into a variable map, so parsing fails fast with the offending item shown.

Source

Thrown at crates/astrid-cli/src/commands/init.rs:75

    pub(crate) grant_capsules: bool,
    /// Require the signed self-contained Distro artifact used by product
    /// Apply. Ordinary `init` retains its legacy source support.
    pub(crate) require_signed: bool,
}

pub(crate) use grant::apply_self_grant;

/// Parse `--var KEY=VALUE` strings into a map.
///
/// Splits on the first `=`. A missing `=` or empty key is an error.
pub(crate) fn parse_cli_vars(raw: &[String]) -> anyhow::Result<HashMap<String, String>> {
    let mut map = HashMap::new();
    for item in raw {
        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:?})");
        }
        map.insert(key.to_string(), value.to_string());
    }
    Ok(map)
}

/// Enforce source flags before this flow can create runtime state.
fn validate_install_source(
    distro_source: &str,
    opts: &InitOpts,
    operator: &astrid_core::PrincipalId,
    target: &astrid_core::PrincipalId,
) -> anyhow::Result<bool> {
    let shuttle_install = distro_source.ends_with(".shuttle");
    // `--grant-capsules` is not wired for `.shuttle`; fail rather than silently
    // skip the requested grants and point at the legacy manual command.
    if shuttle_install && opts.grant_capsules {
        bail!(

View on GitHub (pinned to affd8760f4)

Solutions

  1. Provide each --var argument as KEY=VALUE with a non-empty KEY, e.g. --var env=prod.
  2. Check shell variable expansion so an unset variable doesn't leave an empty key before the '='.
  3. Quote arguments containing spaces or '=' so the split sees the intended key.

Example fix

// before
astrid init --var =production
// after
astrid init --var env=production
Defensive patterns

Strategy: validation

Validate before calling

for item in raw_vars {
    if !item.contains('=') || item.starts_with('=') {
        eprintln!("--var must be non-empty KEY=VALUE, got {item:?}");
        std::process::exit(2);
    }
}

Try / catch

match parse_cli_vars(&vars) {
    Ok(map) => apply(map),
    Err(e) => eprintln!("bad --var: {e:#}"),
}

Prevention

When it happens

Trigger: Calling parse_cli_vars with an entry like '=value' or '=' — i.e. item.split_once('=') succeeds but the key segment is empty.

Common situations: Typo on the command line such as `astrid init --var =prod` or shell quoting that drops the key (`--var "$EMPTY="` where the variable holding the name is unset).

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


AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09). Data as JSON: /api/errors/afc70aaf0452092e. Report an issue: GitHub.