astrid-runtime/astrid · error

--var '{key}' was supplied more than once

Error message

--var '{key}' was supplied more than once

What it means

`from_cli` collects `--var` items into a `HashMap`; `vars.insert` returns `Some(old)` when the key already existed, and that triggers this bail. Duplicate keys in variable overrides are rejected instead of being silently overwritten, so the effective variable set is unambiguous.

Source

Thrown at crates/astrid-cli/src/commands/capsule/install.rs:71

#[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>,
    pub(crate) signature: Option<&'a str>,
}

View on GitHub (pinned to affd8760f4)

Solutions

  1. Remove or deduplicate the repeated `--var` entries so each key appears once.
  2. Keep the last intended value only: `--var FOO=2`.
  3. If both values are needed under different names, rename one key (e.g. `FOO` vs `FOO_ALT`).
  4. In scripts, build a unique key map before assembling the CLI invocation.

Example fix

// before
--var FOO=1 --var FOO=2
// after
--var FOO=2
Defensive patterns

Strategy: validation

Validate before calling

fn dedup_vars(items: &[String]) -> Result<std::collections::HashMap<String, String>, String> {
    let mut map = std::collections::HashMap::new();
    for item in items {
        let (k, v) = item.split_once('=')
            .ok_or_else(|| format!("bad --var {item:?}"))?;
        if map.insert(k.to_string(), v.to_string()).is_some() {
            return Err(format!("duplicate --var key: {k}"));
        }
    }
    Ok(map)
}

Try / catch

match result {
    Err(e) if e.to_string().contains("supplied more than once") =>
        eprintln!("A --var key was repeated; keep only the final intended value."),
    other => other.expect("install failed"),
}

Prevention

When it happens

Trigger: Passing the same key twice on the command line: `--var FOO=1 --var FOO=2`; a loop in a script emitting a `--var` twice; two sources of flags (config + shell) both adding the same key.

Common situations: Scripts accumulating `--var` flags in an array where a key appears in two entries; copy-paste duplication of flags; build tooling appending default vars that collide with user-supplied ones.

Related errors


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