{"record":{"id":"99eb3b24c29046ef","repo":"astrid-runtime/astrid","slug":"var-must-be-key-value-got-item-99eb3b","errorCode":null,"errorMessage":"--var must be KEY=VALUE (got {item:?})","messagePattern":"--var must be KEY=VALUE \\(got (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/init.rs","lineNumber":73,"sourceCode":"    /// `init` installs capsules but attaches no grants and\n    /// prints the manual `agent modify` command for discoverability.\n    pub(crate) grant_capsules: bool,\n    /// Require the signed self-contained Distro artifact used by product\n    /// Apply. Ordinary `init` retains its legacy source support.\n    pub(crate) require_signed: bool,\n}\n\npub(crate) use grant::apply_self_grant;\n\n/// Parse `--var KEY=VALUE` strings into a map.\n///\n/// Splits on the first `=`. A missing `=` or empty key is an error.\npub(crate) fn parse_cli_vars(raw: &[String]) -> anyhow::Result<HashMap<String, String>> {\n    let mut map = HashMap::new();\n    for item in raw {\n        let (key, value) = item\n            .split_once('=')\n            .ok_or_else(|| anyhow::anyhow!(\"--var must be KEY=VALUE (got {item:?})\"))?;\n        if key.is_empty() {\n            bail!(\"--var has an empty key (got {item:?})\");\n        }\n        map.insert(key.to_string(), value.to_string());\n    }\n    Ok(map)\n}\n\n/// Enforce source flags before this flow can create runtime state.\nfn validate_install_source(\n    distro_source: &str,\n    opts: &InitOpts,\n    operator: &astrid_core::PrincipalId,\n    target: &astrid_core::PrincipalId,\n) -> anyhow::Result<bool> {\n    let shuttle_install = distro_source.ends_with(\".shuttle\");\n    // `--grant-capsules` is not wired for `.shuttle`; fail rather than silently\n    // skip the requested grants and point at the legacy manual command.","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/init.rs#L55-L91","documentation":"parse_cli_vars parses each --var item with split_once('='). Any item without an '=' separator cannot be split into KEY=VALUE and produces this error, echoing the offending item with {:?}. It is a CLI usage error, not a runtime failure.","triggerScenarios":"Passing `--var foo` (missing '=value'), `--var =bar` (empty key — though that hits a separate error), or quoting mistakes like `--var \"foo =bar\"` where the value contains stray spaces.","commonSituations":"Users forgetting the value side (`--var name`), shell quoting issues (`--var key=my value` unquoted), or copy-pasting flag syntax from docs incorrectly.","solutions":["Supply the variable as KEY=VALUE, e.g. --var region=eu-west-1","Quote the whole argument if the value contains spaces: --var \"key=my value\"","Check `astrid init --help` for the exact --var syntax","Improve the error to suggest the expected format with an example"],"exampleFix":"// before\nastrid init --var region\n// after\nastrid init --var region=eu-west-1","handlingStrategy":"validation","validationCode":"fn valid_cli_var(item: &str) -> bool {\n    match item.split_once('=') {\n        Some((k, _)) => !k.is_empty(),\n        None => false,\n    }\n}","typeGuard":null,"tryCatchPattern":"let vars = parse_cli_vars(&raw_vars)\n    .map_err(|e| { eprintln!(\"usage: --var KEY=VALUE\\n{e}\"); std::process::exit(2); })?;","preventionTips":["Always pass --var as KEY=VALUE with no space around '='","Quote arguments containing spaces in the shell","Validate flags in scripts with a preflight check before invoking init","Read `astrid init --help` for the accepted syntax"],"tags":["cli","argument-parsing","rust"],"backgroundTag":"invalid-cli-argument","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}