{"record":{"id":"a0380711477704a1","repo":"angular/components","slug":"formatdiagnostics-error-filesystem","errorCode":null,"errorMessage":"formatDiagnostics([error], fileSystem)","messagePattern":"formatDiagnostics\\(\\[error\\], fileSystem\\)","errorType":"exception","errorClass":"TsconfigParseError","httpStatus":null,"severity":"error","filePath":"src/cdk/schematics/update-tool/utils/parse-tsconfig.ts","lineNumber":41,"sourceCode":" *\n * @throws {TsconfigParseError} If the tsconfig could not be read or parsed.\n */\nexport function parseTsconfigFile(\n  tsconfigPath: WorkspacePath,\n  fileSystem: FileSystem,\n): ts.ParsedCommandLine {\n  if (!fileSystem.fileExists(tsconfigPath)) {\n    throw new TsconfigParseError(`Tsconfig cannot not be read: ${tsconfigPath}`);\n  }\n\n  const {config, error} = ts.readConfigFile(\n    tsconfigPath,\n    p => fileSystem.read(fileSystem.resolve(p))!,\n  );\n\n  // If there is a config reading error, we never attempt to parse the config.\n  if (error) {\n    throw new TsconfigParseError(formatDiagnostics([error], fileSystem));\n  }\n\n  const parsed = ts.parseJsonConfigFileContent(\n    config,\n    new FileSystemHost(fileSystem),\n    dirname(tsconfigPath),\n    {},\n  );\n\n  // Skip the \"No inputs found...\" error since we don't want to interrupt the migration if a\n  // tsconfig doesn't match a file. This will result in an empty `Program` which is still valid.\n  const errors = parsed.errors.filter(diag => diag.code !== NO_INPUTS_ERROR_CODE);\n\n  if (errors.length) {\n    throw new TsconfigParseError(formatDiagnostics(errors, fileSystem));\n  }\n\n  return parsed;","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/schematics/update-tool/utils/parse-tsconfig.ts#L23-L59","documentation":"After the file exists, parseTsconfigFile calls ts.readConfigFile; if TypeScript reports a reading error (invalid JSON/JSONC syntax, unreadable content), the error is formatted into a human-readable diagnostic and thrown as TsconfigParseError. The tool deliberately never attempts to parse a config that failed to read.","triggerScenarios":"parseTsconfigFile reaches ts.readConfigFile and the returned `error` is non-null — e.g. the tsconfig contains invalid JSON (trailing content, unquoted comments outside JSONC allowance) or the underlying fileSystem.read fails producing a TS read error.","commonSituations":"Hand-edited tsconfig.json with a syntax mistake (missing comma/brace, trailing commas in strict JSON contexts), a merge conflict marker left in the file, truncated or empty file, or an extends chain pointing at a broken file.","solutions":["Open the tsconfig at the path shown in the diagnostic and fix the JSON/JSONC syntax error reported by the message.","Remove leftover merge-conflict markers or truncated content from the file.","If the file is generated, regenerate it (e.g. via ng update or the CLI) instead of hand-editing."],"exampleFix":"// before (invalid tsconfig)\n{\n  \"compilerOptions\": {\n    \"strict\": true\n  } // missing closing brace\n// after\n{\n  \"compilerOptions\": {\n    \"strict\": true\n  }\n}","handlingStrategy":"try-catch","validationCode":"// Pre-validate JSON/JSONC parses cleanly\nimport {readFileSync} from 'fs';\ntry {\n  readFileSync(tsconfigPath, 'utf8'); // also surfaces unreadable file\n  JSON.parse(readFileSync(tsconfigPath, 'utf8').replace(/\\/\\/.*$/gm, ''));\n} catch (e) {\n  console.error(`tsconfig at ${tsconfigPath} is unreadable or invalid JSON: ${e.message}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const parsed = parseTsconfigFile(path, fileSystem);\n} catch (e) {\n  if (e instanceof TsconfigParseError) {\n    console.error('tsconfig read error, fix the syntax shown in diagnostics:\\n' + e.message);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Validate tsconfig JSON syntax before committing (editor JSONC linting, `tsc --showConfig`).","Resolve merge conflicts in tsconfig files before running ng update.","Avoid hand-editing generated tsconfigs; prefer the CLI to modify them."],"tags":["typescript","tsconfig","json-parse","configuration"],"backgroundTag":"tsconfig-parse-failed","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}