sinelaw/fresh · error

Command failed with exit code

Error message

Command failed with exit code: {:?}

What it means

run_shell_command_blocking runs an external shell command (suspending the TUI, restoring the shell, then waiting) and returns this error when the child process exits with a non-success status. The exit code is included in the message.

Solutions

  1. Read the exit code in the error and run the command manually in a terminal to see its stderr.
  2. Fix the command syntax/path so it exits 0.
  3. If a non-zero exit is expected/acceptable, catch the error and proceed instead of propagating it.

Example fix

// before
editor.run_shell_command_blocking("make test")?; // aborts on failure
// after
if let Err(e) = editor.run_shell_command_blocking("make test") {
    eprintln!("build command reported: {e}"); // non-zero exit tolerated
}
Defensive patterns

Strategy: try-catch

Try / catch

match editor.run_shell_command_blocking(cmd) { Err(e) if e.to_string().contains("Command failed with exit code") => report_exit(e), Err(e) => return Err(e), Ok(()) => Ok(()) }

Prevention

When it happens

Trigger: Any :! command or shell integration whose child process exits non-zero — status.success() is false (non-zero exit code, or None when killed by a signal).

Common situations: Typo in the shell command (127 command not found); command fails on file permissions; lint/build tool invoked via :! returns non-zero; command killed by a signal (code None).

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13). Data as JSON: /api/errors/bb61ee4aef8a28ed. Report an issue: GitHub.

Appendix: source

Thrown at crates/fresh-editor/src/app/shell_command.rs:286

            .map_err(|e| anyhow::anyhow!("Failed to spawn shell: {}", e))?;

        let status = child
            .wait()
            .map_err(|e| anyhow::anyhow!("Failed to wait for command: {}", e))?;

        // Resume TUI — best-effort, nothing useful to do on failure.
        #[allow(clippy::let_underscore_must_use)]
        let _ = stdout().execute(EnterAlternateScreen);
        #[allow(clippy::let_underscore_must_use)]
        let _ = enable_raw_mode();

        // Request a full hard redraw to clear any ghost text from the external command
        self.request_full_redraw();

        if status.success() {
            Ok(())
        } else {
            anyhow::bail!("Command failed with exit code: {:?}", status.code())
        }
    }
}

/// Detect the shell to use for executing commands.
fn detect_shell() -> String {
    // Try SHELL environment variable first
    if let Ok(shell) = std::env::var("SHELL") {
        if !shell.is_empty() {
            return shell;
        }
    }

    // Fall back to common shells
    #[cfg(unix)]
    {
        if std::path::Path::new("/bin/bash").exists() {
            return "/bin/bash".to_string();

View on GitHub (pinned to 67894ca546)