flxzt/rnote · error
SelectorStyle try_from
Error message
SelectorStyle try_from::<u32>() for value {} failed What it means
SelectorStyle::try_from(u32) failed because no SelectorStyle variant (e.g. polygon) matches the given u32 via num_traits::FromPrimitive. The library throws this when a numeric selector-style value, usually restored from persisted settings, is not a valid variant discriminant.
Solutions
- Check that the u32 corresponds to a valid SelectorStyle discriminant (see selectorconfig.rs).
- Fall back to SelectorStyle::default() when conversion fails on loaded settings.
- Migrate or re-save settings produced by older app versions.
Example fix
// before
let style = SelectorStyle::try_from(stored_u32)?;
// after
let style = SelectorStyle::try_from(stored_u32)
.unwrap_or(SelectorStyle::default()); Defensive patterns
Strategy: fallback
Validate before calling
fn is_valid_selector_style(v: u32) -> bool {
SelectorStyle::try_from(v).is_ok()
} Type guard
fn as_selector_style(v: u32) -> Option<SelectorStyle> {
num_traits::FromPrimitive::from_u32(v)
} Try / catch
let style = SelectorStyle::try_from(raw)
.map_err(|e| log::warn!("{e}; using default"))
.unwrap_or(SelectorStyle::default()); Prevention
- Clamp or validate UI dropdown indices against the enum variant count before conversion.
- Migrate persisted selector settings when the enum layout changes.
- Prefer name-based enum serialization over raw discriminants.
When it happens
Trigger: Calling `SelectorStyle::try_from(value)` with a u32 outside valid discriminants, e.g. a value from an old settings file after variants changed, or an out-of-range UI selector index.
Common situations: Restoring selector pen configuration across rnote versions; hand-edited config; a GUI dropdown index that no longer maps to a variant.
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
- BrushStyle try_from:: () for value failed
- EraserStyle try_from
- ShaperStyle try_from
- ToolStyle try_from:: () for value failed
- ShortcutMode try_from
AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08).
Data as JSON: /api/errors/0e82244984da4888.
Report an issue: GitHub.
Appendix: source
Thrown at crates/rnote-engine/src/pens/pensconfig/selectorconfig.rs:40
Rectangle,
#[serde(rename = "single", alias = "apiece")]
Single,
#[serde(rename = "intersectingpath")]
IntersectingPath,
}
impl Default for SelectorStyle {
fn default() -> Self {
Self::Rectangle
}
}
impl TryFrom<u32> for SelectorStyle {
type Error = anyhow::Error;
fn try_from(value: u32) -> Result<Self, Self::Error> {
num_traits::FromPrimitive::from_u32(value).ok_or_else(|| {
anyhow::anyhow!("SelectorStyle try_from::<u32>() for value {} failed", value)
})
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default, rename = "selector_config")]
pub struct SelectorConfig {
#[serde(rename = "style")]
pub style: SelectorStyle,
#[serde(rename = "resize_lock_aspectratio")]
pub resize_lock_aspectratio: bool,
}
impl Default for SelectorConfig {
fn default() -> Self {
Self {
style: SelectorStyle::default(),
resize_lock_aspectratio: false,View on GitHub (pinned to bbc5354502)