{"record":{"id":"297ff97e0ff4247d","repo":"flxzt/rnote","slug":"creating-penstyle-from-str-failed-invalid-name","errorCode":null,"errorMessage":"Creating PenStyle from &str failed, invalid name {s}","messagePattern":"Creating PenStyle from &str failed, invalid name (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/pens/mod.rs","lineNumber":242,"sourceCode":"    fn try_from(value: u32) -> Result<Self, Self::Error> {\n        num_traits::FromPrimitive::from_u32(value)\n            .ok_or_else(|| anyhow::anyhow!(\"PenStyle try_from::<u32>() for value {} failed\", value))\n    }\n}\n\nimpl std::str::FromStr for PenStyle {\n    type Err = anyhow::Error;\n\n    fn from_str(s: &str) -> Result<Self, Self::Err> {\n        match s {\n            \"brush\" => Ok(Self::Brush),\n            \"shaper\" => Ok(Self::Shaper),\n            \"typewriter\" => Ok(Self::Typewriter),\n            \"eraser\" => Ok(Self::Eraser),\n            \"selector\" => Ok(Self::Selector),\n            \"tools\" => Ok(Self::Tools),\n            s => Err(anyhow::anyhow!(\n                \"Creating PenStyle from &str failed, invalid name {s}\"\n            )),\n        }\n    }\n}\n\nimpl Display for PenStyle {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        match self {\n            PenStyle::Brush => write!(f, \"brush\"),\n            PenStyle::Shaper => write!(f, \"shaper\"),\n            PenStyle::Typewriter => write!(f, \"typewriter\"),\n            PenStyle::Eraser => write!(f, \"eraser\"),\n            PenStyle::Selector => write!(f, \"selector\"),\n            PenStyle::Tools => write!(f, \"tools\"),\n        }\n    }\n}\n","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/pens/mod.rs#L224-L260","documentation":"Parsing a string into PenStyle failed because the name did not match any known style (brush, shaper, typewriter, eraser, selector, tools). Raised by FromStr, typically during settings/config deserialization of the pen name.","triggerScenarios":"FromStr for PenStyle with strings like 'pen', 'highlighter', 'Brush' (case mismatch), or empty string from a malformed config.","commonSituations":"Hand-edited config files using old or renamed tool names; other applications writing different pen identifiers; locale/case differences.","solutions":["Use one of the exact valid names: brush, shaper, typewriter, eraser, selector, tools (all lowercase).","Correct the settings file or reset it to defaults.","Make the parser case-insensitive and/or add aliases for legacy names.","Fall back to a default style on parse failure with a warning instead of propagating the error."],"exampleFix":"// before\ns.to_string().parse::<PenStyle>()?; // \"Brush\" -> fails\n// after\nmatch s.to_lowercase().as_str() {\n    \"brush\" | \"pen\" => PenStyle::Brush,\n    other => return Err(anyhow!(\"Creating PenStyle from &str failed, invalid name {other}\")),\n}","handlingStrategy":"fallback","validationCode":"// rust\nconst VALID_STYLES: [&str; 6] = [\"brush\", \"shaper\", \"typewriter\", \"eraser\", \"selector\", \"tools\"];\nfn is_valid_style_name(s: &str) -> bool { VALID_STYLES.contains(&s) }","typeGuard":"fn parse_style_loose(s: &str) -> Option<PenStyle> {\n    s.to_lowercase().parse::<PenStyle>().ok()\n}","tryCatchPattern":"let style = s.parse::<PenStyle>()\n    .inspect_err(|e| log::warn!(\"{e}; using default\"))\n    .unwrap_or(PenStyle::Brush);","preventionTips":["Always write lowercase, canonical style names to config.","Make parsers case-insensitive and accept legacy aliases.","Reset settings to defaults when a style name fails to parse."],"tags":["enum","parsing","settings"],"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"}