{"record":{"id":"ad0adfd72f64492d","repo":"astrid-runtime/astrid","slug":"invalid-value-for-capsule-id-key-expected-one-ad0adf","errorCode":null,"errorMessage":"invalid value for {capsule_id}.{key}: expected one of {}, got {value:?}","messagePattern":"invalid value for (.+?)\\.(.+?): expected one of (.+?), got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/capsule/install_prompts.rs","lineNumber":195,"sourceCode":"            std::env::var(&env_key)\n                .ok()\n                .or_else(|| def.default.as_ref().map(json_value_string))\n                .ok_or_else(|| {\n                    anyhow::anyhow!(\n                        \"required value is missing for {capsule_id}.{key} \\\n                         (use --var {key}=… or set {env_key})\"\n                    )\n                })?\n        } else {\n            if !prompted {\n                eprintln!(\"\\nThis capsule requires configuration:\");\n                prompted = true;\n            }\n            prompt_single_field(&key, def, &collected)\n        };\n\n        if !def.enum_values.is_empty() && !def.enum_values.iter().any(|item| item == &value) {\n            anyhow::bail!(\n                \"invalid value for {capsule_id}.{key}: expected one of {}, got {value:?}\",\n                def.enum_values.join(\", \")\n            );\n        }\n        if def.env_type != \"secret\" && !value.is_empty() {\n            super::local_egress::maybe_prompt_local_egress(capsule_id, &value, config_path);\n        }\n        collected.insert(key.clone(), serde_json::Value::String(value.clone()));\n        values.push(format!(\"{key}={value}\"));\n    }\n\n    if prompted {\n        eprintln!(\"  Configuration will be applied by the daemon.\\n\");\n    }\n    Ok(values)\n}\n\n/// Prompt the user for missing environment-variable values defined in `[env]`.","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/capsule/install_prompts.rs#L177-L213","documentation":"Raised by `collect_install_env_fields` in the capsule installer when a value supplied for a declared `[env]` field fails the field's enum check. Capsule definitions can declare `enum_values` for an env field; before staging the configuration for the daemon-owned install transaction, every value (from `--var`, headless env vars, defaults, or interactive prompt) must exactly match one of the declared options. The library throws this so invalid capsule configuration never reaches the daemon install hook.","triggerScenarios":"Running `astrid capsule install` for a capsule whose EnvDef declares `enum_values`, while the resolved value for that key (via `--var key=value`, the headless env variable, the field default, or a prompted answer) is not an exact string match of any declared enum value. Also triggered by tests install_collection_replaces_explicit_existing_and_preserves_other_existing and install_collection_rejects_undeclared_and_invalid_enum_values.","commonSituations":"Typo in a `--var` value (e.g. `log-level=INFO` when options are `debug,info,warn,error`); wrong casing since matching is case-sensitive; capsule manifest was updated to a new set of allowed options while the user reuses an old value; an old default baked into CI env vars.","solutions":["Read the list of allowed values from the error message ('expected one of ...') and pass an exact match, e.g. `--var <key>=<allowed-value>`.","Check the capsule's `[env]` definition for the field's `enum_values`/options and its casing; matching is exact string equality.","If the value used to be valid, the capsule manifest changed — update your scripts/CI to the new allowed set or pin the older capsule version.","If you believe the value should be legal, ask the capsule author to add it to the field's enum_values and reinstall."],"exampleFix":"// before\nastrid capsule install my-capsule --var log-level=VERBOSE\n// error: invalid value for my-capsule.log-level: expected one of debug, info, warn, error, got \"VERBOSE\"\n\n// after\nastrid capsule install my-capsule --var log-level=error","handlingStrategy":"validation","validationCode":"let allowed = env_def.enum_values;\nif !allowed.is_empty() && !allowed.iter().any(|v| v == value) {\n    eprintln!(\"{key} must be one of: {}\", allowed.join(\", \"));\n    std::process::exit(2);\n}","typeGuard":"fn is_valid_enum_value(value: &str, def: &EnvDef) -> bool {\n    def.enum_values.is_empty() || def.enum_values.iter().any(|item| item == value)\n}","tryCatchPattern":"match collect_install_env_fields(...) {\n    Ok(values) => install(values),\n    Err(e) if e.to_string().contains(\"invalid value for\") => {\n        eprintln!(\"{e:#}\\nFix with: --var <key>=<allowed-value>\");\n        std::process::exit(2);\n    },\n    Err(e) => return Err(e),\n}","preventionTips":["Echo the field's allowed options before prompting or scripting values.","Keep `--var` values for enum fields in checked-in scripts so casing/typos are fixed once.","When a capsule updates, diff its [env] enum_values against the values your CI supplies.","Use tab-completion or interactive prompting instead of hand-typing enum values."],"tags":["cli","config","validation"],"backgroundTag":"invalid-enum-value","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"}