{"record":{"id":"a7209f808b6de227","repo":"flxzt/rnote","slug":"could-not-parse-text-as-page-number-page-outs","errorCode":null,"errorMessage":"Could not parse text as page number, '{page}' outside valid range '{page_range:?}'.","messagePattern":"Could not parse text as page number, '(.+?)' outside valid range '(.+?)'\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"crates/rnote-ui/src/strokecontentpreview.rs","lineNumber":216,"sourceCode":"            match parse_page_text(&self.page_entry.text(), n_pages) {\n                Ok(page) if page == current_page => {\n                    // Don't update entry if it is already the current page\n                }\n                Ok(_) | Err(_) => {\n                    // user facing page number is 1 indexed\n                    self.page_entry.set_text(&(current_page + 1).to_string());\n                }\n            }\n            self.n_pages_button.set_label(&n_pages.to_string());\n        }\n    }\n\n    fn parse_page_text(text: &str, n_pages: usize) -> anyhow::Result<usize> {\n        // user facing page number is 1 indexed\n        let page_range = 1..=n_pages;\n        match text.parse::<usize>() {\n            Ok(page) if page_range.contains(&page) => Ok(page - 1),\n            Ok(page) => Err(anyhow::anyhow!(\n                \"Could not parse text as page number, '{page}' outside valid range '{page_range:?}'.\",\n            )),\n            Err(e) => Err(anyhow::anyhow!(\n                \"Could not parse text as page number, parsing error: {e:?}\"\n            )),\n        }\n    }\n}\n\nglib::wrapper! {\n    pub(crate) struct RnStrokeContentPreview(ObjectSubclass<imp::RnStrokeContentPreview>)\n        @extends Widget,\n        @implements gtk4::Accessible, gtk4::Buildable, gtk4::ConstraintTarget;\n}\n\nimpl Default for RnStrokeContentPreview {\n    fn default() -> Self {\n        Self::new()","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-ui/src/strokecontentpreview.rs#L198-L234","documentation":"Thrown by `parse_page_text` in `strokecontentpreview.rs` when the user-entered text parses as a valid `usize` but falls outside the 1..=n_pages range of the referenced document. The function wants a 1-indexed page number; out-of-range values are rejected with this error so the preview does not render a nonexistent page.","triggerScenarios":"In `update_paintable_content`, the user types a page number greater than the document's page count (e.g. 12 in a 5-page document) or 0 into the stroke content preview's page entry, and the text is parsed as a valid usize.","commonSituations":"Typing 0 or a page beyond the document length; document changed (pages removed) after the entry text was set; pasting a page number from a different document.","solutions":["Enter a page number between 1 and the document's total page count.","Clamp the parsed value to 1..=n_pages (or to the nearest bound) instead of erroring.","Update the entry's allowed range/validator whenever the referenced document's page count changes.","Check `n_pages` of the linked stroke content to confirm the intended page exists."],"exampleFix":"// before\nOk(page) => Err(anyhow::anyhow!(\n    \"Could not parse text as page number, '{page}' outside valid range '{page_range:?}'.\",\n)),\n// after\nOk(page) => {\n    let clamped = page.clamp(1, n_pages);\n    Ok(clamped - 1)\n}","handlingStrategy":"validation","validationCode":"let page: usize = text.trim().parse()?;\nif page == 0 || page > n_pages { return Err(anyhow!(\"page {page} outside 1..={n_pages}\")); }","typeGuard":"fn valid_page(text: &str, n_pages: usize) -> Option<usize> {\n    text.trim().parse::<usize>().ok().filter(|p| (1..=n_pages).contains(p))\n}","tryCatchPattern":null,"preventionTips":["Clamp user page input to 1..=n_pages instead of rejecting","Refresh the valid range whenever the linked document changes","Show the allowed range in the UI next to the page entry"],"tags":["input-validation","page-number","range","ui"],"backgroundTag":"value-out-of-range","analyzedSha":"bbc5354502ba2fc83eec2670b535348825e679a6","analyzedAt":"2026-09-08T13:20:33.747Z","contentChangedAt":"2026-09-08T13:20:33.747Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}