{"record":{"id":"58776436d199c41d","repo":"denisidoro/navi","slug":"unable-to-parse-path","errorCode":null,"errorMessage":"Unable to parse {path}","messagePattern":"Unable to parse (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/common/fs.rs","lineNumber":116,"sourceCode":"            if CONFIG.forward_slash_path() {\n                exe.replace(\"\\\\\", \"/\")\n            } else {\n                exe\n            }\n        })\n        .unwrap_or_else(|_| \"navi\".to_string())\n}\n\n#[cfg(not(target_family = \"windows\"))]\npub fn exe_string() -> String {\n    exe_abs_string().unwrap_or_else(|_| \"navi\".to_string())\n}\n\npub fn create_dir<P: AsRef<Path>>(path: P) -> Result<()> {\n    create_dir_all(path.as_ref()).with_context(|| {\n        format!(\n            \"Failed to create directory `{}`\",\n            pathbuf_to_string(path).expect(\"Unable to parse {path}\")\n        )\n    })\n}\n\npub fn remove_dir<P: AsRef<Path>>(path: P) -> Result<()> {\n    remove_dir_all(path.as_ref()).with_context(|| {\n        format!(\n            \"Failed to remove directory `{}`\",\n            pathbuf_to_string(path).expect(\"Unable to parse {path}\")\n        )\n    })\n}\n","sourceCodeStart":98,"sourceCodeEnd":129,"githubUrl":"https://github.com/denisidoro/navi/blob/f7330b9ad5bd95b7d1a3c96d00e0a77deb589147/src/common/fs.rs#L98-L129","documentation":"`fs::create_dir` wraps `create_dir_all` and builds a context message containing the path. Converting the path to a displayable string uses `pathbuf_to_string(...).expect(...)`, which panics with \"Unable to parse {path}\" when the path cannot be rendered (e.g. non-UTF-8 bytes in the path on Unix).","triggerScenarios":"Calling `fs::create_dir` with a path whose OsStr contains invalid UTF-8 (so `to_str()` returns None) AND whose creation also fails, triggering the context closure that formats the message.","commonSituations":"Paths derived from file names with arbitrary bytes, bad encodings from external tools, or filesystems that allow non-UTF-8 names; usually combined with a permission/disk error that made `create_dir_all` fail in the first place.","solutions":["Ensure the path you pass contains only valid UTF-8 (sanitize or rename offending directories)","Fix the underlying directory-creation failure (permissions, existing file at path, full disk) so the panic closure never runs","Use `to_string_lossy()` instead of `expect` in library code to render non-UTF-8 paths safely","Inspect the path with `Path::display()` or debug formatting to find the offending bytes"],"exampleFix":"// before\npathbuf_to_string(path).expect(\"Unable to parse {path}\")\n// after\npathbuf_to_string(path).unwrap_or_else(|_| path.as_ref().display().to_string())","handlingStrategy":"validation","validationCode":"fn ensure_utf8_path(p: &std::path::Path) -> Result<(), String> {\n    p.to_str().ok_or_else(|| format!(\"path {:?} is not valid UTF-8\", p)).map(|_| ())\n}\n// call before fs::create_dir\nensure_utf8_path(&my_path)?;","typeGuard":"fn is_utf8_path(p: &std::path::Path) -> bool {\n    p.to_str().is_some()\n}","tryCatchPattern":"// create_dir panics only when creation fails AND the path is non-UTF-8;\n// wrap with catch_unwind if you must:\nlet result = std::panic::catch_unwind(|| fs::create_dir(&path));\nmatch result {\n    Ok(Ok(())) => {},\n    _ => eprintln!(\"create_dir failed (check path encoding and permissions)\"),\n}","preventionTips":["Sanitize externally sourced paths to valid UTF-8 before filesystem calls","Prefer Path::display()/to_string_lossy when logging paths","Fix root causes of creation failure (permissions, disk space) so context closures never run","Reject non-UTF-8 filenames at ingestion boundaries"],"tags":["rust","panic","filesystem","non-utf8"],"backgroundTag":"invalid-path-encoding","analyzedSha":"f7330b9ad5bd95b7d1a3c96d00e0a77deb589147","analyzedAt":"2026-09-03T13:58:22.429Z","contentChangedAt":"2026-09-03T13:58:22.429Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}