{"record":{"id":"754a00a04171ea72","repo":"nikivdev/code","slug":"failed-to-open-browser","errorCode":null,"errorMessage":"failed to open browser","messagePattern":"failed to open browser","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":8927,"sourceCode":"            .ok_or_else(|| anyhow::anyhow!(\"failed to parse PR number from URL {}\", url))?;\n        return Ok((number, url));\n    }\n\n    if let Some(found) = gh_find_open_pr_by_head(repo_root, repo, head)? {\n        return Ok(found);\n    }\n\n    bail!(\n        \"failed to determine PR URL after creation (gh output had no URL and PR lookup by head returned empty)\"\n    );\n}\n\nfn open_in_browser(url: &str) -> Result<()> {\n    #[cfg(target_os = \"macos\")]\n    {\n        let status = Command::new(\"open\").arg(url).status()?;\n        if !status.success() {\n            bail!(\"failed to open browser\");\n        }\n        return Ok(());\n    }\n\n    #[cfg(not(target_os = \"macos\"))]\n    {\n        let status = Command::new(\"xdg-open\").arg(url).status()?;\n        if !status.success() {\n            bail!(\"failed to open browser\");\n        }\n        Ok(())\n    }\n}\n\nfn commit_message_title_body(message: &str) -> (String, String) {\n    let mut lines = message.lines();\n    let title = lines.next().unwrap_or(\"no title\").trim().to_string();\n    let rest = lines.collect::<Vec<_>>().join(\"\\n\").trim().to_string();","sourceCodeStart":8909,"sourceCodeEnd":8945,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L8909-L8945","documentation":"`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.","triggerScenarios":"`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.","commonSituations":"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.","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>`)."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"let check = Command::new(\"open\").arg(\"-g\").arg(\"https://example.com\").status();\nif check.map(|s| !s.success()).unwrap_or(true) {\n    eprintln!(\"`open` cannot launch a browser; print the URL instead\");\n}","typeGuard":"fn can_open_browser() -> bool {\n    Command::new(\"open\").arg(\"-g\").arg(\"https://example.com\")\n        .output().map(|o| o.status.success()).unwrap_or(false)\n}","tryCatchPattern":"if let Err(e) = open_in_browser(&url) {\n    eprintln!(\"could not open browser ({e}); open this URL manually:\\n{url}\");\n    // do not fail the whole PR-creation flow because browser launch failed\n}","preventionTips":["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."],"tags":["macos","browser","process-execution"],"backgroundTag":"browser-open-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}