{"record":{"id":"46743baff8bda74d","repo":"opentofu/opentofu","slug":"s-w-46743b","errorCode":null,"errorMessage":"%s: %w","messagePattern":"%s: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/command/webbrowser/exec.go","lineNumber":45,"sourceCode":"func NewExecLauncher(execPath string) Launcher {\n\treturn execLauncher{\n\t\texecPath: execPath,\n\t}\n}\n\ntype execLauncher struct {\n\texecPath string\n}\n\nfunc (l execLauncher) OpenURL(url string) error {\n\tcmd := &exec.Cmd{\n\t\tPath: l.execPath,\n\t\tArgs: []string{l.execPath, url},\n\t\tEnv:  os.Environ(),\n\t}\n\terr := cmd.Run()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", l.execPath, err)\n\t}\n\treturn nil\n}\n\n// ParseBrowserEnv takes the raw value of a BROWSER environment variable and\n// attempts to parse it as a reference to an executable, whose absolute\n// path is returned if successful. Returns an empty string if the value cannot\n// be interpreted as an executable to run.\n//\n// This implements the simple form of this environment variable commonly used\n// by software on Unix-like systems, where the value must be literally just\n// a command to run whose first and only argument would be the URL to open.\n//\n// It does NOT support the more complex interpretation of that environment\n// variable that was proposed at http://www.catb.org/~esr/BROWSER/ , because\n// that form has not been widely implemented and the implementations that\n// exist do not have consistent behavior due to the proposal being\n// ambiguous.","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/opentofu/opentofu/blob/3561785c48c1ce615e7c50261bd351f26053efa2/internal/command/webbrowser/exec.go#L27-L63","documentation":"Returned by the exec-based browser launcher when the program named in the BROWSER environment variable exits non-zero or cannot be run. The launcher (used by 'tofu login' to open the browser for device/OAuth flows) builds an exec.Cmd with the BROWSER value as the executable and the URL as its only argument, and wraps any cmd.Run() failure as \"<execPath>: <cause>\".","triggerScenarios":"'tofu login' (or anything calling webbrowser.OpenURL) with BROWSER set to a command that fails to launch: binary not found ($PATH lookup failure), not executable, or the browser process returns a non-zero exit status (common on headless systems with browsers like w3m that fail without a display).","commonSituations":"SSH sessions or containers where BROWSER is set to something that needs a GUI; stale BROWSER value pointing at a removed browser; CI environments where 'tofu login' is attempted non-interactively.","solutions":["Unset BROWSER (or set it to a real, working browser command) and re-run 'tofu login'","If the auto-open fails, copy the printed URL and open it manually on any machine, then paste the code back - the login flow supports this","On headless machines use BROWSER=echo or similar so the URL is just printed","Verify the browser binary exists and is executable: which $BROWSER"],"exampleFix":"# before\nBROWSER=firefox tofu login   # fails: firefox: exec format error / not found\n# after\nBROWSER=echo tofu login      # prints URL to terminal for manual opening\n# or: unset BROWSER; tofu login","handlingStrategy":"fallback","validationCode":"# Before 'tofu login', confirm BROWSER is executable if set\nif [ -n \"$BROWSER\" ] && ! command -v \"${BROWSER%% *}\" >/dev/null 2>&1; then\n  echo \"BROWSER=$BROWSER is not runnable; falling back to manual URL\" >&2\n  BROWSER=echo tofu login\nelse\n  tofu login\nfi","typeGuard":"func browserLaunchErr(err error) bool {\n  // exec.go wraps as \"<execPath>: %w\" - match on ': exec:' or exit-error shapes\n  return err != nil && (strings.Contains(err.Error(), \": exec:\") || strings.Contains(err.Error(), \"exit status\"))\n}","tryCatchPattern":"err := browser.OpenURL(url)\nif err != nil {\n  // non-fatal by design: show the URL and continue the login flow manually\n  fmt.Printf(\"Could not open browser automatically (%v)\\nVisit this URL: %s\\n\", err, url)\n}","preventionTips":["Set BROWSER to something guaranteed to work headless (echo, or a real GUI browser on desktops)","Never depend on browser auto-open in automation - always plan for copy/paste of the login URL","Test 'tofu login' once per environment (container/CI) during setup, not during deployments"],"tags":["go","browser","login","environment","oauth"],"backgroundTag":null,"analyzedSha":"3561785c48c1ce615e7c50261bd351f26053efa2","analyzedAt":"2026-08-15T23:27:16.226Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}