{"record":{"id":"17d6c2750e8ebdff","repo":"flxzt/rnote","slug":"could-not-parse-text-as-page-number-parsing-error","errorCode":null,"errorMessage":"Could not parse text as page number, parsing error: {e:?}","messagePattern":"Could not parse text as page number, parsing error: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"crates/rnote-ui/src/strokecontentpreview.rs","lineNumber":219,"sourceCode":"                }\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()\n    }\n}\n","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-ui/src/strokecontentpreview.rs#L201-L237","documentation":"Thrown by `parse_page_text` when `text.parse::<usize>()` fails outright — the entry text is not a non-negative integer (e.g. letters, negative sign, empty or oversized value). The `ParseIntError` is included in debug form to aid debugging; the caller must supply numeric page text.","triggerScenarios":"In `update_paintable_content`, the page entry contains non-numeric text — empty string, \"abc\", \"-1\", \"3.5\", or a number exceeding usize — and `parse_page_text` attempts the parse.","commonSituations":"User typed letters or a negative/decimal number into the page field; entry pre-filled with placeholder text; paste of text like \"Page 3\".","solutions":["Enter a plain positive integer (e.g. \"2\") in the page field.","Restrict the entry input to digits (GtkEntry input filter) so non-numeric text cannot be entered.","Trim whitespace and strip non-digit characters before parsing.","Handle the Err branch by resetting the entry to the current valid page instead of propagating the error."],"exampleFix":"// before\nErr(e) => Err(anyhow::anyhow!(\n    \"Could not parse text as page number, parsing error: {e:?}\"\n)),\n// after\nErr(e) => {\n    tracing::debug!(\"invalid page input: {e:?}\");\n    Ok(current_page) // fall back to the previously valid page\n}","handlingStrategy":"validation","validationCode":"let cleaned = text.trim();\nif cleaned.is_empty() || !cleaned.chars().all(|c| c.is_ascii_digit()) {\n    return Err(anyhow!(\"page input must be a positive integer\"));\n}","typeGuard":"fn is_page_text(text: &str) -> bool {\n    let t = text.trim();\n    !t.is_empty() && t.chars().all(|c| c.is_ascii_digit())\n}","tryCatchPattern":"match text.trim().parse::<usize>() {\n    Ok(p) => use_page(p),\n    Err(_) => reset_entry_to_current_page(),\n}","preventionTips":["Restrict the page entry to digit-only input","Trim whitespace and strip non-digits before parsing","Fall back to the current valid page on parse failure instead of propagating"],"tags":["input-validation","parsing","page-number","ui"],"backgroundTag":"invalid-argument-format","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"}