flxzt/rnote · error
Expected file with extension
Error message
Expected file with extension "{expected_ext}", found extension "{ext:?}", file "{}". What it means
file_has_ext found the file but its extension does not match the expected one (e.g. an input was expected to be '.xopp' but had a different extension). The actual extension is included in the message via Debug formatting.
Solutions
- Rename or re-export the file with the correct extension (e.g. mv drawing.txt drawing.xopp only if it truly is a XOPP file)
- Double-check which command expects which format and pass the matching file
- Verify the extension in scripts with Path::extension() before invoking
Example fix
// before rnote-cli import sketch.rnote out.rnote # expects .xopp // after rnote-cli import sketch.xopp out.rnote
Defensive patterns
Strategy: validation
Validate before calling
fn has_ext(p: &Path, ext: &str) -> bool {
p.extension().map_or(false, |e| e == ext)
}
assert!(has_ext(Path::new("sketch.xopp"), "xopp")); Type guard
fn is_xopp(p: &Path) -> bool {
p.extension().map_or(false, |e| e == "xopp")
} Try / catch
match result {
Err(e) if e.to_string().contains("found extension") => {
eprintln!("Wrong file type; the command expects a different extension");
}
other => other,
} Prevention
- Check the extension matches the command's expected format before running
- Don't blind-rename files to fix extension errors; confirm actual format
- Keep rnote and xopp inputs clearly separated in scripts
When it happens
Trigger: Supplying a file with the wrong extension to an argument validated with file_has_ext(path, "xopp") — e.g. renaming a PDF to .xopp, or passing an .rnote file where .xopp is required.
Common situations: Files downloaded without extensions; manual renames; mixing up the rnote and xopp inputs on import/export commands.
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
- Expected file with extension
- The output file " " needs to have a supported extension to…
- Expected directory, found file
- Expected file, found directory
- Failed to get filename from the supplied file
AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08).
Data as JSON: /api/errors/1ec90d607ec549c3.
Report an issue: GitHub.
Appendix: source
Thrown at crates/rnote-cli/src/validators.rs:27
}
Ok(())
}
pub(crate) fn path_is_file(path: &Path) -> anyhow::Result<()> {
if !path.is_file() {
return Err(anyhow::anyhow!(
"Expected file, found directory \"{}\"",
path.display()
));
}
Ok(())
}
pub(crate) fn file_has_ext(path: &Path, expected_ext: &str) -> anyhow::Result<()> {
path_is_file(path)?;
match path.extension() {
Some(ext) if ext == expected_ext => Ok(()),
Some(ext) => Err(anyhow::anyhow!(
"Expected file with extension \"{expected_ext}\", found extension \"{ext:?}\", file \"{}\".",
path.display()
)),
None => Err(anyhow::anyhow!(
"Expected file with extension \"{expected_ext}\", no extension found for file \"{}\".",
path.display()
)),
}
}
View on GitHub (pinned to bbc5354502)