{"record":{"id":"2be9713ffe8950da","repo":"gitbutlerapp/gitbutler","slug":"failed-to-open-terminal-name-status-code-s","errorCode":null,"errorMessage":"Failed to open {terminal_name} ({status_code}): {stderr}","messagePattern":"Failed to open (.+?) \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/but-api/src/open/mod.rs","lineNumber":412,"sourceCode":"            tracing::info!(?cmd, \"terminal command\");\n            let output = cmd\n                .output()\n                .with_context(|| format!(\"Failed to launch {terminal_name} at '{path}'\"))?;\n\n            if output.status.success() {\n                return Ok(());\n            }\n\n            let stderr = output.stderr.to_str_lossy();\n            let stderr = stderr.trim();\n            let status_code = output\n                .status\n                .code()\n                .map_or(\"unknown\".to_string(), |c| c.to_string());\n            if stderr.is_empty() {\n                bail!(\"{terminal_name} exited with non-zero status: {status_code}\",);\n            } else {\n                bail!(\"Failed to open {terminal_name} ({status_code}): {stderr}\");\n            }\n        }\n\n        /// Check if a macOS application is installed using `open -Ra`.\n        fn ensure_app_installed(app_name: &str) -> Result<()> {\n            let status = Command::new(\"open\")\n                .arg(\"-Ra\")\n                .arg(app_name)\n                .stdout(Stdio::null())\n                .stderr(Stdio::null())\n                .status()\n                .context(\"Failed to run 'open -Ra' to check application availability\")?;\n            if !status.success() {\n                return Err(anyhow::anyhow!(\n                    \"'{app_name}' was not found - `open -Ra {app_name}` failed.\"\n                )\n                .context(but_error::Code::DefaultTerminalNotFound));\n            }","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-api/src/open/mod.rs#L394-L430","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Read the embedded stderr: it names the actual failing tool and reason","Fix the reported issue: correct app name/reinstall, repair wezterm config, or normalize the path","Reproduce by running the exact command shown in the error from a shell, then retry openInTerminal"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await client.openInTerminal(terminalId, repoPath);\n} catch (e) {\n  const m = /Failed to open (.+?) \\((\\d+)\\): (.*)/.exec(String(e));\n  if (m) {\n    const [, terminal, code, stderr] = m;\n    // surface stderr from `terminal` (exit code `code`) to the user\n  } else throw e;\n}","preventionTips":["Treat the embedded stderr as the source of truth; it names the failing tool","Keep terminal apps and their CLIs (wezterm) updated and config-error free","Prefer terminals whose launch path the backend fully controls (wezterm CLI)"],"tags":["terminal","macos","process-launch","stderr","rust"],"backgroundTag":"terminal-launch-failed","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}