{"record":{"id":"b5482dc152a8a11e","repo":"angular/angular-cli","slug":"path-path-already-exist","errorCode":null,"errorMessage":"Path \"${path}\" already exist.","messagePattern":"Path \"(.+?)\" already exist\\.","errorType":"exception","errorClass":"FileAlreadyExistException","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/schematics/src/sink/sink.ts","lineNumber":56,"sourceCode":"\nexport abstract class SimpleSinkBase implements Sink {\n  preCommitAction: (action: Action) => void | Action | PromiseLike<Action> | Observable<Action> =\n    Noop;\n  postCommitAction: (action: Action) => void | Observable<void> = Noop;\n  preCommit: () => void | Observable<void> = Noop;\n  postCommit: () => void | Observable<void> = Noop;\n\n  protected abstract _validateFileExists(p: string): Observable<boolean>;\n\n  protected abstract _overwriteFile(path: string, content: Buffer): Observable<void>;\n  protected abstract _createFile(path: string, content: Buffer): Observable<void>;\n  protected abstract _renameFile(path: string, to: string): Observable<void>;\n  protected abstract _deleteFile(path: string): Observable<void>;\n\n  protected abstract _done(): Observable<void>;\n\n  protected _fileAlreadyExistException(path: string): void {\n    throw new FileAlreadyExistException(path);\n  }\n  protected _fileDoesNotExistException(path: string): void {\n    throw new FileDoesNotExistException(path);\n  }\n\n  protected _validateOverwriteAction(action: OverwriteFileAction): Observable<void> {\n    return this._validateFileExists(action.path).pipe(\n      map((b) => {\n        if (!b) {\n          this._fileDoesNotExistException(action.path);\n        }\n      }),\n    );\n  }\n  protected _validateCreateAction(action: CreateFileAction): Observable<void> {\n    return this._validateFileExists(action.path).pipe(\n      map((b) => {\n        if (b) {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/schematics/src/sink/sink.ts#L38-L74","documentation":"FileAlreadyExistException is thrown by the Sink abstraction (via _fileAlreadyExistException) when validating a CreateFileAction whose target path already exists in the sink. Schematics treats 'create' as strictly creating a new file; overwriting is a separate 'overwrite' action. This keeps tree operations explicit and prevents accidental clobbering of existing files.","triggerScenarios":"Calling host.commitSingleAction() or commit() with a 'c' (create) action for a path that already exists in the underlying host, e.g. a schematic used rule/branch().create() or Tree.create() on an existing file path.","commonSituations":"Running a schematic twice where it unconditionally creates a file; generator templates that use `host.create('src/config.ts', ...)` without checking `host.exists()`; merging trees where both sides create the same new file.","solutions":["Check existence first: if (tree.exists(path)) use tree.overwrite(path, content) instead of tree.create(path, content).","Delete the stale file before committing, or skip creation when the content is identical.","Wrap commit in try/catch for FileAlreadyExistException to handle idempotent re-runs explicitly."],"exampleFix":"// before\ntree.create('src/app.config.ts', content);\n// after\nif (tree.exists('src/app.config.ts')) {\n  tree.overwrite('src/app.config.ts', content);\n} else {\n  tree.create('src/app.config.ts', content);\n}","handlingStrategy":"validation","validationCode":"if (tree.exists('/src/app.config.ts')) { /* use overwrite instead of create */ }","typeGuard":"null","tryCatchPattern":"try { host.commit(tree); } catch (e) { if (e instanceof FileAlreadyExistException) { /* skip or overwrite */ } else { throw e; } }","preventionTips":["Always call tree.exists(path) before tree.create(path, ...)","Prefer overwrite() for files that may pre-exist","Design schematics to be idempotent for repeat runs"],"tags":["schematics","file-already-exists","create-action"],"backgroundTag":"file-already-exists","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}