gitbutlerapp/gitbutler · error

exited with non-zero status

Error message

{terminal_name} exited with non-zero status: {status_code}

What it means

run_terminal_command() runs a terminal emulator's launch command and captures output. If the command exits with a non-zero status and stderr is empty, there is nothing more specific to report, so it bails naming the terminal and its exit status code. It signals the terminal emulator rejected or failed the launch without producing a diagnostic.

Solutions

  1. Run the same terminal command manually to see its exit behavior
  2. Fix the terminal emulator's configuration or environment (DISPLAY, Wayland socket)
  3. Verify the cwd passed to open_in_terminal is accessible from the terminal process
  4. Update or reinstall the terminal emulator

Example fix

// before
open_in_terminal("wezterm", broken_path) // exits non-zero, silent
// after
open_in_terminal("wezterm", "/home/user/project") // valid dir
Defensive patterns

Strategy: try-catch

Validate before calling

// check the terminal binary is launchable before delegating
if which::which(terminal::terminal_binary(terminal_id)).is_err() {
    return Err(anyhow!("terminal {terminal_id} not installed"));
}

Try / catch

match open_in_terminal(terminal_id, &path) {
    Err(e) if e.to_string().contains("exited with non-zero status") => {
        eprintln!("{terminal_id} failed silently ({e}); try running it manually");
    }
    r => r?,
}

Prevention

When it happens

Trigger: open_in_terminal launches a configured terminal (e.g. WezTerm, GNOME Terminal, iTerm) whose process exits non-zero without writing to stderr.

Common situations: Terminal binary present but crashing on startup, bad terminal config file, sandbox/display issues (no DISPLAY/Wayland), or terminal exiting immediately due to invalid --cwd arguments.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/8a40cbaaa2438107. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-api/src/open/mod.rs:410

            use bstr::ByteSlice;

            tracing::info!(?cmd, "terminal command");
            let output = cmd
                .output()
                .with_context(|| format!("Failed to launch {terminal_name} at '{path}'"))?;

            if output.status.success() {
                return Ok(());
            }

            let stderr = output.stderr.to_str_lossy();
            let stderr = stderr.trim();
            let status_code = output
                .status
                .code()
                .map_or("unknown".to_string(), |c| c.to_string());
            if stderr.is_empty() {
                bail!("{terminal_name} exited with non-zero status: {status_code}",);
            } else {
                bail!("Failed to open {terminal_name} ({status_code}): {stderr}");
            }
        }

        /// Check if a macOS application is installed using `open -Ra`.
        fn ensure_app_installed(app_name: &str) -> Result<()> {
            let status = Command::new("open")
                .arg("-Ra")
                .arg(app_name)
                .stdout(Stdio::null())
                .stderr(Stdio::null())
                .status()
                .context("Failed to run 'open -Ra' to check application availability")?;
            if !status.success() {
                return Err(anyhow::anyhow!(
                    "'{app_name}' was not found - `open -Ra {app_name}` failed."
                )

View on GitHub (pinned to 58e5313667)