{"record":{"id":"c01cb3c4a523aa7d","repo":"angular/angular-cli","slug":"path-p-does-not-exist","errorCode":null,"errorMessage":"Path \"${p}\" does not exist.","messagePattern":"Path \"(.+?)\" does not exist\\.","errorType":"exception","errorClass":"FileDoesNotExistException","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/schematics/src/tree/host-tree.ts","lineNumber":383,"sourceCode":"      }\n\n      maybeCache = new HostDirEntry(parent && this.getDir(parent), p, this._recordSync, this);\n      this._dirCache.set(p, maybeCache);\n    }\n\n    return maybeCache;\n  }\n  visit(visitor: FileVisitor): void {\n    this.root.visit((path, entry) => {\n      visitor(path, entry);\n    });\n  }\n\n  // Change content of host files.\n  overwrite(path: string, content: Buffer | string): void {\n    const p = this._normalizePath(path);\n    if (!this._recordSync.exists(p)) {\n      throw new FileDoesNotExistException(p);\n    }\n    const c = typeof content == 'string' ? Buffer.from(content) : content;\n    this._record.overwrite(p, c as {} as virtualFs.FileBuffer).subscribe();\n  }\n  beginUpdate(path: string): UpdateRecorder {\n    const entry = this.get(path);\n    if (!entry) {\n      throw new FileDoesNotExistException(path);\n    }\n\n    return UpdateRecorderBase.createFromFileEntry(entry);\n  }\n  commitUpdate(record: UpdateRecorder): void {\n    if (record instanceof UpdateRecorderBase) {\n      const path = record.path;\n      const entry = this.get(path);\n      if (!entry) {\n        throw new ContentHasMutatedException(path);","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/schematics/src/tree/host-tree.ts#L365-L401","documentation":"HostTree.overwrite(path, content) only modifies existing files; it never creates them. If the normalized path does not exist in the tree's virtual file system it throws FileDoesNotExistException. Use create() for new files instead.","triggerScenarios":"Calling tree.overwrite(path, ...) on a path never created in the tree; calling overwrite in a rule that assumed a prior rule/template had generated the file; internally from commitUpdate/merge when the file was deleted between steps.","commonSituations":"Angular schematic rules editing files (e.g. app.component.ts, angular.json) whose path changed across CLI versions; typos in paths; running a rule on a project where the target file was renamed or removed.","solutions":["Guard with tree.exists(path) and call tree.create(path, content) when it's absent.","Confirm the exact path — check the project layout and Angular CLI version conventions (paths move between versions).","Insert the file earlier in the pipeline (template/merge schematic) before overwriting."],"exampleFix":"// before\ntree.overwrite('/src/app/legacy.service.ts', newContent);\n// after\nconst p = '/src/app/legacy.service.ts';\nif (tree.exists(p)) {\n  tree.overwrite(p, newContent);\n} else {\n  tree.create(p, newContent);\n}","handlingStrategy":"validation","validationCode":"const canOverwrite = tree.exists(path);","typeGuard":null,"tryCatchPattern":"try {\n  tree.overwrite(path, content);\n} catch (e) {\n  if ((e as any).constructor?.name === 'FileDoesNotExistException') {\n    tree.create(path, content); // or surface a clear message\n  } else throw e;\n}","preventionTips":["Check tree.exists(path) before overwrite","Use create() for files the rule introduces itself","Verify paths against the current Angular CLI version's project layout","Ensure prior rules/templates that generate the file run before the overwrite step"],"tags":["file-not-found","overwrite","schematics"],"backgroundTag":"file-does-not-exist","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}