{"record":{"id":"6e98a0dd2d0453ee","repo":"JuliusBrussee/caveman","slug":"target-already-exists-path","errorCode":null,"errorMessage":"target already exists: ${path}","messagePattern":"target already exists: (.+?)","errorType":"exception","errorClass":null,"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/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/create-caveman-agent/src/index.ts#L296-L325","documentation":"Before scaffolding, assertAbsent stats the resolved target path and requires ENOENT — the create initializer must never overwrite an existing directory or file. Any existing filesystem entry (directory, file, symlink) produces this error. This is intentional clobber protection, and it also fires for things like an auto-created editor/IDE folder.","triggerScenarios":"Running the initializer twice with the same target, scaffolding into a directory that already exists (even an empty one created by mkdir beforehand), or targeting a path occupied by a file/symlink.","commonSituations":"Re-running after a partial previous attempt, users pre-creating the folder, IDE auto-creating the directory when it is opened, or leftover artifacts from an aborted run.","solutions":["Pick a fresh target name, or move/remove the existing path if its contents are disposable.","If the existing directory is empty, remove it first (`rmdir myapp`) and re-run.","For resuming a failed attempt, delete the partial scaffold before re-creating."],"exampleFix":"# before\nmkdir myapp && npm create @caveman-ai/agent@latest myapp\n# after\nrmdir myapp && npm create @caveman-ai/agent@latest myapp","handlingStrategy":"validation","validationCode":"import { stat } from \"node:fs/promises\";\n\nasync function targetIsFree(path: string): Promise<boolean> {\n  try { await stat(path); return false; } catch { return true; }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the target path does not exist before running the initializer.","Do not pre-create the project directory; the initializer makes it.","Clean up partial scaffolds from failed runs before re-running."],"tags":["cli","filesystem","safety"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}