{"record":{"id":"9d186134bd21f3f1","repo":"libnyanpasu/clash-nyanpasu","slug":"invalid-hotkey-function-s","errorCode":null,"errorMessage":"invalid hotkey function: {s}","messagePattern":"invalid hotkey function: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/core/hotkey.rs","lineNumber":142,"sourceCode":"}\n\nimpl FromStr for HotkeyFunc {\n    type Err = anyhow::Error;\n\n    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {\n        match s {\n            \"open_or_close_dashboard\" => Ok(HotkeyFunc::OpenOrCloseDashboard),\n            \"clash_mode_rule\" => Ok(HotkeyFunc::ClashModeRule),\n            \"clash_mode_global\" => Ok(HotkeyFunc::ClashModeGlobal),\n            \"clash_mode_direct\" => Ok(HotkeyFunc::ClashModeDirect),\n            \"clash_mode_script\" => Ok(HotkeyFunc::ClashModeScript),\n            \"toggle_system_proxy\" => Ok(HotkeyFunc::ToggleSystemProxy),\n            \"enable_system_proxy\" => Ok(HotkeyFunc::EnableSystemProxy),\n            \"disable_system_proxy\" => Ok(HotkeyFunc::DisableSystemProxy),\n            \"toggle_tun_mode\" => Ok(HotkeyFunc::ToggleTunMode),\n            \"enable_tun_mode\" => Ok(HotkeyFunc::EnableTunMode),\n            \"disable_tun_mode\" => Ok(HotkeyFunc::DisableTunMode),\n            _ => bail!(\"invalid hotkey function: {s}\"),\n        }\n    }\n}\n\npub struct Hotkey {\n    current: Arc<Mutex<Vec<String>>>, // 保存当前的热键设置\n\n    app_handle: Arc<Mutex<Option<AppHandle>>>,\n}\n// (hotkey, func)\ntype HotKeyOp<'a> = (&'a str, HotKeyOpType<'a>);\n\n#[derive(Debug)]\nenum HotKeyOpType<'a> {\n    #[allow(unused)]\n    Unbind(&'a str),\n    #[allow(unused)]\n    Change(&'a str, &'a str),","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/core/hotkey.rs#L124-L160","documentation":"HotkeyFunc::from_str parses user-provided hotkey function name strings (from config) into the HotkeyFunc enum. Unknown strings bail with 'invalid hotkey function: {s}'. The config file contained a function name that is not one of the recognized verbs (toggle/enable/disable system proxy or tun mode, etc.).","triggerScenarios":"A verge config hotkey mapping whose value is not one of the exact known strings — typos like 'toggle_sys_proxy', older/renamed function names, or non-English entries.","commonSituations":"Hand-edited config files; config migrated from an older version whose function names changed; users copying hotkey configs between forks with different verbs.","solutions":["Fix the config entry to use an exact supported name (e.g. toggle_system_proxy, enable_tun_mode)","Validate hotkey config at load/patch time and reject unknown functions with a clear UI message before application","Keep a deprecated-name alias map to migrate old function names on config load"],"exampleFix":"// config before\n\"hotkey\": { \"Ctrl+Alt+P\": \"toggle_sys_proxy\" }\n// after\n\"hotkey\": { \"Ctrl+Alt+P\": \"toggle_system_proxy\" }","handlingStrategy":"validation","validationCode":"const VALID_FUNCS: [&str; 9] = [\"open_or_close_dashboard\",\"clash_mode_rule\",\"clash_mode_global\",\"clash_mode_direct\",\"toggle_system_proxy\",\"enable_system_proxy\",\"disable_system_proxy\",\"toggle_tun_mode\",\"enable_tun_mode\",\"disable_tun_mode\"];\nfn hotkey_func_valid(s: &str) -> bool { VALID_FUNCS.contains(&s) }","typeGuard":null,"tryCatchPattern":"match s.parse::<HotkeyFunc>() {\n    Ok(f) => f,\n    Err(e) => return Err(config_error(format!(\"unknown hotkey function: {e}\"))),\n}","preventionTips":["Validate hotkey function names at config load/patch time","Use a frontend dropdown of valid verbs instead of free text","Maintain alias mapping for renamed legacy functions"],"tags":["hotkey","config","parsing"],"backgroundTag":"invalid-enum-value","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"}