{"record":{"id":"d2025b16b401c7a6","repo":"flxzt/rnote","slug":"generating-doc-svg-failed-returned-none","errorCode":null,"errorMessage":"Generating doc svg failed, returned None.","messagePattern":"Generating doc svg failed, returned None\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/engine/export.rs","lineNumber":444,"sourceCode":"    fn export_doc_as_svg_bytes(\n        &self,\n        doc_export_prefs_override: Option<DocExportPrefs>,\n    ) -> oneshot::Receiver<Result<Vec<u8>, anyhow::Error>> {\n        let (oneshot_sender, oneshot_receiver) = oneshot::channel::<anyhow::Result<Vec<u8>>>();\n        let doc_export_prefs =\n            doc_export_prefs_override.unwrap_or(self.config.read().export_prefs.doc_export_prefs);\n        let doc_content = self.extract_document_content();\n\n        rayon::spawn(move || {\n            let result = || -> anyhow::Result<Vec<u8>> {\n                let doc_svg = doc_content\n                    .gen_svg(\n                        doc_export_prefs.with_background,\n                        doc_export_prefs.with_pattern,\n                        doc_export_prefs.optimize_printing,\n                        DocExportPrefs::MARGIN,\n                    )?\n                    .ok_or(anyhow::anyhow!(\"Generating doc svg failed, returned None.\"))?;\n                Ok(rnote_compose::utils::add_xml_header(\n                    rnote_compose::utils::wrap_svg_root(\n                        doc_svg.svg_data.as_str(),\n                        Some(doc_svg.bounds),\n                        Some(doc_svg.bounds),\n                        false,\n                    )\n                    .as_str(),\n                )\n                .into_bytes())\n            };\n\n            if oneshot_sender.send(result()).is_err() {\n                error!(\n                    \"Sending result to receiver failed while exporting document as Svg bytes. Receiver already dropped.\"\n                );\n            }\n        });","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/engine/export.rs#L426-L462","documentation":"During doc export, gen_svg is asked to render the whole document as SVG; it may return None (no renderable content) rather than an error. export_doc_as_svg_bytes treats that None as a failure and throws this error, since a doc export must always produce SVG.","triggerScenarios":"Calling export_doc -> export_doc_as_svg_bytes on a document whose gen_svg returns None, e.g. a document with no renderable strokes/content or filter settings (with_background, optimize_printing) eliminating everything.","commonSituations":"Exporting an empty or effectively empty .rnote file, exporting after programmatic modifications that removed all content, or calling the export API from scripts on documents that were never populated.","solutions":["Check the document has at least one drawable stroke/content before exporting as SVG.","Relax export filters (with_background, with_pattern, optimize_printing) that may suppress all output.","Handle the export error and report 'nothing to export' to the user instead of crashing.","Fall back to exporting a blank page if an empty SVG is acceptable."],"exampleFix":"// before\nlet svg_bytes = engine.export_doc(export_prefs).await?;\n// after\nif engine.document.content_bounds().is_none() {\n    eprintln!(\"document is empty; nothing to export as SVG\");\n} else {\n    let svg_bytes = engine.export_doc(export_prefs).await?;\n}","handlingStrategy":"try-catch","validationCode":"fn can_export_doc(engine: &RnoteEngine) -> bool {\n    engine.document.content_bounds().is_some()\n}","typeGuard":null,"tryCatchPattern":"match engine.export_doc(export_prefs).await {\n    Ok(bytes) => bytes,\n    Err(e) if e.to_string().contains(\"returned None\") => {\n        eprintln!(\"nothing to export: document produced no SVG\");\n        Vec::new()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check content_bounds/is-empty before doc export","Avoid export filter combinations that can suppress all output","Surface 'nothing to export' to users instead of a raw error","Test export on empty and edge-case documents"],"tags":["rust","svg","export","empty-input"],"backgroundTag":"empty-result-set","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"}