{"record":{"id":"3c68d517d976f651","repo":"babalae/better-genshin-impact","slug":"invalid-hotkey","errorCode":null,"errorMessage":"Invalid Hotkey","messagePattern":"Invalid Hotkey","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"Fischless.HotkeyCapture/Hotkey.cs","lineNumber":73,"sourceCode":"                    Control = true;\n                }\n                else if (keyStr.Equals(\"Shift\", StringComparison.OrdinalIgnoreCase))\n                {\n                    Shift = true;\n                }\n                else if (keyStr.Equals(\"Alt\", StringComparison.OrdinalIgnoreCase))\n                {\n                    Alt = true;\n                }\n                else\n                {\n                    Key = (Keys)Enum.Parse(typeof(Keys), keyStr);\n                }\n            }\n        }\n        catch\n        {\n            throw new ArgumentException(\"Invalid Hotkey\");\n        }\n    }\n\n    public override string ToString()\n    {\n        string str = string.Empty;\n        if (Key != Keys.None)\n        {\n            str = string.Format(\"{0}{1}{2}{3}{4}\",\n                Windows ? \"Win + \" : string.Empty,\n                Control ? \"Ctrl + \" : string.Empty,\n                Shift ? \"Shift + \" : string.Empty,\n                Alt ? \"Alt + \" : string.Empty,\n                Key);\n        }\n        return str;\n    }\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/Fischless.HotkeyCapture/Hotkey.cs#L55-L91","documentation":"Thrown by the Hotkey(string) constructor when parsing the hotkey string fails — Enum.Parse throws for an unrecognized key token, or the split/format is invalid. The catch-all swallows the original exception and rethrows a generic ArgumentException(\"Invalid Hotkey\"), discarding which token actually failed.","triggerScenarios":"A persisted hotkey string contains a token that is not a valid System.Windows.Forms.Keys name: a typo, a localized key name, an unknown function key, or an empty token from a trailing '+' delimiter.","commonSituations":"Config file hand-edited with a bad key string; locale mismatch producing a non-English key name; a key name removed in a newer framework; an empty or modifier-only hotkey string saved to disk.","solutions":["Validate the hotkey string format before constructing Hotkey; reject unknown tokens early.","Replace Enum.Parse with Enum.TryParse and report which token failed instead of a generic message.","Sanitize/normalize stored hotkey strings on config load (trim, collapse '+', reject empties)."],"exampleFix":"// before\nKey = (Keys)Enum.Parse(typeof(Keys), keyStr);\n// ... catch { throw new ArgumentException(\"Invalid Hotkey\"); }\n\n// after\nif (!Enum.TryParse(typeof(Keys), keyStr, true, out var parsedKey))\n    throw new ArgumentException($\"Invalid key token: '{keyStr}'\", nameof(keyStr));\nKey = (Keys)parsedKey;","handlingStrategy":"try-catch","validationCode":"foreach (var tok in hotkeyStr.Replace(\" \", \"\").Split('+'))\n{\n    if (modifiers.Contains(tok, StringComparer.OrdinalIgnoreCase)) continue;\n    if (!Enum.TryParse(typeof(Keys), tok, true, out _))\n        return false; // invalid token, do not construct Hotkey\n}\nreturn true;","typeGuard":"static bool IsValidHotkeyString(string s)\n{\n    if (string.IsNullOrWhiteSpace(s)) return false;\n    foreach (var tok in s.Replace(\" \", \"\").Split('+'))\n    {\n        if (tok is \"Win\" or \"Ctrl\" or \"Shift\" or \"Alt\") continue;\n        if (!Enum.TryParse(typeof(Keys), tok, true, out _)) return false;\n    }\n    return true;\n}","tryCatchPattern":"Hotkey? hk = null;\ntry { hk = new Hotkey(stored); }\ncatch (ArgumentException) { hk = new Hotkey(); /* reset to empty/default */ }","preventionTips":["Use Enum.TryParse instead of Enum.Parse to avoid the catch-all.","Validate hotkey strings before persisting them to config.","Preserve the offending token in the error message for easier diagnosis."],"tags":["hotkey","config","parsing"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}