{"record":{"id":"9a264d4388aa4365","repo":"tonhowtf/omniget","slug":"pagina-nao-abriu","errorCode":null,"errorMessage":"pagina {} nao abriu","messagePattern":"pagina (.+?) nao abriu","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":230,"sourceCode":"        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 {\n            api: self.api,\n            page,\n            _doc: self,\n        })\n    }\n\n    /// Copia páginas de `src` (números 1-based, na ordem dada) para o fim.\n    fn import(&self, src: &Document, pages: &[usize]) -> anyhow::Result<()> {\n        let spec = pages\n            .iter()\n            .map(|p| p.to_string())\n            .collect::<Vec<_>>()\n            .join(\",\");\n        let spec = CString::new(spec)?;\n        let at = self.pages() as c_int;\n        let ok = unsafe { (self.api.import_pages)(self.doc, src.doc, spec.as_ptr(), at) };","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L212-L248","documentation":"load_page returned a null pointer, meaning the requested page index could not be loaded from the document. The library reports the 1-based page number in the message to make the failure concrete for the caller.","triggerScenarios":"Calling page(index) with an index >= page_count, or on a corrupted/unreadable PDF where the page tree cannot resolve the given page object; also possible if the document failed to load fully but the handle is non-null.","commonSituations":"Off-by-one bugs (the error prints index+1, the human page number, so an off-by-one call shows a page number that 'exists'), iterating pages without checking page_count first, PDFs with damaged cross-reference tables.","solutions":["Validate index against doc.page_count() before calling page()","Re-check that the source PDF opens and parses correctly (try another viewer)","Clamp loops to `0..doc.page_count()` instead of a stored/assumed count","If the file is damaged, try repairing it with an external tool before loading"],"exampleFix":"// before\nfor i in 0..n { let page = doc.page(i)?; }\n// after\nlet n = doc.page_count();\nfor i in 0..n { let page = doc.page(i).with_context(|| format!(\"page {i} of {n}\"))?; }","handlingStrategy":"validation","validationCode":"if index >= doc.page_count() { return Err(format!(\"page {} out of range (total {})\", index + 1, doc.page_count()).into()); }","typeGuard":"fn page_exists(doc: &Document, index: usize) -> bool { index < doc.page_count() }","tryCatchPattern":"let page = doc.page(i).with_context(|| format!(\"failed to load page {} of {}\", i + 1, doc.page_count()))?;","preventionTips":["Always bound loops with page_count(), never a cached count","Remember page() is 0-based internally even though errors print 1-based","Repair or reject PDFs that fail to open in other viewers","Handle damaged-page PDFs per page instead of failing the whole job"],"tags":["ffi","pdf","null-pointer","bounds"],"backgroundTag":"resource-not-found","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"}