{"record":{"id":"afc70aaf0452092e","repo":"astrid-runtime/astrid","slug":"var-has-an-empty-key-got-item-afc70a","errorCode":null,"errorMessage":"--var has an empty key (got {item:?})","messagePattern":"--var has an empty key \\(got (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/init.rs","lineNumber":75,"sourceCode":"    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.\n    if shuttle_install && opts.grant_capsules {\n        bail!(","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/init.rs#L57-L93","documentation":"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.","triggerScenarios":"Calling parse_cli_vars with an entry like '=value' or '=' — i.e. item.split_once('=') succeeds but the key segment is empty.","commonSituations":"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).","solutions":["Provide each --var argument as KEY=VALUE with a non-empty KEY, e.g. --var env=prod.","Check shell variable expansion so an unset variable doesn't leave an empty key before the '='.","Quote arguments containing spaces or '=' so the split sees the intended key."],"exampleFix":"// before\nastrid init --var =production\n// after\nastrid init --var env=production","handlingStrategy":"validation","validationCode":"for item in raw_vars {\n    if !item.contains('=') || item.starts_with('=') {\n        eprintln!(\"--var must be non-empty KEY=VALUE, got {item:?}\");\n        std::process::exit(2);\n    }\n}","typeGuard":null,"tryCatchPattern":"match parse_cli_vars(&vars) {\n    Ok(map) => apply(map),\n    Err(e) => eprintln!(\"bad --var: {e:#}\"),\n}","preventionTips":["Always write --var as KEY=VALUE with a non-empty key.","Quote shell expansions and guard against unset variables feeding the key.","Add a preflight check in scripts that build --var arguments dynamically."],"tags":["cli","arguments","validation"],"backgroundTag":"empty-required-field","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}