flxzt/rnote · error
Creating PenStyle from &str failed, invalid name
Error message
Creating PenStyle from &str failed, invalid name {s} What it means
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.
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.
Example fix
// before
s.to_string().parse::<PenStyle>()?; // "Brush" -> fails
// after
match s.to_lowercase().as_str() {
"brush" | "pen" => PenStyle::Brush,
other => return Err(anyhow!("Creating PenStyle from &str failed, invalid name {other}")),
} Defensive patterns
Strategy: fallback
Validate before calling
// rust
const VALID_STYLES: [&str; 6] = ["brush", "shaper", "typewriter", "eraser", "selector", "tools"];
fn is_valid_style_name(s: &str) -> bool { VALID_STYLES.contains(&s) } Type guard
fn parse_style_loose(s: &str) -> Option<PenStyle> {
s.to_lowercase().parse::<PenStyle>().ok()
} Try / catch
let style = s.parse::<PenStyle>()
.inspect_err(|e| log::warn!("{e}; using default"))
.unwrap_or(PenStyle::Brush); Prevention
- 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.
When it happens
Trigger: FromStr for PenStyle with strings like 'pen', 'highlighter', 'Brush' (case mismatch), or empty string from a malformed config.
Common situations: Hand-edited config files using old or renamed tool names; other applications writing different pen identifiers; locale/case differences.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Layout from_string failed, invalid name
- PenStyle try_from:: () for value failed
- SplitOrder try_from:: () for value failed
- PatternStyle try_from
- PredefinedFormat try_from
AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08).
Data as JSON: /api/errors/297ff97e0ff4247d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/rnote-engine/src/pens/mod.rs:242
fn try_from(value: u32) -> Result<Self, Self::Error> {
num_traits::FromPrimitive::from_u32(value)
.ok_or_else(|| anyhow::anyhow!("PenStyle try_from::<u32>() for value {} failed", value))
}
}
impl std::str::FromStr for PenStyle {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"brush" => Ok(Self::Brush),
"shaper" => Ok(Self::Shaper),
"typewriter" => Ok(Self::Typewriter),
"eraser" => Ok(Self::Eraser),
"selector" => Ok(Self::Selector),
"tools" => Ok(Self::Tools),
s => Err(anyhow::anyhow!(
"Creating PenStyle from &str failed, invalid name {s}"
)),
}
}
}
impl Display for PenStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PenStyle::Brush => write!(f, "brush"),
PenStyle::Shaper => write!(f, "shaper"),
PenStyle::Typewriter => write!(f, "typewriter"),
PenStyle::Eraser => write!(f, "eraser"),
PenStyle::Selector => write!(f, "selector"),
PenStyle::Tools => write!(f, "tools"),
}
}
}
View on GitHub (pinned to bbc5354502)