libnyanpasu/clash-nyanpasu · error

clash core not found

Error message

clash core not found

What it means

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.

Source

Thrown at backend/tauri/src/core/manager.rs:9

use std::borrow::Cow;

/// 给clash内核的tun模式授权
#[cfg(any(target_os = "macos", target_os = "linux"))]
pub fn grant_permission(core: &nyanpasu_utils::core::CoreType) -> anyhow::Result<()> {
    use std::process::Command;

    let path = crate::core::find_binary_path(&core)
        .map_err(|_| anyhow::anyhow!("clash core not found"))?
        .canonicalize()?
        .to_string_lossy()
        .to_string();

    log::debug!("grant_permission path: {:?}", path);

    #[cfg(target_os = "macos")]
    let output = {
        // the path of clash /Applications/Clash Nyanpasu.app/Contents/MacOS/clash
        // https://apple.stackexchange.com/questions/82967/problem-with-empty-spaces-when-executing-shell-commands-in-applescript
        // let path = escape(&path);
        let path = path.replace(' ', "\\\\ ");
        let shell = format!("chown root:admin {path}\nchmod +sx {path}");
        let command = format!(r#"do shell script "{shell}" with administrator privileges"#);
        Command::new("osascript")
            .args(vec!["-e", &command])
            .output()?
    };

View on GitHub (pinned to f7dbce2997)

Solutions

  1. Download/install the missing sidecar core (run the repo's `pnpm prepare:check` or the core download step) for the selected CoreType
  2. Verify `crate::core::find_binary_path` for that CoreType points at an existing file (check the sidecar/resources directory contents)
  3. Select a different, installed core type before enabling TUN/granting permission
  4. Reinstall the app so bundled cores are restored

Example fix

// before
grant_permission(&CoreType::Mihomo)?;
// after
let core = CoreType::Clash; // a core known to be installed in sidecar/
if crate::core::find_binary_path(&core).is_ok() {
    grant_permission(&core)?;
}
Defensive patterns

Strategy: validation

Validate before calling

fn ensure_core_installed(core: &nyanpasu_utils::core::CoreType) -> anyhow::Result<()> {
    crate::core::find_binary_path(core)?; // errors early with a precise message
    Ok(())
}
if let Err(e) = ensure_core_installed(&core) {
    log::warn!("skipping TUN grant: {e:#}");
    return Ok(()); // degrade instead of failing permission flow
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of libnyanpasu/clash-nyanpasu@f7dbce2997 (2026-09-08). Data as JSON: /api/errors/3b189abf212c8cba. Report an issue: GitHub.