can1357/oh-my-pi · error · Error

bun install failed with exit code ${result.exitCode}

Error message

bun install failed with exit code ${result.exitCode}

What it means

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.

Source

Thrown at packages/coding-agent/src/cli/update-cli.ts:1525

}

/**
 * Update via package manager.
 *
 * Returns the PATH-resolved launcher check so the caller can repair a launcher
 * the manager left unusable, or `undefined` when a rename migration already
 * verified and reported its own result.
 */
async function updateViaBun(release: ReleaseInfo): Promise<InstalledVersionVerification | undefined> {
	console.log(chalk.dim("Updating via bun..."));
	let verification: InstalledVersionVerification | undefined;
	if (release.packages.pkg !== PACKAGE) {
		await migrateRenamedInstall(release, packageManagerMigrationSteps("bun", release));
	} else {
		const args = buildBunInstallArgs(release.version, currentNativeTag(), release.packages);
		const result = await $`bun ${args}`.nothrow();
		if (result.exitCode !== 0) {
			throw new Error(`bun install failed with exit code ${result.exitCode}`);
		}
		verification = await verifyInstalledVersion(release.version);
	}
	try {
		const pruneResult = await pruneBunCacheAfterGlobalInstall();
		if (pruneResult && pruneResult.removedEntries > 0) {
			console.log(chalk.dim(`Pruned ${pruneResult.removedEntries} stale Bun cache entries`));
		}
	} catch (err) {
		console.log(chalk.yellow(`Warning: could not prune stale Bun cache entries: ${err}`));
	}
	return verification;
}

async function updateViaNpm(release: ReleaseInfo): Promise<InstalledVersionVerification | undefined> {
	console.log(chalk.dim("Updating via npm..."));
	if (release.packages.pkg !== PACKAGE) {
		await migrateRenamedInstall(release, packageManagerMigrationSteps("npm", release));

View on GitHub (pinned to 9690622007)

Solutions

  1. Run the same install command manually (`bun install -g <pkg>@<version>`) to see bun's real stderr error
  2. Check network/proxy access to the npm registry
  3. Check write permissions on bun's global install directory (e.g. ~/.bun)
  4. Clear the bun cache (`bun pm cache rm`) if cache corruption is suspected
  5. Retry the self-update, or fall back to installing via npm or the standalone binary

Example fix

// before (opaque failure)
const result = await $`bun ${args}`.nothrow();
if (result.exitCode !== 0) {
	throw new Error(`bun install failed with exit code ${result.exitCode}`);
}
// after (diagnose by rerunning with output)
const result = await $`bun ${args}`.nothrow();
if (result.exitCode !== 0) {
	throw new Error(`bun install failed with exit code ${result.exitCode}: ${result.stderr.text()}`);
}
Defensive patterns

Strategy: try-catch

Validate before calling

const probe = await $`bun pm ping`.nothrow().catch(() => null);
if (!probe || probe.exitCode !== 0) console.warn("bun/registry unavailable; update may fail");

Type guard

function bunInstallSucceeded(r: { exitCode: number }): r is { exitCode: 0 } {
	return r.exitCode === 0;
}

Try / catch

try {
	await updateSelf();
} catch (err) {
	if (err.message.startsWith("bun install failed")) {
		// rerun install manually to see bun's stderr, then retry or fall back
	} else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/c0d61706e89817be. Report an issue: GitHub.