{"record":{"id":"3b189abf212c8cba","repo":"libnyanpasu/clash-nyanpasu","slug":"clash-core-not-found","errorCode":null,"errorMessage":"clash core not found","messagePattern":"clash core not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/core/manager.rs","lineNumber":9,"sourceCode":"use std::borrow::Cow;\n\n/// 给clash内核的tun模式授权\n#[cfg(any(target_os = \"macos\", target_os = \"linux\"))]\npub fn grant_permission(core: &nyanpasu_utils::core::CoreType) -> anyhow::Result<()> {\n    use std::process::Command;\n\n    let path = crate::core::find_binary_path(&core)\n        .map_err(|_| anyhow::anyhow!(\"clash core not found\"))?\n        .canonicalize()?\n        .to_string_lossy()\n        .to_string();\n\n    log::debug!(\"grant_permission path: {:?}\", path);\n\n    #[cfg(target_os = \"macos\")]\n    let output = {\n        // the path of clash /Applications/Clash Nyanpasu.app/Contents/MacOS/clash\n        // https://apple.stackexchange.com/questions/82967/problem-with-empty-spaces-when-executing-shell-commands-in-applescript\n        // let path = escape(&path);\n        let path = path.replace(' ', \"\\\\\\\\ \");\n        let shell = format!(\"chown root:admin {path}\\nchmod +sx {path}\");\n        let command = format!(r#\"do shell script \"{shell}\" with administrator privileges\"#);\n        Command::new(\"osascript\")\n            .args(vec![\"-e\", &command])\n            .output()?\n    };","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/core/manager.rs#L1-L27","documentation":"This error is thrown by `grant_permission`, which grants the clash core binary the capabilities needed for TUN mode on macOS/Linux. Before running the OS permission command it resolves the core binary via `crate::core::find_binary_path(&core)`; when that lookup fails for the requested `CoreType` (mihomo/clash/clash-rs), the result is mapped to \"clash core not found\". It means the sidecar/bundled core executable could not be located on disk, so the permission grant cannot proceed.","triggerScenarios":"Calling `core::manager::grant_permission(&CoreType::Mihomo)` (or another CoreType) when the corresponding sidecar binary is missing from the expected sidecar/resources directory, was not downloaded by `prepare:check`, or the binary name for that core type does not exist for the current platform.","commonSituations":"Fresh clone or worktree without running the sidecar download step; the user selected a core type whose binary was never shipped/downloaded; an upgrade changed the core binary filename so the lookup table no longer matches files on disk.","solutions":["Download/install the missing sidecar core (run the repo's `pnpm prepare:check` or the core download step) for the selected CoreType","Verify `crate::core::find_binary_path` for that CoreType points at an existing file (check the sidecar/resources directory contents)","Select a different, installed core type before enabling TUN/granting permission","Reinstall the app so bundled cores are restored"],"exampleFix":"// before\ngrant_permission(&CoreType::Mihomo)?;\n// after\nlet core = CoreType::Clash; // a core known to be installed in sidecar/\nif crate::core::find_binary_path(&core).is_ok() {\n    grant_permission(&core)?;\n}","handlingStrategy":"validation","validationCode":"fn ensure_core_installed(core: &nyanpasu_utils::core::CoreType) -> anyhow::Result<()> {\n    crate::core::find_binary_path(core)?; // errors early with a precise message\n    Ok(())\n}\nif let Err(e) = ensure_core_installed(&core) {\n    log::warn!(\"skipping TUN grant: {e:#}\");\n    return Ok(()); // degrade instead of failing permission flow\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the sidecar download step (`pnpm prepare:check`) after clone and in CI before packaging","Check the core binary exists for the selected CoreType before exposing the TUN/grant option in the UI","Add an integration test asserting `find_binary_path` resolves every shipped CoreType per platform","Log the resolved path once at startup so missing cores are obvious"],"tags":["rust","filesystem","tun-mode","core-binary"],"backgroundTag":"file-not-found","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"}