{"record":{"id":"79d02134382de0cf","repo":"astrid-runtime/astrid","slug":"astrid-enforced-distro-must-not-be-empty","errorCode":null,"errorMessage":"ASTRID_ENFORCED_DISTRO must not be empty","messagePattern":"ASTRID_ENFORCED_DISTRO must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/dispatch.rs","lineNumber":280,"sourceCode":"    resolve_init_distro_with(requested, std::env::var_os(\"ASTRID_ENFORCED_DISTRO\"))\n}\n\nfn resolve_init_distro_with(\n    requested: Option<String>,\n    enforced: Option<OsString>,\n) -> Result<String> {\n    let Some(enforced) = enforced else {\n        return non_empty_distro_source(requested).ok_or_else(|| {\n            anyhow::anyhow!(\n                \"astrid init requires --distro <@owner/repo, URL, local Distro.toml, or .shuttle> unless ASTRID_ENFORCED_DISTRO is set by an embedding launcher; Astrid Runtime does not choose a product distro\"\n            )\n        });\n    };\n    let enforced = enforced.into_string().map_err(|_| {\n        anyhow::anyhow!(\"ASTRID_ENFORCED_DISTRO must contain a valid UTF-8 distro source\")\n    })?;\n    if enforced.is_empty() {\n        anyhow::bail!(\"ASTRID_ENFORCED_DISTRO must not be empty\");\n    }\n    if requested.is_some() {\n        anyhow::bail!(\n            \"astrid init cannot override the operator-enforced distro in ASTRID_ENFORCED_DISTRO\"\n        );\n    }\n    Ok(enforced)\n}\n\nfn non_empty_distro_source(source: Option<String>) -> Option<String> {\n    source.filter(|source| !source.is_empty())\n}\n\n/// Route the root capsule-verb shorthand (`astrid <verb> [args…]`).\n///\n/// Built-in verbs never reach here — clap matches a declared `Commands`\n/// variant before the `external_subcommand` catch-all. An unrecognised\n/// token that is a near-miss of a built-in is rejected with a \"did you","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/dispatch.rs#L262-L298","documentation":"`resolve_init_distro_with` validates the `ASTRID_ENFORCED_DISTRO` environment variable that operators use to pin the distro source for `astrid init`. If the variable is set but empty, initialization fails closed rather than falling back to a default, ensuring an operator's enforced-distro policy is never silently bypassed.","triggerScenarios":"Running `astrid init` (via `resolve_init_distro`) when `ASTRID_ENFORCED_DISTRO` is exported with an empty value, e.g. `ASTRID_ENFORCED_DISTRO= astrid init`.","commonSituations":"Shell scripts doing `export ASTRID_ENFORCED_DISTRO=$(cat policy_file)` where the file is empty or the command failed; CI configs defining the variable with no value; operators clearing the value intending to unset it.","solutions":["Set `ASTRID_ENFORCED_DISTRO` to a valid non-empty distro source.","Unset the variable entirely (`unset ASTRID_ENFORCED_DISTRO`) if no distro should be enforced, instead of exporting it empty.","Fix the upstream script/config that produces the empty value."],"exampleFix":"// before\nexport ASTRID_ENFORCED_DISTRO=\"\"\nastrid init\n// after\nunset ASTRID_ENFORCED_DISTRO\n# or\nexport ASTRID_ENFORCED_DISTRO=\"internal/my-distro\"","handlingStrategy":"validation","validationCode":"let enforced = std::env::var(\"ASTRID_ENFORCED_DISTRO\").unwrap_or_default();\nif enforced.is_empty() && std::env::var_os(\"ASTRID_ENFORCED_DISTRO\").is_some() {\n    return Err(\"ASTRID_ENFORCED_DISTRO is set but empty; unset it or give it a value\".into());\n}","typeGuard":"fn has_valid_enforced_distro() -> bool {\n    std::env::var(\"ASTRID_ENFORCED_DISTRO\")\n        .map(|v| !v.is_empty())\n        .unwrap_or(true) // unset is fine; empty is not\n}","tryCatchPattern":"match astrid::init(opts) {\n    Err(e) if e.to_string().contains(\"ASTRID_ENFORCED_DISTRO must not be empty\") => {\n        eprintln!(\"unset ASTRID_ENFORCED_DISTRO or set a non-empty distro source\");\n    }\n    other => other?,\n}","preventionTips":["Use `unset VAR` instead of `export VAR=\"\"` to remove enforcement.","Validate the variable in shell profiles/scripts before invoking astrid.","Check that scripts generating the value from files/commands fail loudly when the source is empty."],"tags":["env-var","config","cli"],"backgroundTag":"invalid-env-var-value","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"}