{"record":{"id":"adc63a5b6eea9409","repo":"flxzt/rnote","slug":"expected-directory-found-file","errorCode":null,"errorMessage":"Expected directory, found file \"{}\"","messagePattern":"Expected directory, found file \"(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-cli/src/validators.rs","lineNumber":5,"sourceCode":"use std::path::Path;\n\npub(crate) fn path_is_dir(path: &Path) -> anyhow::Result<()> {\n    if !path.is_dir() {\n        return Err(anyhow::anyhow!(\n            \"Expected directory, found file \\\"{}\\\"\",\n            path.display()\n        ));\n    }\n    Ok(())\n}\n\npub(crate) fn path_is_file(path: &Path) -> anyhow::Result<()> {\n    if !path.is_file() {\n        return Err(anyhow::anyhow!(\n            \"Expected file, found directory \\\"{}\\\"\",\n            path.display()\n        ));\n    }\n    Ok(())\n}\n\npub(crate) fn file_has_ext(path: &Path, expected_ext: &str) -> anyhow::Result<()> {","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-cli/src/validators.rs#L1-L23","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Create the directory first (mkdir -p) before running the command","Point the argument at the intended directory instead of a file","Check with `test -d <path>` or std::path::Path::is_dir() in wrapper scripts before invoking"],"exampleFix":"// before\nrnote-cli export batch --output-dir out/result.rnote\n// after\nmkdir -p out/result && rnote-cli export batch --output-dir out/result","handlingStrategy":"validation","validationCode":"if !std::path::Path::new(dir).is_dir() {\n    std::fs::create_dir_all(dir)?;\n}","typeGuard":"fn is_existing_dir(p: &Path) -> bool {\n    p.is_dir()\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"Expected directory\") => {\n        eprintln!(\"{} is not a directory; create it or point at a directory\", dir);\n    }\n    other => other,\n}","preventionTips":["Create output directories before running CLI commands","Double-check argument order (dir vs file) in scripts","Use shell checks like `test -d` before invocation"],"tags":["validation","filesystem","cli"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"bbc5354502ba2fc83eec2670b535348825e679a6","analyzedAt":"2026-09-08T13:20:33.747Z","contentChangedAt":"2026-09-08T13:20:33.747Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}