{"record":{"id":"6e98a0dd2d0453ee","repo":"JuliusBrussee/caveman","slug":"target-already-exists-path","errorCode":null,"errorMessage":"target already exists: ${path}","messagePattern":"target already exists: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/create-caveman-agent/src/index.ts","lineNumber":314,"sourceCode":"  return \"GEMINI_API_KEY (or GOOGLE_API_KEY)\";\n}\n\nfunction parseProvider(value: string): Provider {\n  const normalized = value.trim().toLowerCase();\n  if (normalized === \"anthropic\" || normalized === \"openai\" || normalized === \"google\") return normalized;\n  throw new Error(`unsupported provider ${JSON.stringify(value)}`);\n}\n\nfunction safeName(value: string): string {\n  const normalized = value.toLowerCase().replace(/[^a-z0-9_-]+/g, \"-\").replace(/^-+|-+$/g, \"\");\n  if (!normalized) throw new Error(\"project name must contain a letter or number\");\n  return normalized.slice(0, 96);\n}\n\nasync function assertAbsent(path: string): Promise<void> {\n  try {\n    await stat(path);\n    throw new Error(`target already exists: ${path}`);\n  } catch (error) {\n    if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n  }\n}\n\nmain().catch((error) => {\n  const message = error instanceof Error ? error.message : String(error);\n  process.stderr.write(`create-caveman-agent: ${message}\\n`);\n  process.exitCode = 1;\n});\n","sourceCodeStart":296,"sourceCodeEnd":325,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/create-caveman-agent/src/index.ts#L296-L325","documentation":"Before scaffolding, assertAbsent stats the target path; if the path already exists (file or directory), it throws to prevent clobbering an existing project. Only ENOENT is treated as 'safe to proceed'.","triggerScenarios":"Running the scaffolder with a target name whose directory or file already exists in the current working directory, e.g. re-running the create command after a previous successful or partial run.","commonSituations":"Re-running the command after a failed install left the directory behind; choosing `my-app` when `my-app` already exists; colliding with an unrelated existing file/folder of the same name.","solutions":["Choose a different project name or run in another directory","Delete or rename the existing target if it is safe to remove: `rm -rf my-app`","Inspect the existing target first — if it is a leftover from a failed run, remove it and re-run"],"exampleFix":"// before\nnpm create @caveman-ai/agent@latest my-app   # ./my-app already exists\n// after\nrm -rf ./my-app   # only if disposable\nnpm create @caveman-ai/agent@latest my-app","handlingStrategy":"validation","validationCode":"import { stat } from \"node:fs/promises\";\ntry {\n  await stat(target);\n  throw new Error(`refusing to overwrite existing target: ${target}`);\n} catch (e) {\n  if ((e as NodeJS.ErrnoException).code !== \"ENOENT\") throw e;\n}","typeGuard":"async function isFreePath(path: string): Promise<boolean> {\n  try { await stat(path); return false; } catch (e) { return (e as NodeJS.ErrnoException).code === \"ENOENT\"; }\n}","tryCatchPattern":"try {\n  await main();\n} catch (error) {\n  if (error instanceof Error && error.message.startsWith(\"target already exists\")) {\n    console.error(`${error.message} — remove it or pick another name`);\n    process.exitCode = 1;\n  } else throw error;\n}","preventionTips":["Check the target directory with ls before scaffolding","Clean up leftover directories from failed runs before retrying","Use unique project names or fresh working directories in CI"],"tags":["filesystem","conflict"],"backgroundTag":"file-already-exists","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"}