{"record":{"id":"00fcc56dd1041771","repo":"gitbutlerapp/gitbutler","slug":"failed-to-execute-command-cmd-00fcc5","errorCode":null,"errorMessage":"Failed to execute command {cmd:?}","messagePattern":"Failed to execute command (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/but-path/src/lib.rs","lineNumber":306,"sourceCode":"            // e.g. run `but gui` in a terminal, and then keep using that terminal.\n            //\n            // This is only necessary on cold start, i.e. when the GUI isn't already running, as\n            // then this process becomes the GUI process. If the GUI is already running, this\n            // process effectively just sends the deep link to the already running GUI and then\n            // exits.\n            cmd.spawn()?;\n        };\n\n        #[cfg(not(target_os = \"linux\"))]\n        {\n            let mut cmd_errors = Vec::new();\n            for mut cmd in open::commands(url.as_str()) {\n                cmd.envs(cleaned_vars.clone());\n                cmd.current_dir(env::temp_dir());\n                if cmd.status().is_ok() {\n                    return Ok(());\n                } else {\n                    cmd_errors.push(anyhow::anyhow!(\"Failed to execute command {cmd:?}\"));\n                }\n            }\n            if !cmd_errors.is_empty() {\n                anyhow::bail!(\"Errors occurred: {cmd_errors:?}\");\n            }\n        }\n        Ok(())\n    }\n}\n\nfn build_open_url(\n    scheme: &str,\n    possibly_project_dir: &std::path::Path,\n    timestamp: u128,\n    new_window: bool,\n) -> anyhow::Result<url::Url> {\n    let mut url = url::Url::parse(&format!(\"{scheme}://open\"))?;\n    url.query_pairs_mut()","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-path/src/lib.rs#L288-L324","documentation":"On non-Linux platforms, `open_url_in_browser`-style logic iterates `open::commands(url)` (candidate launchers such as `open` on macOS or `cmd /C start` on Windows) and runs `cmd.status()` on each. When a candidate fails to spawn or exits nonzero, this per-command error is collected; if every candidate fails, the caller gets `Errors occurred: [Failed to execute command ...]`. It means the OS could not open the URL with any known browser-launch command.","triggerScenarios":"Running on macOS/Windows in a headless or locked-down session (CI runner, SSH without GUI, sandbox) where `open`/`start` fails; a URL no handler accepts; PATH so stripped the launcher binary cannot be found; a launcher that exits nonzero (e.g. no default browser configured).","commonSituations":"Automation invoking the CLI (`but gui`) on headless macOS/Windows runners; kiosk or restricted user accounts with no default browser; AppImage/sandboxed environments on non-Linux targets.","solutions":["Run the command from an interactive GUI session where a default browser is configured","Verify the URL being passed is well-formed (scheme + host)","Set/configure a default browser for the user account, or ensure the launcher (`open`, `cmd`) is on PATH","In code, treat failure as non-fatal: log the warning and surface the URL to the user so they can open it manually"],"exampleFix":"// before\nopen_url_in_browser(&url)?; // Errors occurred: [Failed to execute command ...]\n\n// after\nif let Err(e) = open_url_in_browser(&url) {\n    log::warn!(\"could not open browser ({e:#}); please visit {url} manually\");\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = but_path::open_url_in_browser(&url) {\n    // every candidate launcher failed; degrade to showing the URL\n    log::warn!(\"failed to open browser ({e:#})\");\n    println!(\"Open this URL manually: {url}\");\n}","preventionTips":["Only invoke browser opening from interactive GUI sessions; skip it when running headless (detect CI env vars)","Validate/normalize the URL before passing it to the opener","Never make URL-opening a hard dependency of a command's success"],"tags":["rust","os-integration","browser","process-spawn","macos-windows"],"backgroundTag":"failed-to-open-url","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}