{"record":{"id":"f461b0f4611c4a21","repo":"flxzt/rnote","slug":"eraserstyle-try-from-u32-for-value-failed","errorCode":null,"errorMessage":"EraserStyle try_from::<u32>() for value {} failed","messagePattern":"EraserStyle try_from::<u32>\\(\\) for value (.+?) failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/pens/pensconfig/eraserconfig.rs","lineNumber":29,"sourceCode":"pub enum EraserStyle {\n    #[serde(rename = \"trash_colliding_strokes\")]\n    TrashCollidingStrokes,\n    #[serde(rename = \"split_colliding_strokes\")]\n    SplitCollidingStrokes,\n}\n\nimpl Default for EraserStyle {\n    fn default() -> Self {\n        Self::TrashCollidingStrokes\n    }\n}\n\nimpl TryFrom<u32> for EraserStyle {\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!(\"EraserStyle try_from::<u32>() for value {} failed\", value)\n        })\n    }\n}\n\n#[derive(Clone, Debug, Serialize, Deserialize)]\n#[serde(default, rename = \"eraser_config\")]\npub struct EraserConfig {\n    #[serde(rename = \"width\")]\n    pub width: f64,\n    #[serde(rename = \"style\")]\n    pub style: EraserStyle,\n}\n\nimpl Default for EraserConfig {\n    fn default() -> Self {\n        Self {\n            width: Self::WIDTH_DEFAULT,\n            style: EraserStyle::default(),","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/pens/pensconfig/eraserconfig.rs#L11-L47","documentation":"EraserStyle::try_from(u32) failed because num_traits::FromPrimitive::from_u32 found no EraserStyle variant matching the value (variants include trash_colliding_strokes). The library throws this when a numeric eraser-style value, typically from persisted pen settings, is not a valid discriminant.","triggerScenarios":"Calling `EraserStyle::try_from(value)` with a u32 outside the valid variant discriminants, e.g. a value read from an old settings file after the enum changed, or an out-of-range UI index.","commonSituations":"Restoring eraser pen configuration across rnote versions where the enum layout changed; hand-edited config files; a GUI toggle emitting an index beyond the variant count.","solutions":["Verify the u32 being converted matches a valid EraserStyle discriminant (see eraserconfig.rs).","Fall back to EraserStyle::default() when the stored value cannot be converted.","Re-save or migrate settings files created by older app versions."],"exampleFix":"// before\nlet style = EraserStyle::try_from(stored_u32)?;\n// after\nlet style = EraserStyle::try_from(stored_u32)\n    .unwrap_or(EraserStyle::default());","handlingStrategy":"fallback","validationCode":"fn is_valid_eraser_style(v: u32) -> bool {\n    EraserStyle::try_from(v).is_ok()\n}","typeGuard":"fn as_eraser_style(v: u32) -> Option<EraserStyle> {\n    num_traits::FromPrimitive::from_u32(v)\n}","tryCatchPattern":"let style = EraserStyle::try_from(raw)\n    .map_err(|e| log::warn!(\"{e}; using default\"))\n    .unwrap_or(EraserStyle::default());","preventionTips":["Validate stored settings values against the current enum before applying them.","Use serde name-based serialization for enums to survive variant reordering.","Add a migration step when enum variants change between app 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"}