{"record":{"id":"4b9114d3985fa25a","repo":"denoland/deno","slug":"err-fs-cp-eexist","errorCode":"ERR_FS_CP_EEXIST","errorMessage":"Target already exists","messagePattern":"Target already exists","errorType":"exception","errorClass":"NodeSystemError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_fs/cp/cp.ts","lineNumber":84,"sourceCode":"      });\n    case \"DIR_TO_NON_DIR\":\n      throw new ERR_FS_CP_DIR_TO_NON_DIR({\n        message: err.message,\n        path: err.path,\n        syscall: \"cp\",\n        errno: EISDIR,\n        code: \"EISDIR\",\n      });\n    case \"NON_DIR_TO_DIR\":\n      throw new ERR_FS_CP_NON_DIR_TO_DIR({\n        message: err.message,\n        path: err.path,\n        syscall: \"cp\",\n        errno: ENOTDIR,\n        code: \"ENOTDIR\",\n      });\n    case \"EEXIST\":\n      throw new ERR_FS_CP_EEXIST({\n        message: err.message,\n        path: err.path,\n        syscall: \"cp\",\n        errno: EEXIST,\n        code: \"EEXIST\",\n      });\n    case \"EISDIR\":\n      throw new ERR_FS_EISDIR({\n        message: err.message,\n        path: err.path,\n        syscall: \"cp\",\n        errno: EISDIR,\n        code: \"EISDIR\",\n      });\n    case \"SOCKET\":\n      throw new ERR_FS_CP_SOCKET({\n        message: err.message,\n        path: err.path,","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/_fs/cp/cp.ts#L66-L102","documentation":"ERR_FS_CP_EEXIST ('Target already exists') is raised by throwCpError for kind 'EEXIST': the destination exists and the options forbid overwriting it — i.e. force: false combined with errorOnExist: true (the native on-file/link ops receive opts.force and opts.errorOnExist). With defaults (force: true, errorOnExist: false) existing destinations are overwritten silently.","triggerScenarios":"await fsp.cp(src, dest, { force: false, errorOnExist: true }) when dest already exists; install/extract tools that intentionally refuse to clobber outputs.","commonSituations":"Idempotent deploy scripts that must not overwrite existing installs; cache-population code where EEXIST is used as 'already done'.","solutions":["If overwriting is fine, drop errorOnExist or set force: true","If not overwriting is intended, catch the error and check err.code === 'ERR_FS_CP_EEXIST' (or EEXIST) to treat it as success","Pre-check with fs.existsSync(dest) / fsp.lstat to branch explicitly instead of relying on the throw"],"exampleFix":"// before\nawait fsp.cp(src, dest, { force: false, errorOnExist: true }); // throws when dest exists\n\n// after\ntry {\n  await fsp.cp(src, dest, { force: false, errorOnExist: true });\n} catch (err) {\n  if (err.code !== 'EEXIST' && err.code !== 'ERR_FS_CP_EEXIST') throw err;\n  // dest already present — treat as done\n}","handlingStrategy":"try-catch","validationCode":"if (await fsp.lstat(dest).catch(() => null)) {\n  // dest exists: overwrite (default), or skip, or abort — decide explicitly\n  if (!overwrite) return;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await fsp.cp(src, dest, { force: false, errorOnExist: true });\n} catch (err) {\n  if (err.code !== 'EEXIST' && err.code !== 'ERR_FS_CP_EEXIST') throw err;\n  console.log('dest already exists — skipping');\n}","preventionTips":["Know the option matrix: force:true overwrites, errorOnExist:true turns existence into an error","Use existence pre-checks when 'already installed' should be a normal case","Check err.code, never the message text, when branching on fs errors"],"tags":["node-compat","fs","cp","copy","eexist","overwrite"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}