flxzt/rnote · error

ShaperStyle try_from

Error message

ShaperStyle try_from::<u32>() for value {} failed

What it means

ShaperStyle::try_from(u32) failed because num_traits::FromPrimitive::from_u32 found no ShaperStyle variant (e.g. smooth) matching the value. The library throws this when a numeric shaper-style value, typically restored from persisted settings, is not a valid variant discriminant.

Solutions

  1. Verify the u32 maps to a valid ShaperStyle discriminant (see shaperconfig.rs).
  2. Fall back to ShaperStyle::default() when loading settings with invalid values.
  3. Migrate or re-save settings from older app versions.

Example fix

// before
let style = ShaperStyle::try_from(stored_u32)?;
// after
let style = ShaperStyle::try_from(stored_u32)
    .unwrap_or(ShaperStyle::default());
Defensive patterns

Strategy: fallback

Validate before calling

fn is_valid_shaper_style(v: u32) -> bool {
    ShaperStyle::try_from(v).is_ok()
}

Type guard

fn as_shaper_style(v: u32) -> Option<ShaperStyle> {
    num_traits::FromPrimitive::from_u32(v)
}

Try / catch

let style = ShaperStyle::try_from(raw)
    .map_err(|e| log::warn!("{e}; using default"))
    .unwrap_or(ShaperStyle::default());

Prevention

When it happens

Trigger: Calling `ShaperStyle::try_from(value)` with a u32 that is not a valid discriminant, e.g. a value from an old settings file after enum changes, or an out-of-range UI index.

Common situations: Restoring shaper pen configuration across rnote versions where the enum layout shifted; hand-edited config files; GUI toggles emitting stale indices.

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


AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08). Data as JSON: /api/errors/4c6de21297917379. Report an issue: GitHub.

Appendix: source

Thrown at crates/rnote-engine/src/pens/pensconfig/shaperconfig.rs:33

pub enum ShaperStyle {
    #[serde(rename = "smooth")]
    Smooth = 0,
    #[serde(rename = "rough")]
    Rough,
}

impl Default for ShaperStyle {
    fn default() -> Self {
        Self::Smooth
    }
}

impl TryFrom<u32> for ShaperStyle {
    type Error = anyhow::Error;

    fn try_from(value: u32) -> Result<Self, Self::Error> {
        num_traits::FromPrimitive::from_u32(value).ok_or_else(|| {
            anyhow::anyhow!("ShaperStyle try_from::<u32>() for value {} failed", value)
        })
    }
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default, rename = "shaper_config")]
pub struct ShaperConfig {
    #[serde(rename = "builder_type")]
    pub builder_type: ShapeBuilderType,
    #[serde(rename = "style")]
    pub style: ShaperStyle,
    #[serde(rename = "smooth_options")]
    pub smooth_options: SmoothOptions,
    #[serde(rename = "rough_options")]
    pub rough_options: RoughOptions,
    #[serde(rename = "highlight_mode")]
    pub highlight_mode: bool,
    #[serde(

View on GitHub (pinned to bbc5354502)