{"record":{"id":"43f77d090e44bc9c","repo":"Hmbown/CodeWhale","slug":"command-failed-with-exit-code-exit-code","errorCode":null,"errorMessage":"Command failed with exit code {exit_code}","messagePattern":"Command failed with exit code (.+?)","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":10599,"sourceCode":"        let exit_code = status.code().unwrap_or(-1);\n        let sandbox_type = exec_env.sandbox_type;\n        let sandbox_denied = SandboxManager::was_denied(sandbox_type, exit_code, &stderr_str);\n\n        if !stdout.is_empty() {\n            print!(\"{}\", String::from_utf8_lossy(&stdout));\n        }\n        if !stderr.is_empty() {\n            eprint!(\"{stderr_str}\");\n        }\n        if sandbox_denied {\n            eprintln!(\n                \"{}\",\n                SandboxManager::denial_message(sandbox_type, &stderr_str)\n            );\n        }\n\n        if !status.success() {\n            bail!(\"Command failed with exit code {exit_code}\");\n        }\n    } else {\n        let _ = child.kill();\n        let _ = child.wait();\n        bail!(\"Command timed out after {}ms\", timeout.as_millis());\n    }\n    Ok(())\n}\n\nfn parse_sandbox_policy(\n    policy: &str,\n    network: bool,\n    writable_root: Vec<PathBuf>,\n    exclude_tmpdir: bool,\n    exclude_slash_tmp: bool,\n) -> Result<crate::sandbox::SandboxPolicy> {\n    use crate::sandbox::SandboxPolicy;\n","sourceCodeStart":10581,"sourceCodeEnd":10617,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L10581-L10617","documentation":"A sandboxed command (spawned by the sandbox runner in the TUI CLI) finished and returned a non-success exit status. After printing any sandbox denial message, the wrapper bails with the observed exit code so callers see the child's failure as an error rather than silently succeeding.","triggerScenarios":"Running a command through the sandbox helper where the spawned process exits non-zero and no timeout occurred (`status.success()` is false).","commonSituations":"The command itself failed (bad args, missing file), or the sandbox denied an operation and the process exited with an error code — check the printed denial message and stderr above the bail.","solutions":["Inspect the command's stderr/stdout printed before this error to find the real failure.","If a sandbox denial message was shown, adjust the sandbox policy (e.g. grant network or writable roots).","Fix the underlying command invocation and re-run."],"exampleFix":"// before: policy lacks network for a curl-based build step\nparse_sandbox_policy(\"workspace-write\")\n// after\nparse_sandbox_policy(\"workspace-write\") // plus network_access: true in policy config","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match run_sandboxed(cmd).await {\n    Err(e) if e.to_string().contains(\"Command failed with exit code\") => {\n        // inspect printed stderr/denial message, decide on policy fix vs command fix\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {}\n}\n","preventionTips":["Always surface the child's stderr next to this error; it names the real cause.","Watch for the sandbox denial message printed before the bail — it indicates policy, not command, failure.","Test new commands unsandboxed or with a permissive policy first."],"tags":["sandbox","process","exit-code","cli"],"backgroundTag":"http-error-response","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"}