{"record":{"id":"85aeb246774b7cfa","repo":"router-for-me/CLIProxyAPI","slug":"failed-to-start-browser-command-w","errorCode":null,"errorMessage":"failed to start browser command: %w","messagePattern":"failed to start browser command: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/browser/browser.go","lineNumber":74,"sourceCode":"\t\t// Try common Linux browsers in order of preference\n\t\tbrowsers := []string{\"xdg-open\", \"x-www-browser\", \"www-browser\", \"firefox\", \"chromium\", \"google-chrome\"}\n\t\tfor _, browser := range browsers {\n\t\t\tif _, err := exec.LookPath(browser); err == nil {\n\t\t\t\tcmd = exec.Command(browser, url)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif cmd == nil {\n\t\t\treturn fmt.Errorf(\"no suitable browser found on Linux system\")\n\t\t}\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported operating system: %s\", runtime.GOOS)\n\t}\n\n\tlog.Debugf(\"Running command: %s %v\", cmd.Path, cmd.Args[1:])\n\terr := cmd.Start()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to start browser command: %w\", err)\n\t}\n\n\tlog.Debug(\"Successfully opened URL using platform-specific command\")\n\treturn nil\n}\n\n// IsAvailable checks if the system has a command available to open a web browser.\n// It verifies the presence of necessary commands for the current operating system.\n//\n// Returns:\n//   - true if a browser can be opened, false otherwise.\nfunc IsAvailable() bool {\n\t// First check if open-golang can work\n\ttestErr := open.Run(\"about:blank\")\n\tif testErr == nil {\n\t\treturn true\n\t}\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/browser/browser.go#L56-L92","documentation":"A browser command was selected, but cmd.Start() failed to spawn it. Unlike the lookup failure (error 297), the binary exists on PATH; the exec itself failed — permission denied, broken launcher script, missing dynamic library, or resource limits.","triggerScenarios":"xdg-open exists but errors out immediately (broken .desktop handling, no DISPLAY under X11, exec format error), or a found binary lacks execute permission or its shared libraries.","commonSituations":"Headless session with no DISPLAY/WAYLAND_DISPLAY where GUI browsers fail to start; damaged xdg-utils install; containers with a browser binary but missing libs; PATH shims that shadow a real browser with a non-executable file.","solutions":["Check the wrapped error — exec.ErrNotFound vs permission denied vs library error point to different fixes","For headless use, run with --no-browser and open the printed verification URI manually","Reinstall/repair the launcher package (xdg-utils) or the browser if its binary is broken","Set DISPLAY/WAYLAND_DISPLAY correctly when a GUI session exists"],"exampleFix":"# before\n$ cli-proxy-api --login\n# error: failed to start browser command: exec: ... (no DISPLAY)\n\n# after\n$ cli-proxy-api --login --no-browser\n# then open the printed URL on any machine with a browser","handlingStrategy":"fallback","validationCode":"if !browser.IsAvailable() {\n    log.Infof(\"browser unavailable; open manually: %s\", url)\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := browser.OpenURL(url); err != nil {\n    log.Warnf(\"browser launch failed (%v); open manually: %s\", err, url)\n    // non-fatal: OAuth continues via the printed URL\n}","preventionTips":["Treat browser launch failure as non-fatal: always print the URL as the fallback path","Ensure DISPLAY/WAYLAND_DISPLAY is set in GUI sessions and xdg-utils is intact","Use --no-browser on headless hosts instead of relying on a broken launcher"],"tags":["browser","linux","exec","headless","oauth"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}