{"record":{"id":"e44504f4ac36103b","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-get-core-version","errorCode":null,"errorMessage":"failed to get core version","messagePattern":"failed to get core version","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"backend/tauri/src/utils/resolve.rs","lineNumber":795,"sourceCode":"    };\n    app_handle.get_webview_window(window.label()).is_some()\n}\n\n/// resolve core version\n// TODO: use enum instead\npub async fn resolve_core_version(app_handle: &AppHandle, core_type: &ClashCore) -> Result<String> {\n    let shell = app_handle.shell();\n    let core = core_type.clone().to_string();\n    log::debug!(target: \"app\", \"check config in `{core}`\");\n    let cmd = match core_type {\n        ClashCore::ClashPremium | ClashCore::Mihomo | ClashCore::MihomoAlpha | ClashCore::Meow => {\n            shell.sidecar(core)?.args([\"-v\"])\n        }\n        ClashCore::ClashRs | ClashCore::ClashRsAlpha => shell.sidecar(core)?.args([\"-V\"]),\n    };\n    let out = cmd.output().await?;\n    if !out.status.success() {\n        return Err(anyhow::anyhow!(\"failed to get core version\"));\n    }\n    let out = String::from_utf8_lossy(&out.stdout);\n    log::trace!(target: \"app\", \"get core version: {out:?}\");\n    let out = out.trim().split(' ').collect::<Vec<&str>>();\n    for item in out {\n        log::debug!(target: \"app\", \"check item: {item}\");\n        if item.starts_with('v')\n            || item.starts_with('n')\n            || item.starts_with(\"alpha\")\n            || Version::parse(item).is_ok()\n        {\n            match core_type {\n                ClashCore::ClashRs => return Ok(format!(\"v{}\", item)),\n                _ => return Ok(item.to_string()),\n            }\n        }\n    }\n    Err(anyhow::anyhow!(\"failed to get core version\"))","sourceCodeStart":777,"sourceCodeEnd":813,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/utils/resolve.rs#L777-L813","documentation":"resolve_core_version spawns the selected clash core sidecar binary with -v/-V and captures its output. If the process exits with a non-zero status, the version cannot be trusted, so this error is raised. It indicates the core binary is present (the command ran) but reported failure.","triggerScenarios":"cmd.output() succeeded but out.status.success() is false — the core binary rejects the -v flag, fails to initialize, or crashes at startup.","commonSituations":"Core version changed and no longer supports -v/-V; broken/incompatible build of mihomo or clash-rs; missing dynamic libraries or runtime deps causing early exit; sidecar mismatched with the platform.","solutions":["Log/print out.stderr to see the core's own failure message","Run the core binary manually with -v (or -V for clash-rs) to reproduce and read the error","Re-download or reinstall the core sidecar (pnpm prepare:check) to fix a corrupt/mismatched binary","If a newer core dropped the -v flag, update the flag mapping in the match on ClashCore"],"exampleFix":"// before\nif !out.status.success() {\n    return Err(anyhow::anyhow!(\"failed to get core version\"));\n}\n// after: include stderr for diagnosis\nif !out.status.success() {\n    return Err(anyhow::anyhow!(\n        \"failed to get core version (status {:?}): {}\",\n        out.status,\n        String::from_utf8_lossy(&out.stderr)\n    ));\n}","handlingStrategy":"try-catch","validationCode":"let ok = tokio::process::Command::new(core_path)\n    .arg(\"-v\")\n    .output().await\n    .map(|o| o.status.success())\n    .unwrap_or(false);\nif !ok { log::warn!(\"core binary cannot report version\"); }","typeGuard":null,"tryCatchPattern":"match resolve_core_version(core).await {\n    Ok(v) => log::info!(\"core version: {v}\"),\n    Err(e) => {\n        log::error!(\"core version check failed: {e:#}\");\n        // fall back to assumed version or prompt reinstall\n    }\n}","preventionTips":["Re-download sidecars after core version upgrades (prepare:check)","Run the core binary manually with -v/-V after updates to verify output","Check platform/arch compatibility of the sidecar build","Capture stderr and include it in the error for faster diagnosis"],"tags":["process","sidecar","core","version-check"],"backgroundTag":"http-request-failed","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"}