gitbutlerapp/gitbutler · error · anyhow::Error

Failed to open {terminal_name} ({status_code}): {stderr}

Error message

Failed to open {terminal_name} ({status_code}): {stderr}

What it means

Same macOS run_terminal_command path (crates/but-api/src/open/mod.rs:412): the terminal launch command exited non-zero and its trimmed stderr is non-empty, so the bail embeds the terminal name, status code, and the tool's own stderr for diagnosis.

Source

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

            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."
                )
                .context(but_error::Code::DefaultTerminalNotFound));
            }

View on GitHub (pinned to caf1f223d3)

Solutions

  1. Read the embedded stderr: it names the actual failing tool and reason
  2. Fix the reported issue: correct app name/reinstall, repair wezterm config, or normalize the path
  3. Reproduce by running the exact command shown in the error from a shell, then retry openInTerminal
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await client.openInTerminal(terminalId, repoPath);
} catch (e) {
  const m = /Failed to open (.+?) \((\d+)\): (.*)/.exec(String(e));
  if (m) {
    const [, terminal, code, stderr] = m;
    // surface stderr from `terminal` (exit code `code`) to the user
  } else throw e;
}

Prevention

When it happens

Trigger: `open -a` reporting a specific error (application not found under that name, malformed path), or the wezterm CLI failing with a config error written to stderr.

Common situations: App name mismatch after a rename (e.g. iTerm vs iTerm2), terminal bundle damaged, wezterm config syntax error, path with spaces quoted incorrectly by a wrapper.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20). Data as JSON: /api/errors/2be9713ffe8950da. Report an issue: GitHub.