{"record":{"id":"fe98472166cc98a4","repo":"flxzt/rnote","slug":"failed-to-get-filename-from-the-supplied-file","errorCode":null,"errorMessage":"Failed to get filename from the supplied file '{}'","messagePattern":"Failed to get filename from the supplied file '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-cli/src/create.rs","lineNumber":12,"sourceCode":"// Imports\nuse crate::cli;\nuse rnote_engine::Engine;\nuse std::path::Path;\n\npub(crate) async fn run_create(rnote_file: &Path) -> anyhow::Result<()> {\n    let engine = Engine::default();\n    let Some(rnote_file_name) = rnote_file\n        .file_name()\n        .map(|s| s.to_string_lossy().to_string())\n    else {\n        return Err(anyhow::anyhow!(\n            \"Failed to get filename from the supplied file '{}'\",\n            rnote_file.display()\n        ));\n    };\n    let rnote_bytes = engine.save_as_rnote_bytes(rnote_file_name).await??;\n    cli::create_overwrite_file_w_bytes(rnote_file, &rnote_bytes).await?;\n    Ok(())\n}\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-cli/src/create.rs#L1-L21","documentation":"run_create builds a fresh empty rnote document and saves it to the path supplied on the command line. Before saving it extracts the file name component via Path::file_name(); if the path has no file name component (e.g. it terminates in '..' or is the filesystem root), there is no name to embed in the document, so it aborts with this error. The '{}' in the message is a template placeholder; the actual path is interpolated via rnote_file.display().","triggerScenarios":"Calling `rnote create <path>` where <path> has no file_name(): a path ending in a trailing component like '.' or '..' (e.g. `rnote create ..` or `rnote create foo/..`), or the root path `/`. Also any odd path (e.g. from shell expansion) that normalizes to a non-file component.","commonSituations":"Shell scripts building paths with string concatenation that end in '/' or '..'; users typo-ing the target as a directory instead of a file; running in a root-like directory where '.' resolves to the filesystem root.","solutions":["Pass a concrete file path with a real file name, e.g. `rnote create notes.rnote` instead of a directory or '..' path.","Normalize the path in the shell before invoking (e.g. use realpath/dirname) so it terminates in a file name.","In code, guard with Path::file_name().is_some() before calling run_create and surface a clearer message."],"exampleFix":"// before\nrnote create foo/..\n// after\nrnote create foo/notes.rnote","handlingStrategy":"validation","validationCode":"let path = std::path::Path::new(arg);\nif path.file_name().is_none() {\n    eprintln!(\"'{}' does not name a file (no filename component)\", arg);\n    std::process::exit(2);\n}","typeGuard":"fn has_file_name(p: &std::path::Path) -> bool { p.file_name().is_some() }","tryCatchPattern":null,"preventionTips":["Never point create at directories, '.', '..' or root paths.","Use canonicalized paths that end in a real file name.","Validate paths in wrapper scripts before calling rnote."],"tags":["cli","path","invalid-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"bbc5354502ba2fc83eec2670b535348825e679a6","analyzedAt":"2026-09-08T13:20:33.747Z","contentChangedAt":"2026-09-08T13:20:33.747Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}