{"record":{"id":"55c3da76cc294033","repo":"tonhowtf/omniget","slug":"nao-criou-o-documento","errorCode":null,"errorMessage":"nao criou o documento","messagePattern":"nao criou o documento","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":214,"sourceCode":"                3 => \"nao e um PDF valido\",\n                4 => \"senha incorreta ou ausente\",\n                5 => \"esquema de seguranca nao suportado\",\n                6 => \"pagina invalida\",\n                _ => \"erro desconhecido\",\n            };\n            return Err(anyhow!(\"{}: {}\", path.display(), why));\n        }\n        Ok(Document {\n            api,\n            doc,\n            _data: data,\n        })\n    }\n\n    fn new(api: &'static Api) -> anyhow::Result<Self> {\n        let doc = unsafe { (api.new_doc)() };\n        if doc.is_null() {\n            return Err(anyhow!(\"nao criou o documento\"));\n        }\n        Ok(Document {\n            api,\n            doc,\n            _data: Vec::new(),\n        })\n    }\n\n    fn pages(&self) -> usize {\n        unsafe { (self.api.page_count)(self.doc) }.max(0) as usize\n    }\n\n    fn page(&self, index: usize) -> anyhow::Result<PageRef<'_>> {\n        let page = unsafe { (self.api.load_page)(self.doc, index as c_int) };\n        if page.is_null() {\n            return Err(anyhow!(\"pagina {} nao abriu\", index + 1));\n        }\n        Ok(PageRef {","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L196-L232","documentation":"The FFI call to the PDF engine's document-creation function returned a null pointer, so no PDF document object could be allocated. The library wraps the raw C API (api.new_doc) and treats any null handle as a fatal allocation/initialization failure, raising this anyhow error.","triggerScenarios":"Calling any Document-creating API (e.g. creating a new/empty PDF document) when the underlying native library fails to allocate the document object — typically from memory exhaustion, an unloaded or corrupted native PDF library, or an incompatible/misloaded C API table.","commonSituations":"Low-memory environments (containers with tight memory limits), the native PDF shared library failing to initialize properly, or bundled binary mismatch after an app update so the vtable points at a broken implementation.","solutions":["Check available memory in the environment and raise limits (ulimit, container memory) before retrying","Verify the native PDF library is loaded correctly and matches the expected ABI/version","Retry the operation once; a transient allocation failure may succeed later","If it persists, log the environment details and report — this indicates a broken native setup"],"exampleFix":"// before\nlet doc = Document::new();\n// after\nmatch Document::new() {\n    Ok(doc) => doc,\n    Err(e) => { eprintln!(\"PDF engine failed to create document: {e}\"); return Err(e); }\n}","handlingStrategy":"try-catch","validationCode":"// No pre-call check is reliable; guard the environment instead.\nfn can_attempt() -> bool { /* check available memory / lib loaded */ true }","typeGuard":null,"tryCatchPattern":"match doc_result {\n    Ok(doc) => use(doc),\n    Err(e) if e.to_string().contains(\"nao criou o documento\") => {\n        // native alloc/init failure: free memory, retry once, else abort\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Run in environments with adequate free memory","Keep the native PDF library binaries in sync with the Rust wrapper version","Retry once on transient allocation failures before giving up","Log OS memory stats when this fires to aid diagnosis"],"tags":["ffi","pdf","memory-allocation","null-pointer"],"backgroundTag":"internal-invariant-violation","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"}