{"record":{"id":"e2c7ee3f46b3cda7","repo":"flxzt/rnote","slug":"brushstyle-try-from-u32-for-value-failed","errorCode":null,"errorMessage":"BrushStyle try_from::<u32>() for value {} failed","messagePattern":"BrushStyle try_from::<u32>\\(\\) for value (.+?) failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/pens/pensconfig/brushconfig.rs","lineNumber":43,"sourceCode":"    Marker = 0,\n    #[serde(rename = \"solid\")]\n    Solid,\n    #[serde(rename = \"textured\")]\n    Textured,\n}\n\nimpl Default for BrushStyle {\n    fn default() -> Self {\n        Self::Solid\n    }\n}\n\nimpl TryFrom<u32> for BrushStyle {\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!(\"BrushStyle try_from::<u32>() for value {} failed\", value)\n        })\n    }\n}\n\n#[derive(Debug, Clone, Serialize, Deserialize)]\n#[serde(rename = \"marker_options\")]\npub struct MarkerOptions(SmoothOptions);\n\nimpl Default for MarkerOptions {\n    fn default() -> Self {\n        let mut options = SmoothOptions::default();\n        options.pressure_curve = PressureCurve::Const;\n        options.stroke_width = 12.0;\n\n        Self(options)\n    }\n}\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/pens/pensconfig/brushconfig.rs#L25-L61","documentation":"BrushStyle::try_from(u32) failed because num_traits::FromPrimitive::from_u32 returned None: the u32 does not correspond to any BrushStyle variant (marker, etc.). The library throws this whenever a numeric pen-style value, typically restored from persisted settings or received from the UI layer, is outside the valid discriminant range.","triggerScenarios":"Calling `BrushStyle::try_from(value)` with a u32 that is not a valid variant discriminant, e.g. a value loaded from an old or hand-edited settings file after the enum gained/removed/reordered variants, or a value >= the number of variants.","commonSituations":"Restoring brush pen configuration from an old rnote settings file whose stored u32 no longer matches the current enum layout; a UI toggle button emitting an out-of-range index; schema drift between app versions.","solutions":["Check the u32 value being converted and map it to a valid BrushStyle discriminant (see the enum in brushconfig.rs).","If the value comes from persisted settings, migrate or reset it: fall back to BrushStyle::default() when conversion fails.","If you added/removed enum variants, re-save settings so stored numeric values match the new layout."],"exampleFix":"// before\nlet style = BrushStyle::try_from(stored_u32)?;\n// after\nlet style = BrushStyle::try_from(stored_u32)\n    .unwrap_or_else(|_| BrushStyle::default());","handlingStrategy":"fallback","validationCode":"// Rust: validate before conversion\nfn is_valid_brush_style(v: u32) -> bool {\n    BrushStyle::try_from(v).is_ok()\n}","typeGuard":"fn as_brush_style(v: u32) -> Option<BrushStyle> {\n    num_traits::FromPrimitive::from_u32(v)\n}","tryCatchPattern":"let style = BrushStyle::try_from(raw)\n    .map_err(|e| log::warn!(\"{e}; using default\"))\n    .unwrap_or(BrushStyle::default());","preventionTips":["Never hardcode numeric discriminants; use the enum variants and their Into/TryFrom round-trips.","When settings schema changes, bump the settings version and migrate stored u32 values.","Prefer serializing enums by name (serde) rather than by numeric index."],"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"}