{"record":{"id":"6c51c9d1e58b0fb2","repo":"Hmbown/CodeWhale","slug":"shell-command-failed-status","errorCode":null,"errorMessage":"shell command failed (status={}): {}","messagePattern":"shell command failed \\(status=(.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/shell_dispatcher.rs","lineNumber":421,"sourceCode":"                if self.restore {\n                    let _ = crossterm::terminal::enable_raw_mode();\n                }\n            }\n        }\n        let _guard = FgRawModeGuard {\n            restore: raw_mode_was_enabled,\n        };\n\n        let mut cmd = self.build_command(shell_command);\n        cmd.current_dir(cwd);\n\n        let output = cmd\n            .output()\n            .with_context(|| format!(\"failed to execute shell command: {shell_command}\"))?;\n\n        if !output.status.success() {\n            let stderr = String::from_utf8_lossy(&output.stderr);\n            anyhow::bail!(\n                \"shell command failed (status={}): {}\",\n                output.status,\n                stderr.trim()\n            );\n        }\n\n        let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string();\n        Ok(stdout)\n    }\n\n    // -- Detection --------------------------------------------------------\n\n    fn detect_shell() -> ShellKind {\n        #[cfg(test)]\n        {\n            // Non-blocking on purpose. This runs inside the `LazyLock`\n            // initializer in `global_dispatcher()`, and a test that holds the\n            // env barrier can reach `global_dispatcher()` while another thread","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/shell_dispatcher.rs#L403-L439","documentation":"run_foreground executes a shell command via cmd.output() and, if the process exits with a non-success status, bails with 'shell command failed (status=...)' including trimmed stderr. It means the command itself ran but reported failure — this surfaces the child's own failure, not a dispatch bug.","triggerScenarios":"Calling the shell dispatcher's run_foreground with a command that exits non-zero: bad exit codes from scripts, missing arguments to the invoked program, `grep`/`test` style non-zero semantic exits.","commonSituations":"Typo'd shell commands or flags; scripts failing due to env differences (missing PATH entries, permissions); a program legitimately exiting non-zero for 'no match' or 'no changes'.","solutions":["Read the stderr in the error message to see why the child failed","Run the command manually in a shell to reproduce and fix it","Check PATH, working directory, and file permissions for the invoked program","If a non-zero exit is expected/acceptable, handle the error rather than treating it as fatal"],"exampleFix":"// before\ndispatch(\"ls /nonexistent\")\n// after (shell)\nls /nonexistent 2>&1   # inspect the actual failure, then fix the command or its args","handlingStrategy":"try-catch","validationCode":"fn exit_zero_ok(cmd: &str) -> bool {\n    // cheap pre-checks: command exists on PATH, args quoted\n    !cmd.trim().is_empty()\n}","typeGuard":null,"tryCatchPattern":"match dispatcher.run_foreground(cmd).await {\n    Ok(output) => /* use output */,\n    Err(e) if e.to_string().starts_with(\"shell command failed\") => {\n        // surface stderr from the message; decide if non-zero is acceptable\n        eprintln!(\"command failed: {e}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check the command exists on PATH before dispatching","Run commands with explicit working directory and environment","Treat non-zero exits as data (some tools use them semantically) and handle explicitly"],"tags":["shell","process","command-execution","exit-code"],"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"}