{"record":{"id":"8bde14d71e34a8e7","repo":"flxzt/rnote","slug":"failed-to-get-filename-from-rnote-file","errorCode":null,"errorMessage":"Failed to get filename from rnote_file","messagePattern":"Failed to get filename from rnote_file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-cli/src/import.rs","lineNumber":62,"sourceCode":"    Ok(())\n}\n\npub(crate) fn apply_import_prefs(config: &EngineConfigShared, xopp_dpi: f64) -> anyhow::Result<()> {\n    config.write().import_prefs.xopp_import_prefs.dpi = xopp_dpi;\n    Ok(())\n}\n\npub(crate) async fn import_file(\n    engine: &mut Engine,\n    config: &EngineConfigShared,\n    input_file: &Path,\n    rnote_file: &Path,\n) -> anyhow::Result<()> {\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!(\"Failed to get filename from rnote_file\"));\n    };\n    let input_bytes = cli::read_bytes_from_file(&input_file).await?;\n    let xopp_import_prefs = config.read().import_prefs.xopp_import_prefs;\n    let snapshot = EngineSnapshot::load_from_xopp_bytes(input_bytes, xopp_import_prefs).await?;\n    let _ = engine.load_snapshot(snapshot);\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\n    Ok(())\n}\n","sourceCodeStart":44,"sourceCodeEnd":73,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-cli/src/import.rs#L44-L73","documentation":"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.","triggerScenarios":"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.","commonSituations":"Scripts writing imports into computed directory paths and accidentally passing the directory instead of the destination file; shell expansions collapsing to the root.","solutions":["Pass an explicit destination file path like 'out/imported.rnote' rather than a directory or '..'-terminated path","Validate the target path has a file name component before invoking import","Use a path normalization step (realpath/canonicalize) in scripts"],"exampleFix":"// before\nrnote-cli import drawing.xopp out/\n// after\nrnote-cli import drawing.xopp out/imported.rnote","handlingStrategy":"validation","validationCode":"if rnote_file.file_name().is_none() || rnote_file.is_dir() {\n    eprintln!(\"rnote-file target must be a file path with a name\");\n    std::process::exit(2);\n}","typeGuard":"fn is_valid_target(p: &Path) -> bool {\n    p.file_name().is_some() && !p.is_dir()\n}","tryCatchPattern":"match import_result {\n    Err(e) if e.to_string().contains(\"Failed to get filename from rnote_file\") => {\n        eprintln!(\"Pass a destination file path like out/imported.rnote\");\n    }\n    other => other,\n}","preventionTips":["Always pass a full destination file path, never a directory","Ensure the final path component exists (no bare '/' or '..')","Build output paths with PathBuf::join(name) rather than string concatenation"],"tags":["cli","path","import"],"backgroundTag":"invalid-argument-format","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"}