{"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":"SystemError","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/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/_fs/cp/cp.ts#L66-L102","documentation":"When fs.cp copies a file onto an existing destination, the native code consults the force and errorOnExist options (and the COPYFILE_EXCL mode): with force:false and errorOnExist:true (or an exclusive copy mode), an existing dest is rejected with kind EEXIST, mapped by throwCpError to ERR_FS_CP_EEXIST ('Target already exists', errno EEXIST). Without errorOnExist the copy would silently skip; this flag turns the skip into an explicit error.","triggerScenarios":"fs.cp(src, dest, { errorOnExist: true, force: false }, cb) with dest present; copying with fs.constants.COPYFILE_EXCL semantics where the dest already exists; CI pipelines asserting 'first deploy wins' by failing on any pre-existing artifact.","commonSituations":"Atomic installers that must not clobber a previous release; concurrent workers racing to create the same output file; re-running a generator that treats an existing output as a conflict instead of an overwrite.","solutions":["If overwriting is fine, set force: true (with errorOnExist removed/false) so dest is unlinked before the copy","If the conflict is real, catch the error and surface which path already exists (err.path)","Pre-check with fs.existsSync(dest) and branch to skip/overwrite explicitly instead of relying on the throw"],"exampleFix":"// before\nfs.cp('app.tar', '/srv/app.tar', { errorOnExist: true }, cb); // dest exists\n\n// after — allow overwrite\nfs.cp('app.tar', '/srv/app.tar', { force: true }, cb);\n// after — deliberate conflict handling\nif (fs.existsSync('/srv/app.tar')) { /* skip or ask */ } else fs.cp('app.tar', '/srv/app.tar', cb);","handlingStrategy":"try-catch","validationCode":"if (opts.errorOnExist && fs.existsSync(dest)) { /* decide explicitly instead of letting cp throw */ }","typeGuard":null,"tryCatchPattern":"try { await fs.promises.cp(src, dest, { errorOnExist: true, force: false }); } catch (e) { if (e.code === 'ERR_FS_CP_EEXIST') return { skipped: true, existing: e.path }; throw e; }","preventionTips":["errorOnExist only bites with force:false — set force:true when overwrite is intended","Pre-check existence when the not-clobber guarantee matters","Log e.path so operators see which target collided"],"tags":["node-compat","fs","cp","copy","err-fs-cp-eexist","eexist","deno"],"backgroundTag":"file-already-exists","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}