{"record":{"id":"48eec3ca0b35e253","repo":"flxzt/rnote","slug":"toolstyle-try-from-u32-for-value-failed","errorCode":null,"errorMessage":"ToolStyle try_from::<u32>() for value {} failed","messagePattern":"ToolStyle try_from::<u32>\\(\\) for value (.+?) failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/pens/pensconfig/toolsconfig.rs","lineNumber":40,"sourceCode":"    OffsetCamera,\n    #[serde(rename = \"zoom\")]\n    Zoom,\n    #[serde(rename = \"laser\")]\n    Laser,\n}\n\nimpl Default for ToolStyle {\n    fn default() -> Self {\n        Self::VerticalSpace\n    }\n}\n\nimpl TryFrom<u32> for ToolStyle {\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!(\"ToolStyle try_from::<u32>() for value {} failed\", value)\n        })\n    }\n}\n\n#[derive(Debug, Clone, Default, Serialize, Deserialize)]\n#[serde(rename = \"verticalspace_tool_config\")]\npub struct VerticalSpaceToolConfig {\n    /// horizontal limit\n    pub limit_movement_horizontal_borders: bool,\n    /// vertical limit\n    pub limit_movement_vertical_borders: bool,\n}\n\n#[derive(Clone, Debug, Default, Serialize, Deserialize)]\n#[serde(default, rename = \"tools_config\")]\npub struct ToolsConfig {\n    #[serde(rename = \"style\")]\n    pub style: ToolStyle,","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/pens/pensconfig/toolsconfig.rs#L22-L58","documentation":"ToolStyle::try_from(u32) failed because no ToolStyle variant (e.g. verticalspace) matches the given u32 via num_traits::FromPrimitive. The library throws this when a numeric tool-style value, usually restored from persisted settings, is not a valid variant discriminant.","triggerScenarios":"Calling `ToolStyle::try_from(value)` with a u32 outside valid discriminants, e.g. a value from an old settings file after enum changes, or an out-of-range UI tool index.","commonSituations":"Restoring tool pen configuration across rnote versions; hand-edited config; a GUI dropdown emitting stale indices after the enum gained variants.","solutions":["Check that the u32 matches a valid ToolStyle discriminant (see toolsconfig.rs).","Fall back to ToolStyle::default() when conversion of loaded settings fails.","Migrate or re-save settings produced by older app versions."],"exampleFix":"// before\nlet style = ToolStyle::try_from(stored_u32)?;\n// after\nlet style = ToolStyle::try_from(stored_u32)\n    .unwrap_or(ToolStyle::default());","handlingStrategy":"fallback","validationCode":"fn is_valid_tool_style(v: u32) -> bool {\n    ToolStyle::try_from(v).is_ok()\n}","typeGuard":"fn as_tool_style(v: u32) -> Option<ToolStyle> {\n    num_traits::FromPrimitive::from_u32(v)\n}","tryCatchPattern":"let style = ToolStyle::try_from(raw)\n    .map_err(|e| log::warn!(\"{e}; using default\"))\n    .unwrap_or(ToolStyle::default());","preventionTips":["Check UI tool indices are within the valid variant range before converting.","Migrate stored tool settings when the enum changes.","Use serde rename attributes so persisted values stay stable across versions."],"tags":["rust","enum-conversion","configuration"],"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"}