{"record":{"id":"3532e6988b525924","repo":"Hmbown/CodeWhale","slug":"failed-to-run-command-e","errorCode":null,"errorMessage":"Failed to run command: {e}","messagePattern":"Failed to run command: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":10553,"sourceCode":"\n    let (program, args) = command\n        .split_first()\n        .ok_or_else(|| anyhow::anyhow!(\"Command is required\"))?;\n    let spec =\n        CommandSpec::program(program, args.to_vec(), cwd.clone(), timeout).with_policy(policy);\n    let manager = SandboxManager::new();\n    let exec_env = manager.prepare(&spec);\n\n    let mut cmd = Command::new(exec_env.program());\n    cmd.args(exec_env.args())\n        .current_dir(&exec_env.cwd)\n        .stdout(Stdio::piped())\n        .stderr(Stdio::piped());\n    child_env::apply_to_command(&mut cmd, child_env::string_map_env(&exec_env.env));\n\n    let mut child = cmd\n        .spawn()\n        .map_err(|e| anyhow::anyhow!(\"Failed to run command: {e}\"))?;\n    let stdout_handle = child\n        .stdout\n        .take()\n        .ok_or_else(|| anyhow::anyhow!(\"stdout unavailable\"))?;\n    let stderr_handle = child\n        .stderr\n        .take()\n        .ok_or_else(|| anyhow::anyhow!(\"stderr unavailable\"))?;\n\n    let timeout = exec_env.timeout;\n    let stdout_thread = std::thread::spawn(move || {\n        let mut reader = stdout_handle;\n        let mut buf = Vec::new();\n        let _ = reader.read_to_end(&mut buf);\n        buf\n    });\n    let stderr_thread = std::thread::spawn(move || {\n        let mut reader = stderr_handle;","sourceCodeStart":10535,"sourceCodeEnd":10571,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L10535-L10571","documentation":"This error wraps a failed `Command::spawn()` when the TUI launches an external child process with piped stdout/stderr. `spawn()` only fails at exec/startup time — the binary could not be found, permissions were denied, or the OS refused to fork. The message embeds the underlying OS error via anyhow.","triggerScenarios":"Any code path that runs an external command through this helper (e.g. an exec tool) when the program path does not exist, is not executable, or the process cannot be forked.","commonSituations":"Command name not on PATH or misspelled; binary built for wrong platform; missing execute permission; environment stripping PATH so bare names don't resolve; resource limits preventing fork.","solutions":["Check the wrapped OS error text: 'No such file or directory' means the binary path/name is wrong","Use an absolute path to the binary instead of relying on PATH","Verify the file exists and is executable (`which <cmd>`, `chmod +x`)","If child_env::apply_to_command overrides env, confirm PATH is preserved"],"exampleFix":"// before\nlet mut child = cmd.spawn().map_err(|e| anyhow::anyhow!(\"Failed to run command: {e}\"))?;\n// after\nlet program = which::which(&program).map_err(|e| anyhow::anyhow!(\"command `{program}` not found: {e}\"))?;\nlet mut child = cmd.spawn().map_err(|e| anyhow::anyhow!(\"Failed to run command `{program}`: {e}\"))?;","handlingStrategy":"try-catch","validationCode":"const path = whichSync(cmd);\nif (!fs.existsSync(path) || !(fs.statSync(path).mode & 0o111)) throw new Error(`${cmd} not executable`);","typeGuard":"fn is_spawnable(cmd: &str) -> bool {\n    which::which(cmd).map(|p| p.is_file()).unwrap_or(false)\n}","tryCatchPattern":"match cmd.spawn() {\n    Ok(child) => child,\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        eprintln!(\"command not found: {}\", program); return;\n    }\n    Err(e) => return Err(anyhow::anyhow!(\"Failed to run command: {e}\")),\n}","preventionTips":["Resolve commands to absolute paths at startup and fail fast if missing","Never strip PATH from child env without substituting it","Check executable permission when configuring tools"],"tags":["process","spawn","command"],"backgroundTag":"command-not-found","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}