{"record":{"id":"6d8c3ba51994ff26","repo":"flxzt/rnote","slug":"pdfimportpagestype-try-from-u32-for-value","errorCode":null,"errorMessage":"PdfImportPagesType try_from::<u32>() for value {} failed","messagePattern":"PdfImportPagesType try_from::<u32>\\(\\) for value (.+?) failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/engine/import.rs","lineNumber":43,"sourceCode":"pub enum PdfImportPagesType {\n    #[serde(rename = \"bitmap\")]\n    Bitmap = 0,\n    #[serde(rename = \"vector\")]\n    Vector,\n}\n\nimpl Default for PdfImportPagesType {\n    fn default() -> Self {\n        Self::Vector\n    }\n}\n\nimpl TryFrom<u32> for PdfImportPagesType {\n    type Error = anyhow::Error;\n\n    fn try_from(value: u32) -> Result<Self, Self::Error> {\n        num_traits::FromPrimitive::from_u32(value).ok_or_else(|| {\n            anyhow::anyhow!(\n                \"PdfImportPagesType try_from::<u32>() for value {} failed\",\n                value\n            )\n        })\n    }\n}\n\n#[derive(\n    Debug, Clone, Copy, Serialize, Deserialize, num_derive::FromPrimitive, num_derive::ToPrimitive,\n)]\n#[serde(rename = \"pdf_import_page_spacing\")]\npub enum PdfImportPageSpacing {\n    #[serde(rename = \"continuous\")]\n    Continuous = 0,\n    #[serde(rename = \"one_per_document_page\")]\n    OnePerDocumentPage,\n}\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/engine/import.rs#L25-L61","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlet pages_type = PdfImportPagesType::try_from(raw_u32)?;\n// after\nlet pages_type = PdfImportPagesType::try_from(raw_u32)\n    .unwrap_or_default(); // or map to a safe default variant","handlingStrategy":"validation","validationCode":"let pages_type = PdfImportPagesType::try_from(raw_u32)\n    .unwrap_or_else(|_| PdfImportPagesType::default());","typeGuard":"fn valid_pages_type(v: u32) -> bool {\n    PdfImportPagesType::from_u32(v).is_some()\n}","tryCatchPattern":"match PdfImportPagesType::try_from(raw_u32) {\n    Ok(t) => t,\n    Err(e) => {\n        log::warn!(\"invalid PdfImportPagesType {}, using default\", raw_u32);\n        PdfImportPagesType::default()\n    }\n}","preventionTips":["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"],"tags":["pdf-import","enum","conversion","rust"],"backgroundTag":"invalid-enum-value","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"}