{"record":{"id":"62a36bd8e08a0b62","repo":"angular/angular-cli","slug":"file-does-not-exist","errorCode":null,"errorMessage":"File does not exist.","messagePattern":"File does not exist\\.","errorType":"exception","errorClass":"FileDoesNotExistException","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/core/src/virtual-fs/host/memory.ts","lineNumber":186,"sourceCode":"      if (maybeStats) {\n        if (maybeStats.isFile()) {\n          throw new PathIsFileException(curr);\n        }\n      } else {\n        this._cache.set(curr, this._newDirStats());\n      }\n    }\n\n    // Create the stats.\n    const stats: Stats<SimpleMemoryHostStats> = this._newFileStats(content, old);\n    this._cache.set(path, stats);\n    this._updateWatchers(path, old ? HostWatchEventType.Changed : HostWatchEventType.Created);\n  }\n  protected _read(path: Path): FileBuffer {\n    path = this._toAbsolute(path);\n    const maybeStats = this._cache.get(path);\n    if (!maybeStats) {\n      throw new FileDoesNotExistException(path);\n    } else if (maybeStats.isDirectory()) {\n      throw new PathIsDirectoryException(path);\n    } else if (!maybeStats.content) {\n      throw new PathIsDirectoryException(path);\n    } else {\n      return maybeStats.content;\n    }\n  }\n  protected _delete(path: Path): void {\n    path = this._toAbsolute(path);\n    if (this._isDirectory(path)) {\n      for (const [cachePath] of this._cache.entries()) {\n        if (cachePath.startsWith(path + NormalizedSep) || cachePath === path) {\n          this._cache.delete(cachePath);\n        }\n      }\n    } else {\n      this._cache.delete(path);","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/core/src/virtual-fs/host/memory.ts#L168-L204","documentation":"_read looks up the path in the host's cache; if no entry exists at all, it throws FileDoesNotExistException. The memory host only serves content it has previously stored, so reading a path that was never written (or was deleted) is an immediate failure. It is thrown before the directory/content checks because the entry is absent.","triggerScenarios":"Calling host.content(path) or read() for a path never created via write(); reading after host.delete(path) removed the entry; typos or case-sensitivity mismatches (the memory host uses normalized absolute paths, so 'Src/A.txt' !== 'src/a.txt'); relative paths that do not resolve to the cached absolute path.","commonSituations":"Schematics reading a template file at a slightly wrong path; forgetting to create the file earlier in the same in-memory tree (unlike a real FS, nothing pre-exists); reading files after a rename moved them; case-sensitivity differences between the developer's OS and the normalized virtual paths.","solutions":["Verify the exact path exists first via host.exists(path) and log it if missing.","Create the file with host.write(path, content) before attempting to read it.","Fix typos and match path casing exactly to how the file was created.","If the file was deleted or renamed, update the code to read from the new path or restore the content first."],"exampleFix":"// before\nconst content = host.read(normalize('src/config.json')); // may throw\n// after\nconst p = normalize('src/config.json');\nif (host.exists(p)) {\n  const content = host.read(p);\n} else {\n  host.write(p, Buffer.from('{}'));\n}","handlingStrategy":"validation","validationCode":"import { normalize, Path } from '@angular-devkit/core';\n\nfunction safeRead(host: { exists(p: Path): boolean; read(p: Path): Buffer }, p: Path): Buffer | null {\n  const abs = normalize(p);\n  return host.exists(abs) ? host.read(abs) : null;\n}","typeGuard":null,"tryCatchPattern":"import { FileDoesNotExistException } from '@angular-devkit/core';\n\ntry {\n  const content = host.read(path);\n} catch (e) {\n  if (e instanceof FileDoesNotExistException) {\n    console.warn(`File not found in virtual FS: ${e.path}; creating default`);\n    host.write(path, Buffer.from(''));\n  } else {\n    throw e;\n  }\n}","preventionTips":["Remember memory hosts start empty — create files before reading them.","Match path casing exactly; the virtual FS paths are normalized and case-sensitive.","Update all references after delete()/rename() so no stale paths are read.","Use exists() as a precondition for every dynamic read."],"tags":["virtual-fs","file-system","angular-devkit","missing-file"],"backgroundTag":"file-does-not-exist","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}