{"record":{"id":"e6a1cb75c78f9eef","repo":"jdx/mise","slug":"field-must-not-be-empty","errorCode":null,"errorMessage":"{field} must not be empty","messagePattern":"(.+?) must not be empty","errorType":"validation","errorClass":"eyre::Report","httpStatus":null,"severity":"error","filePath":"src/system/managed_files.rs","lineNumber":1394,"sourceCode":"    }\n    Ok(path)\n}\n\nfn parse_mode(mode: Option<&str>, default: u32) -> Result<u32> {\n    let Some(mode) = mode else {\n        return Ok(default);\n    };\n    let mode = mode.strip_prefix(\"0o\").unwrap_or(mode);\n    let parsed = u32::from_str_radix(mode, 8).wrap_err(\"mode must be an octal string\")?;\n    if parsed > 0o7777 {\n        bail!(\"mode must be between 0000 and 7777\");\n    }\n    Ok(parsed)\n}\n\nfn nonempty(field: &str, value: Option<String>) -> Result<Option<String>> {\n    match value {\n        Some(value) if value.trim().is_empty() => bail!(\"{field} must not be empty\"),\n        Some(value) => Ok(Some(value)),\n        None => Ok(None),\n    }\n}\n\nfn desired_metadata(kind: &str, mode: u32, owner: Option<&str>, group: Option<&str>) -> String {\n    let mut desired = format!(\"{kind} mode {mode:04o}\");\n    if let Some(owner) = owner {\n        desired.push_str(&format!(\" owner {owner}\"));\n    }\n    if let Some(group) = group {\n        desired.push_str(&format!(\" group {group}\"));\n    }\n    desired\n}\n\n#[cfg(unix)]\nfn metadata_matches(","sourceCodeStart":1376,"sourceCodeEnd":1412,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/managed_files.rs#L1376-L1412","documentation":"This error comes from the `nonempty` helper in managed_files.rs, which validates optional string fields (e.g. owner, group, content identifiers) used when managing system files. If a caller supplies Some(value) whose trimmed content is empty (empty string or whitespace only), the library rejects it because an empty field is meaningless for file management operations. `None` is treated as 'not specified' and is accepted.","triggerScenarios":"Calling any managed-files API that passes an optional string field through `nonempty` with Some(\"\") or Some(\"   \") — e.g. setting an owner/group to an empty string, or parsing a manifest that declares a field with an empty value.","commonSituations":"Templated or generated config files where a variable expands to empty (unset env var interpolated into owner field); hand-edited manifests with `owner = \"\"`; YAML/TOML parsers deserializing blank values into Some(\"\") instead of None.","solutions":["Remove the field entirely (or use null/None) instead of passing an empty string, so it is treated as unspecified","Provide the actual intended value (user name, group name, etc.)","Trim-check upstream: if the value comes from user input or env interpolation, reject or default empty input before calling the API"],"exampleFix":"// before\nlet opts = ManagedFileOptions { owner: Some(\"\".to_string()), ..Default::default() };\n// after\nlet opts = ManagedFileOptions { owner: Some(\"root\".to_string()), ..Default::default() };","handlingStrategy":"validation","validationCode":"fn ensure_nonempty(field: &str, value: &Option<String>) -> Result<(), String> {\n    match value {\n        Some(v) if v.trim().is_empty() => Err(format!(\"{field} must not be empty\")),\n        _ => Ok(()),\n    }\n}\nensure_nonempty(\"owner\", &opts.owner)?;","typeGuard":"fn is_present_nonempty(v: &Option<String>) -> bool {\n    v.as_deref().map_or(true, |s| !s.trim().is_empty())\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"must not be empty\") => {\n        // fall back to default / prompt user for a real value\n    }\n    other => other?,\n}","preventionTips":["Never pass Some(\"\") — use None to mean 'not specified'","Trim user/env-sourced strings before storing them in options","Add schema validation that rejects empty strings for these fields"],"tags":["validation","managed-files","empty-string"],"backgroundTag":"empty-required-field","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}