{"record":{"id":"6a63645fce371bbf","repo":"browsh-org/browsh","slug":"browsh-tried-to-run-s-but-failed-with-s-err","errorCode":null,"errorMessage":"Browsh tried to run `%s` but failed with: %s, err: %w","messagePattern":"Browsh tried to run `(.+?)` but failed with: (.+?), err: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"interfacer/src/browsh/browsh.go","lineNumber":124,"sourceCode":"\tif err := file.Sync(); err != nil {\n\t\tShutdown(err)\n\t}\n\tfullPath := file.Name() + \".jpg\"\n\tif err := os.Rename(file.Name(), fullPath); err != nil {\n\t\tShutdown(err)\n\t}\n\tmessage := \"Screenshot saved to \" + fullPath\n\tsendMessageToWebExtension(\"/status,\" + message)\n}\n\n// Shell provides nice and easy shell commands\nfunc Shell(command string) string {\n\tparts := strings.Fields(command)\n\thead := parts[0]\n\tparts = parts[1:]\n\tout, err := exec.Command(head, parts...).CombinedOutput()\n\tif err != nil {\n\t\terr := fmt.Errorf(\n\t\t\t\"Browsh tried to run `%s` but failed with: %s, err: %w\",\n\t\t\tcommand,\n\t\t\tstring(out),\n\t\t\terr,\n\t\t)\n\t\tShutdown(err)\n\t}\n\treturn strings.TrimSpace(string(out))\n}\n\n// TTYStart starts Browsh\nfunc TTYStart(injectedScreen tcell.Screen) {\n\tscreen = injectedScreen\n\tsetupTcell()\n\twriteString(1, 0, logo, tcell.StyleDefault)\n\twriteString(\n\t\t0,\n\t\t15,","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/browsh-org/browsh/blob/499ef386d45cd1e2b5457dd04887c017f77b7e27/interfacer/src/browsh/browsh.go#L106-L142","documentation":"`Shell` is browsh's helper for running external commands (`ps aux`, `git rev-parse`, `firefox --version`, etc.). When `exec.Command(...).CombinedOutput()` returns an error, browsh wraps the command, its combined output, and the underlying error via `%w` and calls `Shutdown`. Since core logic depends on these shell calls, any failure is fatal.","triggerScenarios":"Any caller (`checkIfFirefoxIsAlreadyRunning`, `startWERFirefox`, `getFirefoxPath`, `ensureFirefoxVersion`, `stopFirefox`) invokes a command whose binary is missing (PATH lookup fails), exits non-zero, or is unlaunchable — e.g. `ps` or `git` not installed in a slim container.","commonSituations":"Running browsh in a minimal Docker image without `ps` or `git`; `git rev-parse --show-toplevel` executed outside a git repo during web-ext dev mode; PATH lacking standard system directories when launched from a daemon/IDE; a Firefox path failing to execute with `--version`.","solutions":["Read the wrapped output in the message to identify which command failed and why.","Install the missing tool in the environment (e.g. `apt-get install -y procps git` in Debian slim images).","For the web-ext dev path, run browsh from inside the browsh git repository so `git rev-parse --show-toplevel` succeeds.","Ensure PATH includes /usr/bin, /bin, /usr/sbin etc. when launching browsh from a service or IDE."],"exampleFix":"// before (Dockerfile, failing)\nFROM debian:slim\nRUN apt-get install -y firefox\n// after\nFROM debian:slim\nRUN apt-get install -y firefox procps git ca-certificates","handlingStrategy":"try-catch","validationCode":"const { execSync } = require('child_process');\nfor (const tool of ['ps', 'git']) {\n  try { execSync(`command -v ${tool}`, { shell: '/bin/sh' }); }\n  catch { throw new Error(`${tool} missing from PATH; install it (e.g. procps/git)`); }\n}","typeGuard":null,"tryCatchPattern":"try {\n  startBrowsh();\n} catch (e) {\n  if (/Browsh tried to run/.test(e.message)) {\n    // message contains the command, its output and the wrapped err\n    console.error('Fix environment for failed shell command:', e.message);\n  } else { throw e; }\n}","preventionTips":["Install procps and git in slim container images.","Run web-ext dev mode from inside the browsh git repo.","Preserve a sane PATH when launching browsh from daemons/IDEs.","Preflight-check required binaries (ps, git, firefox) at startup."],"tags":["shell","process-execution","environment"],"backgroundTag":"command-execution-failed","analyzedSha":"499ef386d45cd1e2b5457dd04887c017f77b7e27","analyzedAt":"2026-09-02T19:05:32.228Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}