{"record":{"id":"d569ab030eae46af","repo":"astrid-runtime/astrid","slug":"keypair-name-must-not-be-empty","errorCode":null,"errorMessage":"keypair name must not be empty","messagePattern":"keypair name must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/keypair.rs","lineNumber":577,"sourceCode":"            public_hex: dir.join(format!(\"{name}.pub.hex\")),\n            meta: path,\n        };\n        match read_meta(&paths) {\n            Ok(meta) => out.push(KeyEntry { name, meta }),\n            Err(e) => {\n                tracing::warn!(name = %name, error = %e, \"skipping unreadable keypair meta\");\n            },\n        }\n    }\n    out.sort_by(|a, b| a.name.cmp(&b.name));\n    Ok(out)\n}\n\n// ── Misc helpers ─────────────────────────────────────────────────\n\nfn validate_name(name: &str) -> Result<()> {\n    if name.is_empty() {\n        bail!(\"keypair name must not be empty\");\n    }\n    if name.len() > MAX_NAME_LEN {\n        bail!(\n            \"keypair name must be at most {MAX_NAME_LEN} chars (got {})\",\n            name.len()\n        );\n    }\n    // Lowercase letters, digits, dash. Same posture as principal ids;\n    // also avoids path-separator / shell-meta surprises.\n    if !name\n        .chars()\n        .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-')\n    {\n        bail!(\"keypair name {name:?} contains invalid chars; only a-z, 0-9, '-' are allowed\");\n    }\n    Ok(())\n}\n","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/keypair.rs#L559-L595","documentation":"`validate_name` rejects an empty keypair name before any file operations. Names are used to build key file paths, so an empty string would produce invalid paths; this is the first of several name checks (length, charset).","triggerScenarios":"Calling keypair commands with --name \"\" or an argument that resolves to empty (e.g. an unset shell variable expanded to nothing), or code paths like load_public_key_hex/record_binding receiving an empty name.","commonSituations":"Shell scripts with unset variables: `--name \"$KP_NAME\"` where KP_NAME is empty; mis-parsed CLI args; programmatic callers passing an empty string.","solutions":["Pass a non-empty keypair name.","Omit --name entirely to use the default keypair name for generate.","Fix the shell variable/script so the name is set before invocation.","Validate inputs in automation before calling astrid."],"exampleFix":"// before\nastrid keypair show \"$KP_NAME\"   # KP_NAME empty\n// after\n: \"${KP_NAME:?KP_NAME must be set}\"\nastrid keypair show \"$KP_NAME\"","handlingStrategy":"validation","validationCode":"[ -n \"$KP_NAME\" ] || { echo \"keypair name required\" >&2; exit 2; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use ${VAR:?} guards in shell scripts for name variables","Omit --name to accept the default instead of passing empty","Validate CLI inputs in wrappers before invoking astrid"],"tags":["cli","validation","keypair"],"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-14T11:17:12.474Z"}