flxzt/rnote · warning · anyhow::Error
Could not parse text as page number, parsing error
Error message
Could not parse text as page number, parsing error: {e:?} What it means
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.
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.
Example fix
// before
Err(e) => Err(anyhow::anyhow!(
"Could not parse text as page number, parsing error: {e:?}"
)),
// after
Err(e) => {
tracing::debug!("invalid page input: {e:?}");
Ok(current_page) // fall back to the previously valid page
} Defensive patterns
Strategy: validation
Validate before calling
let cleaned = text.trim();
if cleaned.is_empty() || !cleaned.chars().all(|c| c.is_ascii_digit()) {
return Err(anyhow!("page input must be a positive integer"));
} Type guard
fn is_page_text(text: &str) -> bool {
let t = text.trim();
!t.is_empty() && t.chars().all(|c| c.is_ascii_digit())
} Try / catch
match text.trim().parse::<usize>() {
Ok(p) => use_page(p),
Err(_) => reset_entry_to_current_page(),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: User typed letters or a negative/decimal number into the page field; entry pre-filled with placeholder text; paste of text like "Page 3".
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Could not parse text as page number
- Layout from_string failed, invalid name
- Failed to parse `type` attribute of XoppBackground with…
- failed to parse `tool` attribute in XoppStroke with node id
- failed to parse `color` attribute in XoppStroke with node id
AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08).
Data as JSON: /api/errors/17d6c2750e8ebdff.
Report an issue: GitHub.
Appendix: source
Thrown at crates/rnote-ui/src/strokecontentpreview.rs:219
}
Ok(_) | Err(_) => {
// user facing page number is 1 indexed
self.page_entry.set_text(&(current_page + 1).to_string());
}
}
self.n_pages_button.set_label(&n_pages.to_string());
}
}
fn parse_page_text(text: &str, n_pages: usize) -> anyhow::Result<usize> {
// user facing page number is 1 indexed
let page_range = 1..=n_pages;
match text.parse::<usize>() {
Ok(page) if page_range.contains(&page) => Ok(page - 1),
Ok(page) => Err(anyhow::anyhow!(
"Could not parse text as page number, '{page}' outside valid range '{page_range:?}'.",
)),
Err(e) => Err(anyhow::anyhow!(
"Could not parse text as page number, parsing error: {e:?}"
)),
}
}
}
glib::wrapper! {
pub(crate) struct RnStrokeContentPreview(ObjectSubclass<imp::RnStrokeContentPreview>)
@extends Widget,
@implements gtk4::Accessible, gtk4::Buildable, gtk4::ConstraintTarget;
}
impl Default for RnStrokeContentPreview {
fn default() -> Self {
Self::new()
}
}
View on GitHub (pinned to bbc5354502)