{"record":{"id":"4c6de21297917379","repo":"flxzt/rnote","slug":"shaperstyle-try-from-u32-for-value-failed","errorCode":null,"errorMessage":"ShaperStyle try_from::<u32>() for value {} failed","messagePattern":"ShaperStyle try_from::<u32>\\(\\) for value (.+?) failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/pens/pensconfig/shaperconfig.rs","lineNumber":33,"sourceCode":"pub enum ShaperStyle {\n    #[serde(rename = \"smooth\")]\n    Smooth = 0,\n    #[serde(rename = \"rough\")]\n    Rough,\n}\n\nimpl Default for ShaperStyle {\n    fn default() -> Self {\n        Self::Smooth\n    }\n}\n\nimpl TryFrom<u32> for ShaperStyle {\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!(\"ShaperStyle try_from::<u32>() for value {} failed\", value)\n        })\n    }\n}\n\n#[derive(Clone, Debug, Serialize, Deserialize)]\n#[serde(default, rename = \"shaper_config\")]\npub struct ShaperConfig {\n    #[serde(rename = \"builder_type\")]\n    pub builder_type: ShapeBuilderType,\n    #[serde(rename = \"style\")]\n    pub style: ShaperStyle,\n    #[serde(rename = \"smooth_options\")]\n    pub smooth_options: SmoothOptions,\n    #[serde(rename = \"rough_options\")]\n    pub rough_options: RoughOptions,\n    #[serde(rename = \"highlight_mode\")]\n    pub highlight_mode: bool,\n    #[serde(","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/pens/pensconfig/shaperconfig.rs#L15-L51","documentation":"ShaperStyle::try_from(u32) failed because num_traits::FromPrimitive::from_u32 found no ShaperStyle variant (e.g. smooth) matching the value. The library throws this when a numeric shaper-style value, typically restored from persisted settings, is not a valid variant discriminant.","triggerScenarios":"Calling `ShaperStyle::try_from(value)` with a u32 that is not a valid discriminant, e.g. a value from an old settings file after enum changes, or an out-of-range UI index.","commonSituations":"Restoring shaper pen configuration across rnote versions where the enum layout shifted; hand-edited config files; GUI toggles emitting stale indices.","solutions":["Verify the u32 maps to a valid ShaperStyle discriminant (see shaperconfig.rs).","Fall back to ShaperStyle::default() when loading settings with invalid values.","Migrate or re-save settings from older app versions."],"exampleFix":"// before\nlet style = ShaperStyle::try_from(stored_u32)?;\n// after\nlet style = ShaperStyle::try_from(stored_u32)\n    .unwrap_or(ShaperStyle::default());","handlingStrategy":"fallback","validationCode":"fn is_valid_shaper_style(v: u32) -> bool {\n    ShaperStyle::try_from(v).is_ok()\n}","typeGuard":"fn as_shaper_style(v: u32) -> Option<ShaperStyle> {\n    num_traits::FromPrimitive::from_u32(v)\n}","tryCatchPattern":"let style = ShaperStyle::try_from(raw)\n    .map_err(|e| log::warn!(\"{e}; using default\"))\n    .unwrap_or(ShaperStyle::default());","preventionTips":["Validate stored shaper settings values before conversion.","Version settings files and migrate numeric enum values on upgrades.","Avoid persisting raw discriminants; store variant names instead."],"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"}