{"record":{"id":"4d612550530d1552","repo":"tonhowtf/omniget","slug":"nao-importou-as-paginas","errorCode":null,"errorMessage":"nao importou as paginas {:?}","messagePattern":"nao importou as paginas (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":250,"sourceCode":"        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) };\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    }","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L232-L268","documentation":"import_pages invoked the native page-import function which returned 0 (failure), so pages from the source document could not be copied into this document. The requested page list is echoed in the message for debugging.","triggerScenarios":"Calling import with a page spec whose indices don't exist in the source document, importing from a source document that failed to load properly, or a native-library failure while appending (e.g. object number overflow, unsupported page structure).","commonSituations":"Merging PDFs where the user-supplied page selection references pages beyond the source's count, merging encrypted/corrupted PDFs, combining documents produced by incompatible PDF versions.","solutions":["Validate the page list against the source document's page_count() before importing","Verify the source document opens and its pages load (page() succeeds)","Check the PDFs aren't encrypted or password-protected","Split large merges into smaller batches to rule out native resource limits"],"exampleFix":"// before\ndoc.import(&src, vec![1, 5, 99])?;\n// after\nlet n = src.page_count();\nlet pages: Vec<usize> = requested.into_iter().filter(|p| *p >= 1 && *p <= n).collect();\nif pages.is_empty() { anyhow::bail!(\"no valid pages in selection\"); }\ndoc.import(&src, pages)?;","handlingStrategy":"validation","validationCode":"let n = src.page_count();\nanyhow::ensure!(pages.iter().all(|p| (1..=n).contains(p)), \"page selection out of source range 1..={n}\");","typeGuard":null,"tryCatchPattern":"if let Err(e) = doc.import(&src, &pages) {\n    if e.to_string().starts_with(\"nao importou\") {\n        // retry per-page to isolate the offending source page\n    }\n}","preventionTips":["Validate selections against the source's page_count() first","Reject encrypted/password-protected sources up front","Batch large merges and log which batch fails","Keep both documents' handles alive (PageRef borrows) during import"],"tags":["ffi","pdf","merge","invalid-argument"],"backgroundTag":"unsupported-operation","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"}