ClementTsang/bottom · error
invalid path
Error message
invalid path: {e:?} What it means
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.
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
Example fix
// before
let usage = partition.usage()?;
// after
let mp = partition.mount_point();
if mp.to_str().map_or(true, |s| s.contains('\0')) {
eprintln!("skipping partition with invalid mount point: {mp:?}");
} else {
let usage = partition.usage()?;
} Defensive patterns
Strategy: validation
Validate before calling
fn usable_mount_point(mp: &std::path::Path) -> bool {
mp.to_str().map_or(false, |s| !s.contains('\0'))
}
if !usable_mount_point(partition.mount_point()) {
eprintln!("skipping partition with non-UTF-8 mount point");
} else {
let usage = partition.usage()?;
} Type guard
fn valid_c_string_path(mp: &std::path::Path) -> Option<std::ffi::CString> {
mp.to_str().ok()?.contains('\0').not()
.then(|| std::ffi::CString::new(mp.as_os_str().as_encoded_bytes().to_vec()).ok())
.flatten()
} Try / catch
match partition.usage() {
Ok(u) => handle(u),
Err(e) if e.to_string().starts_with("invalid path") => {
eprintln!("skipping partition: {e}")
}
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- statvfs had an issue getting info from
- missing filesystem type
- statvfs failed to get the disk usage for disk
- Unable to open zfs proc directory
- Unsupported OS
AI-assisted analysis of ClementTsang/bottom@b77d317502 (2026-09-07).
Data as JSON: /api/errors/af83ecc5ce1f6478.
Report an issue: GitHub.
Appendix: source
Thrown at src/collection/disks/unix/linux/partition.rs:87
} else {
device.to_owned()
}
} else {
"Name Unavailable".to_string()
}
}
/// Returns the usage stats for this partition.
pub fn usage(&self) -> anyhow::Result<Usage> {
// TODO: This might be unoptimal.
let path = self
.mount_point
.to_str()
.ok_or_else(|| io::Error::from(io::ErrorKind::InvalidInput))
.and_then(|string| {
CString::new(string).map_err(|_| io::Error::from(io::ErrorKind::InvalidInput))
})
.map_err(|e| anyhow::anyhow!("invalid path: {e:?}"))?;
let mut vfs = mem::MaybeUninit::<libc::statvfs>::uninit();
// SAFETY: libc call, `path` is a valid C string and buf is a valid
// pointer to write to.
let result = unsafe { libc::statvfs(path.as_ptr(), vfs.as_mut_ptr()) };
if result == 0 {
// SAFETY: If result is 0, it succeeded, and vfs should be non-null.
let vfs = unsafe { vfs.assume_init() };
Ok(Usage::new(vfs))
} else {
Err(anyhow::anyhow!(
"statvfs had an issue getting info from {path:?}"
))
}
}
}View on GitHub (pinned to b77d317502)