{"record":{"id":"c8ea30fb68bd282f","repo":"flxzt/rnote","slug":"shortcutmode-try-from-u32-for-value-failed","errorCode":null,"errorMessage":"ShortcutMode try_from::<u32>() for value {} failed","messagePattern":"ShortcutMode try_from::<u32>\\(\\) for value (.+?) failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/pens/shortcuts.rs","lineNumber":37,"sourceCode":")]\n#[serde(rename = \"shortcut_mode\")]\npub enum ShortcutMode {\n    #[serde(rename = \"temporary\")]\n    Temporary,\n    #[serde(rename = \"permanent\")]\n    Permanent,\n    #[serde(rename = \"toggle\")]\n    Toggle,\n    #[serde(rename = \"disabled\")]\n    Disabled,\n}\n\nimpl TryFrom<u32> for ShortcutMode {\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!(\"ShortcutMode try_from::<u32>() for value {} failed\", value)\n        })\n    }\n}\n\n#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]\n#[serde(rename = \"shortcut_action\")]\npub enum ShortcutAction {\n    #[serde(rename = \"change_pen_style\")]\n    ChangePenStyle {\n        #[serde(rename = \"style\")]\n        style: PenStyle,\n        #[serde(rename = \"mode\")]\n        mode: ShortcutMode,\n    },\n}\n\n/// The registered shortcut actions for the given shortcut keys.\n#[derive(Debug, Clone, Serialize, Deserialize)]","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/pens/shortcuts.rs#L19-L55","documentation":"ShortcutMode::try_from(u32) failed because num_traits::FromPrimitive::from_u32 found no ShortcutMode variant (e.g. temporary) matching the value. The library throws this when a numeric shortcut-mode value, typically restored from persisted shortcut settings, is not a valid variant discriminant.","triggerScenarios":"Calling `ShortcutMode::try_from(value)` with a u32 that is not a valid discriminant, e.g. a value loaded from an old shortcut settings file after the enum changed, or an out-of-range UI index.","commonSituations":"Restoring keyboard-shortcut configuration across rnote versions; hand-edited shortcut files; stored mode indices drifting after variants were added or removed.","solutions":["Verify the u32 corresponds to a valid ShortcutMode discriminant (see shortcuts.rs).","Fall back to ShortcutMode::default() when conversion fails on loaded settings.","Migrate or re-save shortcut settings from older app versions."],"exampleFix":"// before\nlet mode = ShortcutMode::try_from(stored_u32)?;\n// after\nlet mode = ShortcutMode::try_from(stored_u32)\n    .unwrap_or(ShortcutMode::default());","handlingStrategy":"fallback","validationCode":"fn is_valid_shortcut_mode(v: u32) -> bool {\n    ShortcutMode::try_from(v).is_ok()\n}","typeGuard":"fn as_shortcut_mode(v: u32) -> Option<ShortcutMode> {\n    num_traits::FromPrimitive::from_u32(v)\n}","tryCatchPattern":"let mode = ShortcutMode::try_from(raw)\n    .map_err(|e| log::warn!(\"{e}; using default\"))\n    .unwrap_or(ShortcutMode::default());","preventionTips":["Validate persisted shortcut mode values before conversion.","Add migration logic when ShortcutMode variants change between releases.","Prefer storing shortcut modes as strings rather than numeric indices."],"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"}