{"record":{"id":"1b46b6c08dd4806b","repo":"flxzt/rnote","slug":"selectionexportformat-try-from-u32-for-value","errorCode":null,"errorMessage":"SelectionExportFormat try_from::<u32>() for value {} failed","messagePattern":"SelectionExportFormat try_from::<u32>\\(\\) for value (.+?) failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/engine/export.rs","lineNumber":253,"sourceCode":"    }\n}\n\nimpl SelectionExportFormat {\n    pub fn file_ext(self) -> String {\n        match self {\n            SelectionExportFormat::Svg => String::from(\"svg\"),\n            SelectionExportFormat::Png => String::from(\"png\"),\n            SelectionExportFormat::Jpeg => String::from(\"jpg\"),\n        }\n    }\n}\n\nimpl TryFrom<u32> for SelectionExportFormat {\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                \"SelectionExportFormat try_from::<u32>() for value {} failed\",\n                value\n            )\n        })\n    }\n}\n\n#[derive(Debug, Clone, Copy, Serialize, Deserialize)]\n#[serde(default, rename = \"selection_export_prefs\")]\npub struct SelectionExportPrefs {\n    /// Whether the background should be exported.\n    #[serde(rename = \"with_background\")]\n    pub with_background: bool,\n    /// Whether the background pattern should be exported.\n    #[serde(rename = \"with_pattern\")]\n    pub with_pattern: bool,\n    /// Whether the background and stroke colors should be optimized for printing.\n    #[serde(rename = \"optimize_printing\")]","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/engine/export.rs#L235-L271","documentation":"SelectionExportFormat implements TryFrom<u32> via num_traits::FromPrimitive; any u32 with no matching variant triggers this error. It validates numeric selection-export format identifiers (e.g. png, svg, pdf) before exporting a selection.","triggerScenarios":"Calling SelectionExportFormat::try_from(u32) with an invalid integer, typically while deserializing selection-export preferences or handling frontend export requests.","commonSituations":"Preferences written by another rnote version, corrupted settings, or integrations passing unchecked integer format codes.","solutions":["Validate the u32 against the defined SelectionExportFormat variants before converting.","Migrate old enum values when opening files from other versions.","Default to a safe selection export format on failure.","Store formats by stable name rather than discriminant."],"exampleFix":"// before\nlet format = SelectionExportFormat::try_from(raw_u32)?;\n// after\nlet format = SelectionExportFormat::try_from(raw_u32)\n    .unwrap_or(SelectionExportFormat::Png);","handlingStrategy":"validation","validationCode":"fn is_valid_selection_export_format(v: u32) -> bool {\n    SelectionExportFormat::try_from(v).is_ok()\n}","typeGuard":"fn as_selection_export_format(v: u32) -> Option<SelectionExportFormat> {\n    num_traits::FromPrimitive::from_u32(v)\n}","tryCatchPattern":"match SelectionExportFormat::try_from(raw) {\n    Ok(f) => f,\n    Err(_) => {\n        log::warn!(\"unknown selection export format {raw}; defaulting\");\n        SelectionExportFormat::Png\n    }\n}","preventionTips":["Validate format integers from external callers","Keep discriminants stable across versions or add migrations","Prefer name-based serialization","Use unwrap_or(default) for preference restoration"],"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"}