nikivdev/code · error
failed to open browser
Error message
failed to open browser
What it means
`open_in_browser` (src/commit.rs:8927) on macOS runs `open <url>`; if the spawned process exits non-zero this bail reports the URL could not be opened in the system browser.
Source
Thrown at src/commit.rs:8927
.ok_or_else(|| anyhow::anyhow!("failed to parse PR number from URL {}", url))?;
return Ok((number, url));
}
if let Some(found) = gh_find_open_pr_by_head(repo_root, repo, head)? {
return Ok(found);
}
bail!(
"failed to determine PR URL after creation (gh output had no URL and PR lookup by head returned empty)"
);
}
fn open_in_browser(url: &str) -> Result<()> {
#[cfg(target_os = "macos")]
{
let status = Command::new("open").arg(url).status()?;
if !status.success() {
bail!("failed to open browser");
}
return Ok(());
}
#[cfg(not(target_os = "macos"))]
{
let status = Command::new("xdg-open").arg(url).status()?;
if !status.success() {
bail!("failed to open browser");
}
Ok(())
}
}
fn commit_message_title_body(message: &str) -> (String, String) {
let mut lines = message.lines();
let title = lines.next().unwrap_or("no title").trim().to_string();
let rest = lines.collect::<Vec<_>>().join("\n").trim().to_string();View on GitHub (pinned to a747e741ae)
Solutions
- Set a valid default browser in macOS System Settings > Desktop & Dock > Default web browser.
- Test `open <url>` in a terminal to confirm the environment can open URLs.
- Run in a GUI session instead of headless/SSH/CI, or use the PR URL already printed.
- Verify `/usr/bin/open` works (`open -a 'Safari' <url>`).
Defensive patterns
Strategy: fallback
Validate before calling
let check = Command::new("open").arg("-g").arg("https://example.com").status();
if check.map(|s| !s.success()).unwrap_or(true) {
eprintln!("`open` cannot launch a browser; print the URL instead");
} Type guard
fn can_open_browser() -> bool {
Command::new("open").arg("-g").arg("https://example.com")
.output().map(|o| o.status.success()).unwrap_or(false)
} Try / catch
if let Err(e) = open_in_browser(&url) {
eprintln!("could not open browser ({e}); open this URL manually:\n{url}");
// do not fail the whole PR-creation flow because browser launch failed
} Prevention
- Set an explicit default browser in macOS System Settings.
- In CI/headless environments, skip browser opening and rely on the printed URL.
- Treat browser-open failure as non-fatal; the PR URL is the source of truth.
When it happens
Trigger: `Command::new("open").arg(url).status()` spawns successfully but `open` returns non-zero: no default browser set, Launch Services failure, dangling default handler after a browser uninstall, or headless/sandboxed macOS environment.
Common situations: CI runner or SSH session on a Mac with no GUI session; default-browser registration pointing at an uninstalled app; container/sandbox where LaunchServices is unavailable.
Related errors
- codex skill-eval launchd install failed: {}
- pbcopy exited with status {}
- Refusing to disable Apple service '{}'. This could break you
- Failed to disable service: {}
- Failed to enable service: {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/754a00a04171ea72.
Report an issue: GitHub.