{"record":{"id":"c0d61706e89817be","repo":"can1357/oh-my-pi","slug":"bun-install-failed-with-exit-code-result-exitcod","errorCode":null,"errorMessage":"bun install failed with exit code ${result.exitCode}","messagePattern":"bun install failed with exit code (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli/update-cli.ts","lineNumber":1525,"sourceCode":"}\n\n/**\n * Update via package manager.\n *\n * Returns the PATH-resolved launcher check so the caller can repair a launcher\n * the manager left unusable, or `undefined` when a rename migration already\n * verified and reported its own result.\n */\nasync function updateViaBun(release: ReleaseInfo): Promise<InstalledVersionVerification | undefined> {\n\tconsole.log(chalk.dim(\"Updating via bun...\"));\n\tlet verification: InstalledVersionVerification | undefined;\n\tif (release.packages.pkg !== PACKAGE) {\n\t\tawait migrateRenamedInstall(release, packageManagerMigrationSteps(\"bun\", release));\n\t} else {\n\t\tconst args = buildBunInstallArgs(release.version, currentNativeTag(), release.packages);\n\t\tconst result = await $`bun ${args}`.nothrow();\n\t\tif (result.exitCode !== 0) {\n\t\t\tthrow new Error(`bun install failed with exit code ${result.exitCode}`);\n\t\t}\n\t\tverification = await verifyInstalledVersion(release.version);\n\t}\n\ttry {\n\t\tconst pruneResult = await pruneBunCacheAfterGlobalInstall();\n\t\tif (pruneResult && pruneResult.removedEntries > 0) {\n\t\t\tconsole.log(chalk.dim(`Pruned ${pruneResult.removedEntries} stale Bun cache entries`));\n\t\t}\n\t} catch (err) {\n\t\tconsole.log(chalk.yellow(`Warning: could not prune stale Bun cache entries: ${err}`));\n\t}\n\treturn verification;\n}\n\nasync function updateViaNpm(release: ReleaseInfo): Promise<InstalledVersionVerification | undefined> {\n\tconsole.log(chalk.dim(\"Updating via npm...\"));\n\tif (release.packages.pkg !== PACKAGE) {\n\t\tawait migrateRenamedInstall(release, packageManagerMigrationSteps(\"npm\", release));","sourceCodeStart":1507,"sourceCodeEnd":1543,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli/update-cli.ts#L1507-L1543","documentation":"This error is thrown by the self-update flow in update-cli.ts when the updater delegates installation to bun (`bun install ...` via buildBunInstallArgs) and the spawned process exits non-zero. Bun's stderr is not surfaced in the message, so the exit code is the only diagnostic given. It means the new version of the package could not be installed globally with bun.","triggerScenarios":"Running the CLI's self-update command on an install managed by bun when `bun <install args>` exits non-zero — e.g. no network access to the npm registry, version not found, permission denied on the global install directory, or a corrupt bun cache.","commonSituations":"Offline or proxied environments blocking registry.npmjs.org; requesting a version/tag that does not exist; global bin dir owned by root; bun cache corruption after an interrupted install.","solutions":["Run the same install command manually (`bun install -g <pkg>@<version>`) to see bun's real stderr error","Check network/proxy access to the npm registry","Check write permissions on bun's global install directory (e.g. ~/.bun)","Clear the bun cache (`bun pm cache rm`) if cache corruption is suspected","Retry the self-update, or fall back to installing via npm or the standalone binary"],"exampleFix":"// before (opaque failure)\nconst result = await $`bun ${args}`.nothrow();\nif (result.exitCode !== 0) {\n\tthrow new Error(`bun install failed with exit code ${result.exitCode}`);\n}\n// after (diagnose by rerunning with output)\nconst result = await $`bun ${args}`.nothrow();\nif (result.exitCode !== 0) {\n\tthrow new Error(`bun install failed with exit code ${result.exitCode}: ${result.stderr.text()}`);\n}","handlingStrategy":"try-catch","validationCode":"const probe = await $`bun pm ping`.nothrow().catch(() => null);\nif (!probe || probe.exitCode !== 0) console.warn(\"bun/registry unavailable; update may fail\");","typeGuard":"function bunInstallSucceeded(r: { exitCode: number }): r is { exitCode: 0 } {\n\treturn r.exitCode === 0;\n}","tryCatchPattern":"try {\n\tawait updateSelf();\n} catch (err) {\n\tif (err.message.startsWith(\"bun install failed\")) {\n\t\t// rerun install manually to see bun's stderr, then retry or fall back\n\t} else throw err;\n}","preventionTips":["Keep bun and its global bin dir writable and on PATH","Verify registry connectivity before self-updating in CI/proxied environments","Pin a fallback install method (standalone installer) for machines where bun install is restricted"],"tags":["install","bun","self-update","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"}