flxzt/rnote · error
PdfImportPagesType try_from
Error message
PdfImportPagesType try_from::<u32>() for value {} failed What it means
TryFrom<u32> for PdfImportPagesType converts a raw u32 (typically from stored import preferences or a UI combo-box index) into the enum via num_traits::FromPrimitive. When the value does not match any variant, this error is thrown. It guards against corrupted or out-of-range stored settings.
Solutions
- Validate the u32 against the known variant range before converting, and fall back to a default (e.g. PdfImportPagesType::default()) on failure
- Fix the stored preference value in the settings/prefs file to a valid discriminant
- Migrate preferences when upgrading across versions that changed the enum layout
Example fix
// before
let pages_type = PdfImportPagesType::try_from(raw_u32)?;
// after
let pages_type = PdfImportPagesType::try_from(raw_u32)
.unwrap_or_default(); // or map to a safe default variant Defensive patterns
Strategy: validation
Validate before calling
let pages_type = PdfImportPagesType::try_from(raw_u32)
.unwrap_or_else(|_| PdfImportPagesType::default()); Type guard
fn valid_pages_type(v: u32) -> bool {
PdfImportPagesType::from_u32(v).is_some()
} Try / catch
match PdfImportPagesType::try_from(raw_u32) {
Ok(t) => t,
Err(e) => {
log::warn!("invalid PdfImportPagesType {}, using default", raw_u32);
PdfImportPagesType::default()
}
} Prevention
- Validate stored u32 prefs against the enum before use
- Add migrations when enum variants change between versions
- Use unwrap_or_default for user-facing settings rather than propagating the error
When it happens
Trigger: Calling PdfImportPagesType::try_from(v) with a u32 that is not a valid discriminant of the enum — e.g. a value saved by a newer/older app version with different variants, a corrupted prefs file, or an unchecked index from a GUI.
Common situations: Loading PDF import settings from an old or hand-edited config where the pages-type field holds an out-of-range number; schema changes between rnote versions that renumbered variants.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- PdfImportPageSpacing try_from
- SplitOrder try_from:: () for value failed
- PatternStyle try_from
- PredefinedFormat try_from
- MeasureUnit try_from
AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08).
Data as JSON: /api/errors/6d8c3ba51994ff26.
Report an issue: GitHub.
Appendix: source
Thrown at crates/rnote-engine/src/engine/import.rs:43
pub enum PdfImportPagesType {
#[serde(rename = "bitmap")]
Bitmap = 0,
#[serde(rename = "vector")]
Vector,
}
impl Default for PdfImportPagesType {
fn default() -> Self {
Self::Vector
}
}
impl TryFrom<u32> for PdfImportPagesType {
type Error = anyhow::Error;
fn try_from(value: u32) -> Result<Self, Self::Error> {
num_traits::FromPrimitive::from_u32(value).ok_or_else(|| {
anyhow::anyhow!(
"PdfImportPagesType try_from::<u32>() for value {} failed",
value
)
})
}
}
#[derive(
Debug, Clone, Copy, Serialize, Deserialize, num_derive::FromPrimitive, num_derive::ToPrimitive,
)]
#[serde(rename = "pdf_import_page_spacing")]
pub enum PdfImportPageSpacing {
#[serde(rename = "continuous")]
Continuous = 0,
#[serde(rename = "one_per_document_page")]
OnePerDocumentPage,
}
View on GitHub (pinned to bbc5354502)