{"record":{"id":"326abf7b2ca79599","repo":"Hmbown/CodeWhale","slug":"kind-must-not-be-empty","errorCode":null,"errorMessage":"{kind} must not be empty","messagePattern":"(.+?) must not be empty","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/automation_manager.rs","lineNumber":2777,"sourceCode":"fn read_run_file(path: &Path) -> Result<AutomationRunRecord> {\n    let raw =\n        fs::read_to_string(path).with_context(|| format!(\"Failed to read {}\", path.display()))?;\n    let run: AutomationRunRecord = serde_json::from_str(&raw)\n        .with_context(|| format!(\"Failed to parse {}\", path.display()))?;\n    if run.schema_version > CURRENT_RUN_SCHEMA_VERSION {\n        bail!(\n            \"Automation run schema v{} is newer than supported v{}\",\n            run.schema_version,\n            CURRENT_RUN_SCHEMA_VERSION\n        );\n    }\n    Ok(run)\n}\n\nfn ensure_safe_storage_id(kind: &str, value: &str) -> Result<()> {\n    let mut components = Path::new(value).components();\n    let Some(component) = components.next() else {\n        bail!(\"{kind} must not be empty\");\n    };\n    if components.next().is_some() || !matches!(component, std::path::Component::Normal(_)) {\n        bail!(\"{kind} must be a single path component\");\n    }\n    Ok(())\n}\n\nfn validate_name_and_prompt(name: &str, prompt: &str) -> Result<()> {\n    if name.trim().is_empty() {\n        bail!(\"Automation name is required\");\n    }\n    if prompt.trim().is_empty() {\n        bail!(\"Automation prompt is required\");\n    }\n    Ok(())\n}\n\nfn normalize_optional_string(value: Option<String>) -> Option<String> {","sourceCodeStart":2759,"sourceCodeEnd":2795,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/automation_manager.rs#L2759-L2795","documentation":"ensure_safe_storage_id validates that a storage identifier (kind describes which field, e.g. automation id or run id) is usable as a filename. An empty string yields no first path component, so it is rejected with this error before it can produce an invalid or colliding storage path.","triggerScenarios":"Passing an empty string (or a value that Path::new sees as having no Normal components, like \"\" ) as an id to a save/load automation or run API.","commonSituations":"An id field left unset/empty in a deserialized record or UI form; trimming a name down to nothing before deriving an id; a generator bug producing empty ids.","solutions":["Ensure the id is generated/non-empty before calling the storage API (e.g. reject empty input in the caller or use a UUID).","Fix the form/deserialization path that produced an empty id.","Add a caller-side check that !id.is_empty() before persisting."],"exampleFix":"// before\nstore.save_run(\"\")?;\n// after\nif run_id.is_empty() { return Err(anyhow!(\"run id must not be empty\")); }\nstore.save_run(run_id)?;","handlingStrategy":"validation","validationCode":"if id.is_empty() || Path::new(id).components().next().is_none() {\n    return Err(anyhow!(\"{kind} must not be empty\"));\n}","typeGuard":"fn is_safe_storage_id(id: &str) -> bool {\n    let mut c = Path::new(id).components();\n    matches!(c.next(), Some(std::path::Component::Normal(_))) && c.next().is_none()\n}","tryCatchPattern":"match ensure_safe_storage_id(\"run id\", &id) {\n    Ok(()) => store.save_run(&id, run)?,\n    Err(e) => regenerate_id_and_retry(),\n}","preventionTips":["Generate ids with a UUID or slug generator instead of accepting free-form input.","Validate ids at the point of creation, not only at storage time.","Reject empty form fields before they become record ids."],"tags":["validation","storage","path"],"backgroundTag":"empty-required-field","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}