tonhowtf/omniget · error
pagina nao abriu
Error message
pagina {} nao abriu What it means
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.
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
Example fix
// before
for i in 0..n { let page = doc.page(i)?; }
// after
let n = doc.page_count();
for i in 0..n { let page = doc.page(i).with_context(|| format!("page {i} of {n}"))?; } Defensive patterns
Strategy: validation
Validate before calling
if index >= doc.page_count() { return Err(format!("page {} out of range (total {})", index + 1, doc.page_count()).into()); } Type guard
fn page_exists(doc: &Document, index: usize) -> bool { index < doc.page_count() } Try / catch
let page = doc.page(i).with_context(|| format!("failed to load page {} of {}", i + 1, doc.page_count()))?; Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- nao criou o documento
- nao importou as paginas
- nao gravou o PDF
- sem memoria para x
- pagina fora do documento
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/9a264d4388aa4365.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/pdf.rs:230
let doc = unsafe { (api.new_doc)() };
if doc.is_null() {
return Err(anyhow!("nao criou o documento"));
}
Ok(Document {
api,
doc,
_data: Vec::new(),
})
}
fn pages(&self) -> usize {
unsafe { (self.api.page_count)(self.doc) }.max(0) as usize
}
fn page(&self, index: usize) -> anyhow::Result<PageRef<'_>> {
let page = unsafe { (self.api.load_page)(self.doc, index as c_int) };
if page.is_null() {
return Err(anyhow!("pagina {} nao abriu", index + 1));
}
Ok(PageRef {
api: self.api,
page,
_doc: self,
})
}
/// Copia páginas de `src` (números 1-based, na ordem dada) para o fim.
fn import(&self, src: &Document, pages: &[usize]) -> anyhow::Result<()> {
let spec = pages
.iter()
.map(|p| p.to_string())
.collect::<Vec<_>>()
.join(",");
let spec = CString::new(spec)?;
let at = self.pages() as c_int;
let ok = unsafe { (self.api.import_pages)(self.doc, src.doc, spec.as_ptr(), at) };View on GitHub (pinned to 8600b91f42)