{"record":{"id":"57b6ebcab77a5064","repo":"libnyanpasu/clash-nyanpasu","slug":"hotkey-error-invalid-hotkey","errorCode":null,"errorMessage":"hotkey_error.invalid_hotkey","messagePattern":"hotkey_error\\.invalid_hotkey","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/core/hotkey.rs","lineNumber":234,"sourceCode":"                    _ => {\n                        let key = key.unwrap_or(\"None\");\n                        let func = func.unwrap_or(\"None\");\n                        log::error!(target: \"app\", \"invalid hotkey `{key}`:`{func}`\");\n                    }\n                }\n            }\n            *self.current.lock() = hotkeys;\n        }\n\n        Ok(())\n    }\n\n    /// 检查一个键是否合法\n    fn check_key(hotkey: &str) -> anyhow::Result<()> {\n        // fix #287\n        // tauri的这几个方法全部有Result expect，会panic，先检测一遍避免挂了\n        if hotkey.parse::<Shortcut>().is_err() {\n            bail!(\"{}\", t!(\"hotkey_error.invalid_hotkey\", hotkey = hotkey));\n        }\n        // Validate super key requirement\n        if !Self::validate_super_key(hotkey) {\n            bail!(\"{}\", t!(\"hotkey_error.missing_super_key\"));\n        }\n        Ok(())\n    }\n\n    /// Check if the hotkey contains a super key modifier (case-insensitive)\n    pub fn validate_super_key(hotkey: &str) -> bool {\n        let hotkey_lower = hotkey.to_lowercase();\n        SUPER_KEYS\n            .iter()\n            .any(|key| hotkey_lower.contains(&key.to_lowercase()))\n    }\n\n    fn register(&self, hotkey: &str, func: &str) -> Result<()> {\n        let app_handle = self.app_handle.lock();","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/core/hotkey.rs#L216-L252","documentation":"check_key validates a hotkey string by parsing it as a global-hotkey Shortcut before registering, because Tauri's shortcut APIs panic on invalid input. If parsing fails it bails with the localized message hotkey_error.invalid_hotkey (which includes the offending hotkey). This is a pre-flight guard converting would-be panics into errors.","triggerScenarios":"registering/updating a hotkey whose string cannot parse as a Shortcut — wrong separator, missing modifier, unknown key name (e.g. 'Ctrl+Alt+PrtSc', 'Meta+A' unsupported forms, empty string).","commonSituations":"Users typing hotkeys manually in config; frontend sending malformed accelerator strings; platform-specific key names not recognized on all OSes.","solutions":["Correct the hotkey string to a valid accelerator (modifier+key, e.g. CmdOrCtrl+Shift+P) and re-save config","Validate hotkeys in the frontend picker before persisting them","Surface the localized hotkey_error.invalid_hotkey message (it already includes the bad value) to guide the user"],"exampleFix":"// config before\n\"Ctrl Alt P\": \"toggle_system_proxy\"\n// after\n\"Ctrl+Alt+P\": \"toggle_system_proxy\"","handlingStrategy":"validation","validationCode":"fn is_valid_hotkey(hotkey: &str) -> bool {\n    hotkey.parse::<global_hotkey::Shortcut>().is_ok()\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = Hotkey::register(hotkey, func) {\n    ui.show_error(t!(\"hotkey_error.invalid_hotkey\", hotkey = hotkey));\n}","preventionTips":["Validate hotkey strings in the frontend picker before saving","Use a GUI shortcut recorder instead of free-text input","Test hotkey strings per target platform"],"tags":["hotkey","validation","localization"],"backgroundTag":"invalid-argument-format","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}