{"record":{"id":"0ffd5f849a35024c","repo":"xai-org/grok-build","slug":"failed-to-run-program-e","errorCode":null,"errorMessage":"failed to run {program}: {e}","messagePattern":"failed to run (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-pager/src/wrap_cmd.rs","lineNumber":208,"sourceCode":"\n/// Replace the current process with `program <args...>` (no PTY wrapping).\n#[cfg(unix)]\nfn exec_command(program: &str, args: &[String]) -> Result<()> {\n    use std::os::unix::process::CommandExt;\n\n    let err = std::process::Command::new(program).args(args).exec();\n\n    // exec() only returns on error.\n    Err(anyhow::anyhow!(\"failed to exec {program}: {err}\"))\n}\n\n/// On non-Unix platforms, spawn and wait.\n#[cfg(not(unix))]\nfn exec_command(program: &str, args: &[String]) -> Result<()> {\n    let status = std::process::Command::new(program)\n        .args(args)\n        .status()\n        .map_err(|e| anyhow::anyhow!(\"failed to run {program}: {e}\"))?;\n\n    std::process::exit(status.code().unwrap_or(1));\n}\n\n#[cfg(all(test, unix))]\n#[path = \"wrap_cmd_tests.rs\"]\nmod tests;\n","sourceCodeStart":190,"sourceCodeEnd":216,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager/src/wrap_cmd.rs#L190-L216","documentation":"On non-Unix platforms, `exec_command` falls back to spawning the program and waiting for its status; this error is returned when `Command::status()` fails to spawn the process (the child never ran). Unlike the Unix path, it cannot replace the process, so spawn failures surface as this anyhow error naming the program.","triggerScenarios":"On Windows or other non-Unix targets: the program name cannot be resolved to an executable (no PATH hit, wrong extension); insufficient permissions; the program path is a directory.","commonSituations":"Wrapping a Unix-only tool on Windows where it was never installed; missing .exe extension handling; antivirus or policy blocking process spawn; PATH differences between the shell and the spawned environment.","solutions":["Verify the program is installed on the target platform and resolvable on PATH.","On Windows ensure the name resolves with the correct executable extension or give an explicit path to the .exe.","Check that spawn permissions/AV policy allow launching the binary.","Use the inner `{e}` io::Error kind (NotFound/PermissionDenied) to choose between installing the tool vs fixing permissions."],"exampleFix":"// before\nexec_command(\"tool.sh\", &args)?; // .sh not executable on Windows\n// after\n#[cfg(windows)]\nlet program = String::from(\"tool.exe\");\n#[cfg(not(windows))]\nlet program = String::from(\"tool.sh\");\nexec_command(&program, &args)?;","handlingStrategy":"validation","validationCode":"fn can_spawn(program: &str) -> Result<(), String> {\n    let path = std::env::var(\"PATH\").unwrap_or_default();\n    for dir in path.split(';').chain(path.split(':')) {\n        let candidate = std::path::Path::new(dir).join(program);\n        if candidate.is_file() { return Ok(()); }\n    }\n    Err(format!(\"{program} not found on PATH\"))\n}","typeGuard":null,"tryCatchPattern":"match exec_command(program, &args) {\n    Ok(()) => {}\n    Err(e) if e.to_string().contains(\"not found\") => {\n        eprintln!(\"'{program}' is not installed on this platform\");\n        std::process::exit(127);\n    }\n    Err(e) => { eprintln!(\"spawn failed: {e:#}\"); std::process::exit(1); }\n}","preventionTips":["Test the wrapper on all supported platforms in CI; non-Unix uses spawn instead of exec.","Handle platform-specific executable naming (.exe, .cmd) explicitly.","Document platform requirements for wrapped tools."],"tags":["rust","process-spawn","windows","cross-platform"],"backgroundTag":"process-spawn-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}