flxzt/rnote · error

Expected directory, found file

Error message

Expected directory, found file "{}"

What it means

The path_is_dir validator rejects any path that is not an existing directory. It exists so CLI commands that require an output/input directory fail early with a clear message instead of writing into a wrong location.

Solutions

  1. Create the directory first (mkdir -p) before running the command
  2. Point the argument at the intended directory instead of a file
  3. Check with `test -d <path>` or std::path::Path::is_dir() in wrapper scripts before invoking

Example fix

// before
rnote-cli export batch --output-dir out/result.rnote
// after
mkdir -p out/result && rnote-cli export batch --output-dir out/result
Defensive patterns

Strategy: validation

Validate before calling

if !std::path::Path::new(dir).is_dir() {
    std::fs::create_dir_all(dir)?;
}

Type guard

fn is_existing_dir(p: &Path) -> bool {
    p.is_dir()
}

Try / catch

match result {
    Err(e) if e.to_string().contains("Expected directory") => {
        eprintln!("{} is not a directory; create it or point at a directory", dir);
    }
    other => other,
}

Prevention

When it happens

Trigger: Passing a path that exists as a regular file (or does not exist at all, since is_dir() is false) to an argument validated with path_is_dir.

Common situations: Swapping the order of file and directory CLI arguments; typos pointing at a sibling file; expected directory not yet created so is_dir() is false.

Related errors


AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08). Data as JSON: /api/errors/adc63a5b6eea9409. Report an issue: GitHub.

Appendix: source

Thrown at crates/rnote-cli/src/validators.rs:5

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<()> {

View on GitHub (pinned to bbc5354502)