{"record":{"id":"897613d5b592feca","repo":"can1357/oh-my-pi","slug":"bun-pm-cache-returned-an-empty-cache-path","errorCode":null,"errorMessage":"bun pm cache returned an empty cache path","messagePattern":"bun pm cache returned an empty cache path","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/extensibility/plugins/bun-git-cache.ts","lineNumber":55,"sourceCode":"\n\ttry {\n\t\tconst parsed = new URL(withoutFragment);\n\t\tconst repoPath = parsed.pathname.replace(/^\\/+|\\/+$/g, \"\").replace(/\\.git$/i, \"\");\n\t\treturn `${parsed.protocol.toLowerCase()}//${parsed.host.toLowerCase()}/${repoPath}`;\n\t} catch {\n\t\treturn withoutFragment.replace(/\\/+$/g, \"\").replace(/\\.git$/i, \"\");\n\t}\n}\n\n/** Fetches current heads and tags into Bun's matching cached bare clone before a plugin update. */\nexport async function refreshBunGitCache(source: GitSource, cwd: string): Promise<void> {\n\tconst cacheResult = await runCommand([\"bun\", \"pm\", \"cache\"], cwd);\n\tif (cacheResult.exitCode !== 0) {\n\t\tthrow new Error(`bun pm cache failed: ${cacheResult.stderr}`);\n\t}\n\tconst cacheDir = cacheResult.stdout.trim();\n\tif (!cacheDir) {\n\t\tthrow new Error(\"bun pm cache returned an empty cache path\");\n\t}\n\n\tlet entries: Dirent[];\n\ttry {\n\t\tentries = await fs.readdir(cacheDir, { withFileTypes: true });\n\t} catch (err) {\n\t\tif (isEnoent(err)) return;\n\t\tthrow err;\n\t}\n\n\tconst repositoryUrl = normalizeRepositoryUrl(source.repo);\n\tfor (const entry of entries) {\n\t\tif (!entry.isDirectory() || !entry.name.endsWith(\".git\")) continue;\n\t\tconst repositoryDir = path.join(cacheDir, entry.name);\n\t\tconst originResult = await runCommand([\"git\", \"-C\", repositoryDir, \"config\", \"--get\", \"remote.origin.url\"], cwd);\n\t\tif (originResult.exitCode !== 0 || normalizeRepositoryUrl(originResult.stdout.trim()) !== repositoryUrl) continue;\n\n\t\tconst fetchResult = await runCommand(","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/extensibility/plugins/bun-git-cache.ts#L37-L73","documentation":"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).","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Run `bun pm cache` in a shell; if it prints nothing, upgrade bun (`bun upgrade`) or reinstall bun.","Check you are not aliasing/wrapping bun in a script that discards stdout.","Verify BUN_INSTALL/cache env vars are sane so `pm cache` resolves a directory."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const probe = Bun.spawnSync([\"bun\", \"pm\", \"cache\"], { stdout: \"pipe\" });\nif (probe.exitCode !== 0 || !probe.stdout.toString().trim()) {\n  throw new Error(\"bun pm cache does not print a cache path; fix bun before installing git plugins\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await updateGitPlugin(source, cwd);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"empty cache path\")) {\n    // reinstall/upgrade bun, or fall back to plain git clone install\n  } else throw err;\n}","preventionTips":["Don't wrap/alias bun with scripts that swallow stdout","Upgrade bun if `bun pm cache` prints nothing in a shell","Set BUN_INSTALL and cache env vars explicitly in minimal containers"],"tags":["bun","plugins","cache","environment"],"backgroundTag":"bun-command-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}