{"record":{"id":"d7d4af0c89a11fec","repo":"flxzt/rnote","slug":"docpagesexportformat-try-from-u32-for-value","errorCode":null,"errorMessage":"DocPagesExportFormat try_from::<u32>() for value {} failed","messagePattern":"DocPagesExportFormat try_from::<u32>\\(\\) for value (.+?) failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/engine/export.rs","lineNumber":144,"sourceCode":"    Svg,\n    #[serde(rename = \"png\")]\n    Png,\n    #[serde(rename = \"jpeg\")]\n    Jpeg,\n}\n\nimpl Default for DocPagesExportFormat {\n    fn default() -> Self {\n        Self::Svg\n    }\n}\n\nimpl TryFrom<u32> for DocPagesExportFormat {\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                \"DocPagesExportFormat try_from::<u32>() for value {} failed\",\n                value\n            )\n        })\n    }\n}\n\nimpl DocPagesExportFormat {\n    pub fn file_ext(self) -> String {\n        match self {\n            Self::Svg => String::from(\"svg\"),\n            Self::Png => String::from(\"png\"),\n            Self::Jpeg => String::from(\"jpg\"),\n        }\n    }\n}\n\n/// Document pages export preferences.","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/engine/export.rs#L126-L162","documentation":"DocPagesExportFormat implements TryFrom<u32> via num_traits::FromPrimitive; a u32 that maps to no variant produces this error. It validates numeric page-export format identifiers before an export runs.","triggerScenarios":"Calling DocPagesExportFormat::try_from(u32) with an out-of-range or stale value, e.g. when deserializing page-export preferences for exporting individual pages.","commonSituations":"Settings or documents from a different rnote version where discriminants changed, corrupted files, or external callers supplying raw integer format codes.","solutions":["Check the u32 against the defined DocPagesExportFormat variants first.","Migrate enum values when loading files from other versions.","Fall back to a default export format instead of propagating the error.","Serialize format enums by name for cross-version stability."],"exampleFix":"// before\nlet format = DocPagesExportFormat::try_from(raw_u32)?;\n// after\nlet format = DocPagesExportFormat::try_from(raw_u32)\n    .unwrap_or(DocPagesExportFormat::Png);","handlingStrategy":"validation","validationCode":"fn is_valid_pages_export_format(v: u32) -> bool {\n    DocPagesExportFormat::try_from(v).is_ok()\n}","typeGuard":"fn as_pages_export_format(v: u32) -> Option<DocPagesExportFormat> {\n    num_traits::FromPrimitive::from_u32(v)\n}","tryCatchPattern":"match DocPagesExportFormat::try_from(raw) {\n    Ok(f) => f,\n    Err(_) => {\n        log::warn!(\"unknown pages export format {raw}; defaulting\");\n        DocPagesExportFormat::Png\n    }\n}","preventionTips":["Range-check integer format identifiers before conversion","Serialize formats by name for durability","Migrate values when enum definitions change","Fall back to defaults rather than failing the whole export"],"tags":["rust","enum","export"],"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-16T09:17:16.951Z"}