{"record":{"id":"69dc68aa6214acf0","repo":"flxzt/rnote","slug":"docexportformat-try-from-u32-for-value-fai","errorCode":null,"errorMessage":"DocExportFormat try_from::<u32>() for value {} failed","messagePattern":"DocExportFormat try_from::<u32>\\(\\) for value (.+?) failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/engine/export.rs","lineNumber":52,"sourceCode":"    Svg,\n    #[serde(rename = \"pdf\")]\n    Pdf,\n    #[serde(rename = \"xopp\")]\n    Xopp,\n}\n\nimpl Default for DocExportFormat {\n    fn default() -> Self {\n        Self::Pdf\n    }\n}\n\nimpl TryFrom<u32> for DocExportFormat {\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                \"DocExportFormat try_from::<u32>() for value {} failed\",\n                value\n            )\n        })\n    }\n}\n\nimpl DocExportFormat {\n    /// File extension for the format.\n    pub fn file_ext(self) -> String {\n        match self {\n            DocExportFormat::Svg => String::from(\"svg\"),\n            DocExportFormat::Pdf => String::from(\"pdf\"),\n            DocExportFormat::Xopp => String::from(\"xopp\"),\n        }\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/engine/export.rs#L34-L70","documentation":"DocExportFormat implements TryFrom<u32> via num_traits::FromPrimitive; a u32 with no matching variant yields this error. It guards numeric export-format identifiers (e.g. png, svg, pdf) read from preferences or IPC.","triggerScenarios":"Calling DocExportFormat::try_from(u32) with an invalid value, typically during export flows that deserialize the requested format from stored prefs or frontend calls.","commonSituations":"Preferences saved by another rnote version with different discriminants, corrupted settings, or frontends passing out-of-range integer format codes.","solutions":["Validate the u32 against the defined DocExportFormat variants before conversion.","Use the current rnote version's enum ordering; migrate values from older files.","Default to a safe format (e.g. PNG) on conversion failure.","Persist formats by name instead of integer discriminant."],"exampleFix":"// before\nlet format = DocExportFormat::try_from(raw_u32)?;\n// after\nlet format = DocExportFormat::try_from(raw_u32)\n    .unwrap_or(DocExportFormat::Png);","handlingStrategy":"validation","validationCode":"fn is_valid_doc_export_format(v: u32) -> bool {\n    DocExportFormat::try_from(v).is_ok()\n}","typeGuard":"fn as_doc_export_format(v: u32) -> Option<DocExportFormat> {\n    num_traits::FromPrimitive::from_u32(v)\n}","tryCatchPattern":"match DocExportFormat::try_from(raw) {\n    Ok(f) => f,\n    Err(_) => {\n        log::warn!(\"unknown export format {raw}; defaulting to PNG\");\n        DocExportFormat::Png\n    }\n}","preventionTips":["Validate format codes coming from frontends/IPC","Keep enum ordering stable; add migrations when it changes","Default to a safe format on invalid input","Test export flows against saved preferences from older versions"],"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"}