{"record":{"id":"003e8979182af076","repo":"JuliusBrussee/caveman","slug":"envvar-does-not-point-to-an-executable-explicit","errorCode":null,"errorMessage":"${envVar} does not point to an executable: ${explicit}","messagePattern":"(.+?) does not point to an executable: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/binary-installer/installer.mjs","lineNumber":178,"sourceCode":"// exits within a second or two of being asked to.\nasync function replaceWithRetry(part, target, attempts = 6) {\n  for (let attempt = 0; ; attempt++) {\n    try {\n      renameSync(part, target);\n      return;\n    } catch (error) {\n      const locked = error.code === \"EPERM\" || error.code === \"EBUSY\" ||\n                     error.code === \"EACCES\" || error.code === \"ETXTBSY\";\n      if (!locked || attempt >= attempts - 1) throw error;\n      await new Promise((done) => setTimeout(done, 100 * 2 ** attempt));\n    }\n  }\n}\n\nexport async function ensureBinary({ name, envVar }) {\n  const explicit = process.env[envVar];\n  if (explicit) {\n    if (!executable(explicit)) throw new Error(`${envVar} does not point to an executable: ${explicit}`);\n    return explicit;\n  }\n  const found = onPath(name);\n  if (found) return found;\n  const binDir = join(process.env.CAVEMAN_HOME ?? join(homedir(), \".caveman\"), \"bin\");\n  const target = join(binDir, binaryInstallFilename(name));\n  if (executable(target)) return target;\n\n  const { os, arch } = targetPlatform();\n  const artifact = `${name}_${os}_${arch}`;\n  const base = (process.env.CAVE_BINARY_RELEASE_BASE ?? BINARY_RELEASE_BASE_DEFAULT).replace(/\\/+$/, \"\");\n  const release = `${base}/${BINARY_RELEASE}`;\n  const timeout = timeoutMs();\n  const [checksumsResponse, signatureResponse] = await Promise.all([\n    asset(`${release}/checksums.txt`, timeout),\n    asset(`${release}/checksums.txt.keysig`, timeout),\n  ]);\n  const [checksums, signature] = await Promise.all([checksumsResponse.text(), signatureResponse.text()]);","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/binary-installer/installer.mjs#L160-L196","documentation":"`ensureBinary({ name, envVar })` first honors an explicit override: if `process.env[envVar]` is set, that path must exist and be executable (checked by `executable()`). If it isn't, the installer throws immediately instead of silently ignoring the override and downloading. This catches misconfigured overrides early with the offending path in the message.","triggerScenarios":"Calling `ensureBinary({ name, envVar })` when `process.env[envVar]` is set to a path that is missing, a directory, or lacks the execute bit — e.g. `CAVEMAN_RIPGREP_BIN=/opt/rg/bin` (directory), a deleted binary, a Windows-style path on Linux, or a file that was never `chmod +x`.","commonSituations":"Hand-edited shell profile pointing at a path that moved after an upgrade; copied binary without preserving permissions; Docker image copied binaries with `COPY` losing exec bits; pointing at a wrapper script that isn't executable.","solutions":["Run `ls -l \"$CAVEMAN_<NAME>_BIN\"` and confirm the file exists and has the x bit.","Fix the env var to the real binary path, or `unset` it so ensureBinary falls back to PATH lookup/download.","If the file exists but isn't executable: `chmod +x <path>`.","If the binary was removed by an upgrade, reinstall it or let the installer download it by unsetting the override."],"exampleFix":"// before\nexport CAVEMAN_RIPGREP_BIN=/opt/tools/rg-14/bin   # directory, not executable\n// after\nexport CAVEMAN_RIPGREP_BIN=/opt/tools/rg-14/bin/rg && chmod +x \"$CAVEMAN_RIPGREP_BIN\"","handlingStrategy":"validation","validationCode":"import { accessSync, constants } from \"node:fs\";\nfunction isExecutable(p) {\n  try { accessSync(p, constants.F_OK | constants.X_OK); return true; } catch { return false; }\n}\nconst v = process.env.CAVEMAN_RIPGREP_BIN;\nif (v && !isExecutable(v)) throw new Error(`CAVEMAN_RIPGREP_BIN not executable: ${v}`);","typeGuard":null,"tryCatchPattern":"try {\n  await ensureBinary({ name, envVar });\n} catch (e) {\n  if (String(e.message).includes(\"does not point to an executable\")) {\n    delete process.env[envVar]; // fall back to PATH lookup / download\n    return ensureBinary({ name, envVar });\n  }\n  throw e;\n}","preventionTips":["Validate env-var paths in shell profiles at login (test -x).","chmod +x binaries after copying; use `COPY --chmod=755` in Dockerfiles.","Unset stale overrides after upgrading/relocating tools.","Point overrides at files, never directories."],"tags":["configuration","environment","filesystem"],"backgroundTag":"invalid-env-var-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}