{"record":{"id":"222f30dbea602587","repo":"tonhowtf/omniget","slug":"pagina-fora-do-documento-paginas","errorCode":null,"errorMessage":"pagina fora do documento ({} paginas): {}","messagePattern":"pagina fora do documento \\((.+?) paginas\\): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":406,"sourceCode":"        .filter(|p| !p.is_empty())\n    {\n        if let Some((a, b)) = part.split_once('-') {\n            let a: usize = if a.trim().is_empty() {\n                1\n            } else {\n                a.trim()\n                    .parse()\n                    .map_err(|_| anyhow!(\"intervalo invalido: {}\", part))?\n            };\n            let b: usize = if b.trim().is_empty() {\n                total\n            } else {\n                b.trim()\n                    .parse()\n                    .map_err(|_| anyhow!(\"intervalo invalido: {}\", part))?\n            };\n            if a == 0 || b == 0 || a > total || b > total {\n                return Err(anyhow!(\n                    \"pagina fora do documento ({} paginas): {}\",\n                    total,\n                    part\n                ));\n            }\n            if a <= b {\n                out.extend(a..=b);\n            } else {\n                out.extend((b..=a).rev());\n            }\n        } else {\n            let n: usize = part\n                .parse()\n                .map_err(|_| anyhow!(\"pagina invalida: {}\", part))?;\n            if n == 0 || n > total {\n                return Err(anyhow!(\n                    \"pagina fora do documento ({} paginas): {}\",\n                    total,","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L388-L424","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Query the document's page count first and clamp/validate the requested range before calling","Treat 0 as invalid — pages are 1-based in this API","For batch jobs, intersect the requested range with 1..=total and skip documents where the intersection is empty","Return a clear message to users showing the valid range 1..total"],"exampleFix":"// before\nlet pages = parse_ranges(\"60\", doc.page_count())?;\n// after\nlet total = doc.page_count();\nlet requested: Vec<usize> = parse_selection(\"60\");\nlet valid: Vec<usize> = requested.into_iter().filter(|p| (1..=total).contains(p)).collect();\nanyhow::ensure!(!valid.is_empty(), \"no pages in 1..={total}\");\nlet pages = parse_ranges(&fmt(valid), total)?;","handlingStrategy":"validation","validationCode":"let total = doc.page_count();\nlet ok = selection.iter().all(|p| (1..=total).contains(p));\nif !ok { return Err(format!(\"pages must be within 1..={total}\")); }","typeGuard":"fn in_range(n: usize, total: usize) -> bool { n >= 1 && n <= total }","tryCatchPattern":"match parse_ranges(spec, doc.page_count()) {\n    Ok(p) => p,\n    Err(e) if e.to_string().contains(\"fora do documento\") => {\n        // clamp to valid range or surface 'document only has N pages' to the user\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Fetch page_count() fresh at validation time, never cache across mutations","Treat pages as 1-based throughout the UI and API boundary","Intersect automated selections with 1..=total and skip empty results","Update stored page references whenever documents are re-generated"],"tags":["pdf","validation","bounds","user-input"],"backgroundTag":"value-out-of-range","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"}