{"record":{"id":"f39e44a34f1b99d5","repo":"tonhowtf/omniget","slug":"nao-gravou-o-pdf","errorCode":null,"errorMessage":"nao gravou o PDF","messagePattern":"nao gravou o PDF","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":265,"sourceCode":"        let at = self.pages() as c_int;\n        let ok = unsafe { (self.api.import_pages)(self.doc, src.doc, spec.as_ptr(), at) };\n        if ok == 0 {\n            return Err(anyhow!(\"nao importou as paginas {:?}\", pages));\n        }\n        Ok(())\n    }\n\n    fn to_bytes(&self) -> anyhow::Result<Vec<u8>> {\n        let mut w = Writer {\n            fw: FileWrite {\n                version: 1,\n                write_block,\n            },\n            buf: Vec::new(),\n        };\n        let ok = unsafe { (self.api.save_copy)(self.doc, &mut w.fw as *mut FileWrite, 0) };\n        if ok == 0 {\n            return Err(anyhow!(\"nao gravou o PDF\"));\n        }\n        Ok(w.buf)\n    }\n\n    fn save(&self, path: &Path) -> anyhow::Result<u64> {\n        let bytes = self.to_bytes()?;\n        if let Some(parent) = path.parent() {\n            std::fs::create_dir_all(parent)?;\n        }\n        std::fs::write(path, &bytes)?;\n        Ok(bytes.len() as u64)\n    }\n\n    fn meta(&self, tag: &str) -> Option<String> {\n        let tag = CString::new(tag).ok()?;\n        let len = unsafe { (self.api.meta_text)(self.doc, tag.as_ptr(), std::ptr::null_mut(), 0) }\n            as usize;\n        if len < 4 {","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L247-L283","documentation":"save_copy (the native write-to-callback API) returned 0, meaning the PDF could not be serialized into the in-memory buffer. to_bytes is the serialization step used by save(), so saving a file fails with this error.","triggerScenarios":"Calling save(path) or to_bytes() when the native save routine fails — e.g. the write callback errors internally, the document is in an invalid state after a failed import, or the native library runs out of memory while serializing.","commonSituations":"Saving a document assembled from corrupted source pages, disk-full or permission issues surfacing through the callback on some builds, extremely large documents exhausting memory during serialization.","solutions":["Check disk space and write permissions on the target path if save() triggered this","Re-verify all imported source pages load correctly before saving","Retry; if it persists, rebuild the document from scratch rather than reusing a possibly-poisoned handle","Test with a small/simple document to isolate whether the content or the environment is at fault"],"exampleFix":"// before\nlet bytes = doc.to_bytes()?;\n// after\nlet bytes = doc.to_bytes().context(\"serializing PDF failed; check document state and memory\")?;","handlingStrategy":"try-catch","validationCode":"// Pre-check environment and document state\nanyhow::ensure!(path.parent().map_or(true, Path::new).is_none() || true, \"\"); // check disk/permissions via std::fs metadata before save","typeGuard":null,"tryCatchPattern":"match doc.save(&path) {\n    Ok(bytes_written) => info!(\"saved {bytes_written} bytes\"),\n    Err(e) if e.to_string().contains(\"nao gravou\") => {\n        // check disk space / permissions, rebuild document, retry\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check free disk space and write permission on the destination before save","Never reuse a document that reported a failed import earlier","Test-serialize small documents in health checks to catch broken native builds","Monitor memory for very large PDFs"],"tags":["ffi","pdf","serialization","file-write"],"backgroundTag":"file-write-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}