flxzt/rnote · error
Expected file, found directory
Error message
Expected file, found directory "{}" What it means
Sentinel validation guard in path_is_file: the given path exists but is a directory, not a regular file, so it fails the file-type check. Fires whenever a CLI argument expected to be a file (e.g. an .rnote input) resolves to a directory.
Solutions
- Pass the path to the actual file, not its containing directory
- Verify the file exists (ls / Path::is_file) before running the command
- Fix the typo or path in scripts; note the tool will not create missing inputs
Example fix
// before rnote-cli export --rnote-file ./notes/ // after rnote-cli export --rnote-file ./notes/sketch.rnote
Defensive patterns
Strategy: validation
Validate before calling
let p = std::path::Path::new(input);
if !p.is_file() {
eprintln!("{} is not a regular file", input);
std::process::exit(2);
} Type guard
fn is_existing_file(p: &Path) -> bool {
p.is_file()
} Try / catch
match result {
Err(e) if e.to_string().contains("Expected file, found directory") => {
eprintln!("Input must be a file, not a directory; check the path");
}
other => other,
} Prevention
- Verify input paths point to real files before invoking
- Avoid tab-completing to directories for file arguments
- Check for typos in file names
When it happens
Trigger: Passing a directory or nonexistent path to an argument validated with path_is_file, such as the input .rnote or .xopp file path.
Common situations: Tab-completion selecting the parent directory; expecting the tool to create the file; typos in the file name.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Expected directory, found file
- Failed to get file name from output-file
- Failed to get file stem from rnote file
- Expected file with extension
- Expected file with extension
AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08).
Data as JSON: /api/errors/7fb5b7a81f6cf261.
Report an issue: GitHub.
Appendix: source
Thrown at crates/rnote-cli/src/validators.rs:15
use std::path::Path;
pub(crate) fn path_is_dir(path: &Path) -> anyhow::Result<()> {
if !path.is_dir() {
return Err(anyhow::anyhow!(
"Expected directory, found file \"{}\"",
path.display()
));
}
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)