{"record":{"id":"4a9ffb34eae76247","repo":"can1357/oh-my-pi","slug":"brew-update-failed-with-exit-code-update-exitcod","errorCode":null,"errorMessage":"brew update failed with exit code ${update.exitCode}","messagePattern":"brew update failed with exit code (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli/update-cli.ts","lineNumber":1659,"sourceCode":"\ttry {\n\t\tawait steps.repair(launcherPath);\n\t} catch (err) {\n\t\tthrow new Error(`${steps.manager} update did not produce a working launcher and binary repair failed: ${err}`, {\n\t\t\tcause: installError ?? err,\n\t\t});\n\t}\n\tconsole.log(\n\t\tchalk.yellow(\n\t\t\t`This install is no longer managed by ${steps.manager}. Removing the old global package may delete this launcher; if it does, reinstall with: ${installerHint()}`,\n\t\t),\n\t);\n}\n\nasync function updateViaHomebrew(expectedVersion: string, force: boolean): Promise<void> {\n\tconsole.log(chalk.dim(\"Updating Homebrew formulae...\"));\n\tconst update = await $`brew update`.nothrow();\n\tif (update.exitCode !== 0) {\n\t\tthrow new Error(`brew update failed with exit code ${update.exitCode}`);\n\t}\n\n\tconsole.log(chalk.dim(\"Updating via Homebrew...\"));\n\tconst args = buildHomebrewUpdateArgs(force);\n\tconst result = await $`brew ${args}`.nothrow();\n\tif (result.exitCode !== 0) {\n\t\tthrow new Error(`brew ${args[0]} failed with exit code ${result.exitCode}`);\n\t}\n\n\tawait printVerification(expectedVersion);\n}\n\nasync function updateViaMise(expectedVersion: string, force: boolean): Promise<void> {\n\tconsole.log(chalk.dim(\"Updating via mise...\"));\n\tconst args = buildMiseUpgradeArgs();\n\tconst result = await $`mise ${args}`.nothrow();\n\tif (result.exitCode !== 0) {\n\t\tthrow new Error(`mise upgrade failed with exit code ${result.exitCode}`);","sourceCodeStart":1641,"sourceCodeEnd":1677,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli/update-cli.ts#L1641-L1677","documentation":"Thrown in updateViaHomebrew when `brew update` (refreshing Homebrew's formula index) exits non-zero, before the actual `brew upgrade` is attempted. The CLI aborts the Homebrew update path because a stale formula index would install the wrong or missing version.","triggerScenarios":"Self-update targets the homebrew method and `brew update` fails — no network to GitHub/Homebrew API, broken taps, HOMEBREW_API_DOMAIN misconfigured, or permissions problems in the Homebrew prefix.","commonSituations":"Offline/CI environments; corporate proxies blocking https://formulae.brew.sh; a broken third-party tap; macOS permission prompts (TMPDIR owned by root after restore).","solutions":["Run `brew update -v` manually to see the underlying error","Check network/proxy access to formulae.brew.sh and github.com","Fix or untap broken taps reported by brew","Repair Homebrew permissions (`sudo chown -R $(whoami) $(brew --prefix)/*` where applicable)","Update manually: `brew update && brew upgrade <formula>`"],"exampleFix":"// before\nconst update = await $`brew update`.nothrow();\nif (update.exitCode !== 0) {\n\tthrow new Error(`brew update failed with exit code ${update.exitCode}`);\n}\n// after (diagnose)\nconst update = await $`brew update`.nothrow();\nif (update.exitCode !== 0) {\n\tthrow new Error(`brew update failed (${update.exitCode}): ${update.stderr.text()}`);\n}","handlingStrategy":"retry","validationCode":"const probe = await $`brew --repository`.nothrow();\nif (probe.exitCode !== 0) throw new Error(\"Homebrew unavailable at expected path\");","typeGuard":"function brewOk(r: { exitCode: number }): r is { exitCode: 0 } {\n\treturn r.exitCode === 0;\n}","tryCatchPattern":"try {\n\tawait updateSelf({ method: \"homebrew\" });\n} catch (err) {\n\tif (err.message.includes(\"brew update failed\")) {\n\t\tawait Bun.sleep(2000); // transient network/API flake: retry once\n\t\tawait updateSelf({ method: \"homebrew\" });\n\t} else throw err;\n}","preventionTips":["Run `brew update` periodically outside the tool so the index is fresh","Keep taps clean; remove broken third-party taps","Whitelist formulae.brew.sh and github.com in proxies/firewalls"],"tags":["homebrew","self-update","network","process-exit-code"],"backgroundTag":"package-install-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}