sigoden/dufs · error · anyhow::Error
Failed to get file name of
Error message
Failed to get file name of `{}` What it means
Error from the try_get_file_name helper in utils.rs: `Path::file_name()` returned None or the final component is not valid UTF-8, so no usable file name can be extracted. It fires for paths like `..`, `/`, or paths ending in non-UTF-8 bytes, and propagates out of handle_zip_dir and handle_send_file when building zips or file responses.
Solutions
- Ensure the requested path refers to an actual file with a valid name, not the root or `..`
- Avoid non-UTF-8 file names in the served directory, or rename them
- Use get_file_name (returns empty string) if a best-effort name is acceptable
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/utils.rs:37 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of sigoden/dufs@fe7fd564f8 (2026-09-09).
Data as JSON: /api/errors/245b9c4d91d0caad.
Report an issue: GitHub.
Appendix: source
Thrown at src/utils.rs:37
parts.join("/")
}
pub fn decode_uri(v: &str) -> Option<Cow<'_, str>> {
percent_encoding::percent_decode(v.as_bytes())
.decode_utf8()
.ok()
}
pub fn get_file_name(path: &Path) -> &str {
path.file_name()
.and_then(|v| v.to_str())
.unwrap_or_default()
}
pub fn try_get_file_name(path: &Path) -> Result<&str> {
path.file_name()
.and_then(|v| v.to_str())
.ok_or_else(|| anyhow!("Failed to get file name of `{}`", path.display()))
}
pub fn glob(pattern: &str, target: &str) -> bool {
let pat = match ::glob::Pattern::new(pattern) {
Ok(pat) => pat,
Err(_) => return false,
};
pat.matches(target)
}
// Load public certificate from file.
#[cfg(feature = "tls")]
pub fn load_certs<T: AsRef<Path>>(file_name: T) -> Result<Vec<CertificateDer<'static>>> {
let mut certs = vec![];
for cert in CertificateDer::pem_file_iter(file_name.as_ref()).with_context(|| {
format!(
"Failed to load cert file at `{}`",
file_name.as_ref().display()View on GitHub (pinned to fe7fd564f8)