flxzt/rnote · error
Failed to get file name from output-file
Error message
Failed to get file name from output-file "{}". What it means
export_to_file failed to derive an export file name from the --output-file path. Path::file_name() returns None only when the path terminates in '..' or is the root, so the CLI refuses to guess a name for the exported document.
Solutions
- Pass a concrete file path with a final component (e.g. 'out/doc.rnote'), not a path ending in '..' or '/'
- Normalize the path in a wrapper script before invoking the CLI (realpath)
- Check the output path with Path::file_name().is_some() before calling the export command
Example fix
// before rnote-cli export doc --output-file out/.. // after rnote-cli export doc --output-file out/doc.rnote
Defensive patterns
Strategy: validation
Validate before calling
fn has_file_name(p: &Path) -> bool { p.file_name().is_some() }
if !has_file_name(output_file) { eprintln!("--output-file must end in a real file name"); std::process::exit(2); } Type guard
fn is_valid_output_path(p: &Path) -> bool {
p.file_name().is_some() && !p.is_dir()
} Try / catch
match export_result {
Err(e) if e.to_string().contains("Failed to get file name") => {
eprintln!("Invalid --output-file path; provide a path ending in a file name");
}
Err(e) => return Err(e),
Ok(bytes) => { /* write bytes */ }
} Prevention
- Always pass output paths ending in a concrete file name
- Avoid trailing '..' or '/' in path arguments
- Normalize paths with canonicalize/realpath in scripts
When it happens
Trigger: Running `rnote-cli export doc` with an output-file path ending in '..' (e.g. 'out/..') or pointing at the filesystem root, so Path::file_name() yields None.
Common situations: Shell-expanded paths like '--output-file $dir/..' meant to target a directory; scripts constructing paths by naive string concatenation that end with a trailing '..' or '/'.
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
- Failed to get file stem from rnote file
- Failed to get filename from the supplied file
- Failed to get file stem
- Failed to get filename from rnote_file
- Expected directory, found file
AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08).
Data as JSON: /api/errors/6e7be0e4c94678e9.
Report an issue: GitHub.
Appendix: source
Thrown at crates/rnote-cli/src/export.rs:571
..
} => {
select_strokes_for_selection_args(engine, selection, *selection_collision);
let export_bytes = engine
.export_selection(None)
.await??
.context("Exporting selection failed, no strokes selected.")?;
cli::create_overwrite_file_w_bytes(&output_file, &export_bytes).await?;
if open {
cli::open_file_default_app(output_file)?;
}
}
cli::ExportCommand::Doc { .. } => {
let Some(export_file_name) = output_file
.as_ref()
.file_name()
.map(|s| s.to_string_lossy().to_string())
else {
return Err(anyhow::anyhow!(
"Failed to get file name from output-file \"{}\".",
output_file.as_ref().display()
));
};
let export_bytes = engine.export_doc(export_file_name, None).await??;
cli::create_overwrite_file_w_bytes(&output_file, &export_bytes).await?;
if open {
cli::open_file_default_app(output_file)?;
}
}
cli::ExportCommand::DocPages {
output_dir,
output_file_stem,
export_format: output_format,
..
} => {
validators::path_is_dir(output_dir)?;
// The output file cannot be set with this subcommandView on GitHub (pinned to bbc5354502)