{"record":{"id":"af83ecc5ce1f6478","repo":"ClementTsang/bottom","slug":"invalid-path-e","errorCode":null,"errorMessage":"invalid path: {e:?}","messagePattern":"invalid path: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/collection/disks/unix/linux/partition.rs","lineNumber":87,"sourceCode":"            } else {\n                device.to_owned()\n            }\n        } else {\n            \"Name Unavailable\".to_string()\n        }\n    }\n\n    /// Returns the usage stats for this partition.\n    pub fn usage(&self) -> anyhow::Result<Usage> {\n        // TODO: This might be unoptimal.\n        let path = self\n            .mount_point\n            .to_str()\n            .ok_or_else(|| io::Error::from(io::ErrorKind::InvalidInput))\n            .and_then(|string| {\n                CString::new(string).map_err(|_| io::Error::from(io::ErrorKind::InvalidInput))\n            })\n            .map_err(|e| anyhow::anyhow!(\"invalid path: {e:?}\"))?;\n\n        let mut vfs = mem::MaybeUninit::<libc::statvfs>::uninit();\n\n        // SAFETY: libc call, `path` is a valid C string and buf is a valid\n        // pointer to write to.\n        let result = unsafe { libc::statvfs(path.as_ptr(), vfs.as_mut_ptr()) };\n\n        if result == 0 {\n            // SAFETY: If result is 0, it succeeded, and vfs should be non-null.\n            let vfs = unsafe { vfs.assume_init() };\n            Ok(Usage::new(vfs))\n        } else {\n            Err(anyhow::anyhow!(\n                \"statvfs had an issue getting info from {path:?}\"\n            ))\n        }\n    }\n}","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/ClementTsang/bottom/blob/b77d3175028849824e987c35177e8f61450d72e7/src/collection/disks/unix/linux/partition.rs#L69-L105","documentation":"Raised in the public `usage()` of a Linux disk partition. The mount point (a `Path`/OsStr) is converted to a UTF-8 str and then to a `CString` for the `libc::statvfs` call; any failure in either conversion (non-UTF-8 path, or path containing an interior NUL byte) is turned into `io::ErrorKind::InvalidInput` and then formatted as `invalid path: {e:?}`. This means statvfs could not even be invoked because the mount point is not a valid C string.","triggerScenarios":"`usage()` called on a partition whose mount point contains non-UTF-8 bytes (OsStr on Linux is raw bytes) or an embedded NUL byte, so `to_str()` or `CString::new` fails.","commonSituations":"Mount points with weird bytes in their names (rare but possible on Linux since paths need not be UTF-8); filesystems mounted at paths created with control characters; running on unusual/loopback mounts with malformed mount entries in /proc/mounts.","solutions":["Inspect the partition's mount_point bytes and fix the source of the non-UTF-8/NUL path (rename the mount point or correct the mount)","If you control the path, ensure it is valid UTF-8 without interior NULs before using this API","Skip or filter partitions whose mount points fail `Path::to_str()` on your side before calling `usage()`","Use lossy handling (`to_string_lossy`) only for display; for statvfs you must drop or fix such paths"],"exampleFix":"// before\nlet usage = partition.usage()?;\n// after\nlet mp = partition.mount_point();\nif mp.to_str().map_or(true, |s| s.contains('\\0')) {\n    eprintln!(\"skipping partition with invalid mount point: {mp:?}\");\n} else {\n    let usage = partition.usage()?;\n}","handlingStrategy":"validation","validationCode":"fn usable_mount_point(mp: &std::path::Path) -> bool {\n    mp.to_str().map_or(false, |s| !s.contains('\\0'))\n}\n\nif !usable_mount_point(partition.mount_point()) {\n    eprintln!(\"skipping partition with non-UTF-8 mount point\");\n} else {\n    let usage = partition.usage()?;\n}","typeGuard":"fn valid_c_string_path(mp: &std::path::Path) -> Option<std::ffi::CString> {\n    mp.to_str().ok()?.contains('\\0').not()\n        .then(|| std::ffi::CString::new(mp.as_os_str().as_encoded_bytes().to_vec()).ok())\n        .flatten()\n}","tryCatchPattern":"match partition.usage() {\n    Ok(u) => handle(u),\n    Err(e) if e.to_string().starts_with(\"invalid path\") => {\n        eprintln!(\"skipping partition: {e}\")\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check mount_point().to_str().is_some() before calling usage()","Skip partitions with non-UTF-8 or NUL-containing mount points","Fix/rename mount points containing unusual bytes at the system level","Treat such partitions as unmonitorable rather than failing the whole sweep"],"tags":["linux","disks","filesystem","path","statvfs"],"backgroundTag":"invalid-argument-format","analyzedSha":"b77d3175028849824e987c35177e8f61450d72e7","analyzedAt":"2026-09-07T14:53:21.246Z","contentChangedAt":"2026-09-07T14:53:21.246Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}