can1357/oh-my-pi · error · Error

bun pm cache returned an empty cache path

Error message

bun pm cache returned an empty cache path

What it means

After `bun pm cache` succeeds, refreshBunGitCache trims its stdout to obtain the cache directory. If stdout is empty it throws, because the subsequent readdir needs a concrete cache path. This indicates a bun whose `pm cache` behaves unexpectedly (exited 0 but printed nothing).

Source

Thrown at packages/coding-agent/src/extensibility/plugins/bun-git-cache.ts:55

	try {
		const parsed = new URL(withoutFragment);
		const repoPath = parsed.pathname.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "");
		return `${parsed.protocol.toLowerCase()}//${parsed.host.toLowerCase()}/${repoPath}`;
	} catch {
		return withoutFragment.replace(/\/+$/g, "").replace(/\.git$/i, "");
	}
}

/** Fetches current heads and tags into Bun's matching cached bare clone before a plugin update. */
export async function refreshBunGitCache(source: GitSource, cwd: string): Promise<void> {
	const cacheResult = await runCommand(["bun", "pm", "cache"], cwd);
	if (cacheResult.exitCode !== 0) {
		throw new Error(`bun pm cache failed: ${cacheResult.stderr}`);
	}
	const cacheDir = cacheResult.stdout.trim();
	if (!cacheDir) {
		throw new Error("bun pm cache returned an empty cache path");
	}

	let entries: Dirent[];
	try {
		entries = await fs.readdir(cacheDir, { withFileTypes: true });
	} catch (err) {
		if (isEnoent(err)) return;
		throw err;
	}

	const repositoryUrl = normalizeRepositoryUrl(source.repo);
	for (const entry of entries) {
		if (!entry.isDirectory() || !entry.name.endsWith(".git")) continue;
		const repositoryDir = path.join(cacheDir, entry.name);
		const originResult = await runCommand(["git", "-C", repositoryDir, "config", "--get", "remote.origin.url"], cwd);
		if (originResult.exitCode !== 0 || normalizeRepositoryUrl(originResult.stdout.trim()) !== repositoryUrl) continue;

		const fetchResult = await runCommand(

View on GitHub (pinned to 9690622007)

Solutions

  1. Run `bun pm cache` in a shell; if it prints nothing, upgrade bun (`bun upgrade`) or reinstall bun.
  2. Check you are not aliasing/wrapping bun in a script that discards stdout.
  3. Verify BUN_INSTALL/cache env vars are sane so `pm cache` resolves a directory.
Defensive patterns

Strategy: validation

Validate before calling

const probe = Bun.spawnSync(["bun", "pm", "cache"], { stdout: "pipe" });
if (probe.exitCode !== 0 || !probe.stdout.toString().trim()) {
  throw new Error("bun pm cache does not print a cache path; fix bun before installing git plugins");
}

Try / catch

try {
  await updateGitPlugin(source, cwd);
} catch (err) {
  if (err instanceof Error && err.message.includes("empty cache path")) {
    // reinstall/upgrade bun, or fall back to plain git clone install
  } else throw err;
}

Prevention

When it happens

Trigger: `bun pm cache` exits 0 but prints an empty cache path — nonstandard bun builds, wrapped/aliased bun binaries that swallow stdout, or output redirection issues in the spawn environment.

Common situations: bun installed via a shim/manager that doesn't forward stdout; unusual bun versions where `pm cache` prints to stderr or nothing; custom BUN_INSTALL env misconfiguration.

Related errors


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