tonhowtf/omniget · warning

pagina fora do documento

Error message

pagina fora do documento ({} paginas): {}

What it means

A parsed page number is 0 or exceeds the document's total page count. The library validates every range bound against the actual page count (obtained from page_count) and reports both the total and the offending token.

Solutions

  1. Query the document's page count first and clamp/validate the requested range before calling
  2. Treat 0 as invalid — pages are 1-based in this API
  3. For batch jobs, intersect the requested range with 1..=total and skip documents where the intersection is empty
  4. Return a clear message to users showing the valid range 1..total

Example fix

// before
let pages = parse_ranges("60", doc.page_count())?;
// after
let total = doc.page_count();
let requested: Vec<usize> = parse_selection("60");
let valid: Vec<usize> = requested.into_iter().filter(|p| (1..=total).contains(p)).collect();
anyhow::ensure!(!valid.is_empty(), "no pages in 1..={total}");
let pages = parse_ranges(&fmt(valid), total)?;
Defensive patterns

Strategy: validation

Validate before calling

let total = doc.page_count();
let ok = selection.iter().all(|p| (1..=total).contains(p));
if !ok { return Err(format!("pages must be within 1..={total}")); }

Type guard

fn in_range(n: usize, total: usize) -> bool { n >= 1 && n <= total }

Try / catch

match parse_ranges(spec, doc.page_count()) {
    Ok(p) => p,
    Err(e) if e.to_string().contains("fora do documento") => {
        // clamp to valid range or surface 'document only has N pages' to the user
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling split/render/to_text/read_pages/redaction_check/read_raw_chars with a range like "50" or "40-60" on a 45-page document, or "0", which is invalid since pages are 1-based.

Common situations: Stale page references after the document changed (pages removed), UIs that don't clamp input to page_count, automated scripts with hardcoded page numbers applied to different documents.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/222f30dbea602587. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/pdf.rs:406

        .filter(|p| !p.is_empty())
    {
        if let Some((a, b)) = part.split_once('-') {
            let a: usize = if a.trim().is_empty() {
                1
            } else {
                a.trim()
                    .parse()
                    .map_err(|_| anyhow!("intervalo invalido: {}", part))?
            };
            let b: usize = if b.trim().is_empty() {
                total
            } else {
                b.trim()
                    .parse()
                    .map_err(|_| anyhow!("intervalo invalido: {}", part))?
            };
            if a == 0 || b == 0 || a > total || b > total {
                return Err(anyhow!(
                    "pagina fora do documento ({} paginas): {}",
                    total,
                    part
                ));
            }
            if a <= b {
                out.extend(a..=b);
            } else {
                out.extend((b..=a).rev());
            }
        } else {
            let n: usize = part
                .parse()
                .map_err(|_| anyhow!("pagina invalida: {}", part))?;
            if n == 0 || n > total {
                return Err(anyhow!(
                    "pagina fora do documento ({} paginas): {}",
                    total,

View on GitHub (pinned to 8600b91f42)