Hmbown/CodeWhale · error

shell command failed

Error message

shell command failed (status={}): {}

What it means

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.

Solutions

  1. Read the stderr in the error message to see why the child failed
  2. Run the command manually in a shell to reproduce and fix it
  3. Check PATH, working directory, and file permissions for the invoked program
  4. If a non-zero exit is expected/acceptable, handle the error rather than treating it as fatal

Example fix

// before
dispatch("ls /nonexistent")
// after (shell)
ls /nonexistent 2>&1   # inspect the actual failure, then fix the command or its args
Defensive patterns

Strategy: try-catch

Validate before calling

fn exit_zero_ok(cmd: &str) -> bool {
    // cheap pre-checks: command exists on PATH, args quoted
    !cmd.trim().is_empty()
}

Try / catch

match dispatcher.run_foreground(cmd).await {
    Ok(output) => /* use output */,
    Err(e) if e.to_string().starts_with("shell command failed") => {
        // surface stderr from the message; decide if non-zero is acceptable
        eprintln!("command failed: {e}");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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'.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/6c51c9d1e58b0fb2. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/shell_dispatcher.rs:421

                if self.restore {
                    let _ = crossterm::terminal::enable_raw_mode();
                }
            }
        }
        let _guard = FgRawModeGuard {
            restore: raw_mode_was_enabled,
        };

        let mut cmd = self.build_command(shell_command);
        cmd.current_dir(cwd);

        let output = cmd
            .output()
            .with_context(|| format!("failed to execute shell command: {shell_command}"))?;

        if !output.status.success() {
            let stderr = String::from_utf8_lossy(&output.stderr);
            anyhow::bail!(
                "shell command failed (status={}): {}",
                output.status,
                stderr.trim()
            );
        }

        let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string();
        Ok(stdout)
    }

    // -- Detection --------------------------------------------------------

    fn detect_shell() -> ShellKind {
        #[cfg(test)]
        {
            // Non-blocking on purpose. This runs inside the `LazyLock`
            // initializer in `global_dispatcher()`, and a test that holds the
            // env barrier can reach `global_dispatcher()` while another thread

View on GitHub (pinned to 73e0f67d83)