flxzt/rnote · error

Failed to get filename from rnote_file

Error message

Failed to get filename from rnote_file

What it means

import_file could not extract a file name from the target rnote_file path, which is required as the document title when saving the imported XOPP as .rnote bytes. The error is raised when Path::file_name() returns None.

Solutions

  1. Pass an explicit destination file path like 'out/imported.rnote' rather than a directory or '..'-terminated path
  2. Validate the target path has a file name component before invoking import
  3. Use a path normalization step (realpath/canonicalize) in scripts

Example fix

// before
rnote-cli import drawing.xopp out/
// after
rnote-cli import drawing.xopp out/imported.rnote
Defensive patterns

Strategy: validation

Validate before calling

if rnote_file.file_name().is_none() || rnote_file.is_dir() {
    eprintln!("rnote-file target must be a file path with a name");
    std::process::exit(2);
}

Type guard

fn is_valid_target(p: &Path) -> bool {
    p.file_name().is_some() && !p.is_dir()
}

Try / catch

match import_result {
    Err(e) if e.to_string().contains("Failed to get filename from rnote_file") => {
        eprintln!("Pass a destination file path like out/imported.rnote");
    }
    other => other,
}

Prevention

When it happens

Trigger: Running `rnote-cli import` with an rnote-file target path of '/', a path ending in '..', or otherwise lacking a final component, after successfully loading the XOPP bytes.

Common situations: Scripts writing imports into computed directory paths and accidentally passing the directory instead of the destination file; shell expansions collapsing to the root.

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


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

Appendix: source

Thrown at crates/rnote-cli/src/import.rs:62

    Ok(())
}

pub(crate) fn apply_import_prefs(config: &EngineConfigShared, xopp_dpi: f64) -> anyhow::Result<()> {
    config.write().import_prefs.xopp_import_prefs.dpi = xopp_dpi;
    Ok(())
}

pub(crate) async fn import_file(
    engine: &mut Engine,
    config: &EngineConfigShared,
    input_file: &Path,
    rnote_file: &Path,
) -> anyhow::Result<()> {
    let Some(rnote_file_name) = rnote_file
        .file_name()
        .map(|s| s.to_string_lossy().to_string())
    else {
        return Err(anyhow::anyhow!("Failed to get filename from rnote_file"));
    };
    let input_bytes = cli::read_bytes_from_file(&input_file).await?;
    let xopp_import_prefs = config.read().import_prefs.xopp_import_prefs;
    let snapshot = EngineSnapshot::load_from_xopp_bytes(input_bytes, xopp_import_prefs).await?;
    let _ = engine.load_snapshot(snapshot);
    let rnote_bytes = engine.save_as_rnote_bytes(rnote_file_name).await??;
    cli::create_overwrite_file_w_bytes(&rnote_file, &rnote_bytes).await?;

    Ok(())
}

View on GitHub (pinned to bbc5354502)