{"record":{"id":"bf52ada543365f93","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-execute-sidecar-command","errorCode":null,"errorMessage":"failed to execute sidecar command","messagePattern":"failed to execute sidecar command","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/utils/collect.rs","lineNumber":78,"sourceCode":"        memory: Cow::Owned(SizeFormatter::new(system.total_memory(), BINARY).to_string()),\n    };\n\n    let mut core = BTreeMap::new();\n    for c in CoreType::get_supported_cores() {\n        let name: &str = c.as_ref();\n\n        let mut command = std::process::Command::new(\n            super::dirs::get_data_or_sidecar_path(name)\n                .map_err(|e| std::io::Error::other(e.to_string()))?,\n        );\n        command.args(if matches!(c, CoreType::Clash(ClashCoreType::ClashRust)) {\n            [\"-V\"]\n        } else {\n            [\"-v\"]\n        });\n        #[cfg(windows)]\n        let command = command.creation_flags(0x08000000);\n        let output = command.output().expect(\"failed to execute sidecar command\");\n        let stdout = String::from_utf8_lossy(&output.stdout);\n        core.insert(\n            Cow::Borrowed(name),\n            Cow::Owned(stdout.replace(\"\\n\\n\", \" \").trim().to_owned()),\n        );\n    }\n    Ok(EnvInfo {\n        os: Cow::Owned(\n            format!(\n                \"{} {}\",\n                System::long_os_version().unwrap_or(\"\".to_string()),\n                System::kernel_version().unwrap_or(\"\".to_string()),\n            )\n            .trim()\n            .to_owned(),\n        ),\n        arch: Cow::Owned(System::cpu_arch()),\n        core,","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/utils/collect.rs#L60-L96","documentation":"`collect_envs` runs the bundled mihomo/clash sidecar binary with `-v`/`-V` to harvest version info and unwraps `Command::output()` with this message. The expect panics if the child process cannot be spawned or waited on — typically because the sidecar executable is missing, not executable, or the platform spawn call fails. This is a startup/environment error surfaced as a hard panic rather than a Result.","triggerScenarios":"Calling `collect_envs` when the sidecar binary path does not exist (download/symlink step skipped, e.g. fresh checkout without `pnpm prepare:check`), the file lacks the execute bit (Linux/macOS) or is blocked/quarantined (Windows/macOS Gatekeeper), or the OS resource limits prevent process creation.","commonSituations":"Building in a fresh worktree where `backend/tauri/sidecar/` was not populated; antivirus or quarantine attributes blocking the downloaded core; wrong architecture binary (arm64 vs x64); running from a stripped package that excluded the sidecar resources.","solutions":["Ensure the sidecar core binaries are downloaded/linked: run `pnpm prepare:check` (or the repo's prepare script) so `backend/tauri/sidecar/` is populated.","Check the binary exists and is executable (`chmod +x` on Unix; unblock/quarantine removal on Windows/macOS).","Verify the architecture of the sidecar matches the host; re-download the correct core.","Handle the error gracefully by replacing `.expect(...)` with error propagation/logging so missing sidecars degrade instead of panicking."],"exampleFix":"// before\nlet output = command.output().expect(\"failed to execute sidecar command\");\n// after\nlet output = command.output().map_err(|e| {\n    anyhow::anyhow!(\"failed to execute sidecar command: {e}\")\n})?;","handlingStrategy":"fallback","validationCode":"let sidecar = sidecar_path.as_ref();\nif !sidecar.exists() {\n    eprintln!(\"sidecar binary missing: {}\", sidecar.display());\n}\n#[cfg(unix)]\n{\n    use std::os::unix::fs::PermissionsExt;\n    let mode = sidecar.metadata().map(|m| m.permissions().mode());\n    if !matches!(mode, Some(m) if m & 0o111 != 0) {\n        eprintln!(\"sidecar binary is not executable\");\n    }\n}","typeGuard":null,"tryCatchPattern":"let output = match command.output() {\n    Ok(o) => o,\n    Err(e) => {\n        tracing::warn!(\"sidecar spawn failed: {e}; skipping env collection\");\n        return;\n    }\n};","preventionTips":["Run the repo's prepare/sidecar download script after fresh clones and worktrees","Verify sidecar architecture matches the host before shipping","Check quarantine/AV status of downloaded cores on macOS/Windows"],"tags":["rust","sidecar","process-spawn","panic"],"backgroundTag":"command-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"}