{"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":null,"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/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/open/mod.rs#L394-L430","documentation":"The stderr-present sibling of error 142: the terminal emulator's launch command exited non-zero and printed a diagnostic to stderr, so run_terminal_command() includes the terminal name, status code, and stderr text in the error. This is the more informative variant and usually pinpoints the actual launch problem.","triggerScenarios":"open_in_terminal launches a terminal whose process exits non-zero and writes an error message to stderr (bad flag, missing profile, config parse error, etc.).","commonSituations":"Passing unsupported CLI flags to the terminal, a broken terminal config (e.g. invalid wezterm.lua or alacritty.yml), terminal not liking the --working-directory value, or a snap/flatpak-confined terminal refusing access.","solutions":["Read the stderr in the message and fix the reported terminal problem","Correct the terminal's configuration file referenced in stderr","Check the flags open_in_terminal passes for your terminal version and adjust/upgrade the terminal","Ensure the terminal has access to the target directory (sandbox/permission issues)"],"exampleFix":"// before (broken alacritty config)\n// bail!(\"Failed to open Alacritty (1): error parsing alacritty.yml\")\n// after: fix alacritty.yml, then\nopen_in_terminal(\"alacritty\", path)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match open_in_terminal(terminal_id, &path) {\n    Err(e) if e.to_string().starts_with(\"Failed to open \") => {\n        // surface stderr from the message to the user; offer another terminal\n        eprintln!(\"Terminal launch failed: {e}\");\n        open_in_terminal(\"fallback-terminal\", &path)?;\n    }\n    r => r?,\n}","preventionTips":["Read the stderr in the message — it names the actual terminal problem","Keep terminal config files (alacritty.yml, wezterm.lua) syntactically valid","Match CLI flags to the installed terminal version"],"tags":["terminal","process","stderr"],"backgroundTag":"command-failed-nonzero-status","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}