{"record":{"id":"d9545f81bd62b0d9","repo":"angular/angular-cli","slug":"errors-join-n","errorCode":null,"errorMessage":"${errors.join('\\n')}","messagePattern":"\\$\\{errors\\.join\\('\\\\n'\\)\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/utilities/prettier.ts","lineNumber":120,"sourceCode":"\n  // Spawn Prettier once per batch so repositories with many changed files do not\n  // overflow the OS command-line length limit. A failure in one batch (e.g. a file\n  // Prettier cannot parse) must not stop the remaining batches, matching the previous\n  // single-invocation behavior, so errors are collected and reported together.\n  const errors: string[] = [];\n  for (const batch of batchFilesByArgumentLength(files, baseLength, MAX_COMMAND_LINE_LENGTH)) {\n    try {\n      await execFileAsync(process.execPath, [...baseArgs, ...batch], {\n        cwd,\n        shell: false,\n      });\n    } catch (error) {\n      errors.push(error instanceof Error ? error.message : String(error));\n    }\n  }\n\n  if (errors.length > 0) {\n    throw new Error(errors.join('\\n'));\n  }\n}\n","sourceCodeStart":102,"sourceCodeEnd":123,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/utilities/prettier.ts#L102-L123","documentation":"`formatFiles` formats a batch of files (with Prettier) and collects every per-file formatting error instead of failing on the first one. After processing, if the `errors` array is non-empty it throws a single `Error` whose message is all collected error messages joined by newlines, so callers see every failure at once. This batches failures from schematic runs (`runSchematic`) and package migrations (`executePackageMigrations`).","triggerScenarios":"Running a schematic or migration (via `runSchematic`/`executePackageMigrations`) where formatting one or more touched files with Prettier throws — e.g. syntax errors in generated files, files that Prettier cannot parse, or formatter exceptions.","commonSituations":"A custom schematic generating syntactically invalid TypeScript/HTML; files with unsupported syntax for the installed Prettier version; concurrently modified files during migrations; generators emitting malformed templates.","solutions":["Read each line of the joined message — it contains one underlying error per failed file — and fix the listed files.","Run Prettier directly on the reported files (`npx prettier --check <file>`) to reproduce and see the full parser error.","Fix the generator/template that produced unparseable output and re-run the schematic/migration.","Pin a Prettier version compatible with your codebase's syntax, and format generated code in CI to catch issues early."],"exampleFix":"// error message\nUnexpected token (1:5)\nCannot format file: invalid.css\n// fix the reported file, then re-run\nnpx prettier --write src/broken-file.ts\nng generate ...  # re-run schematic","handlingStrategy":"try-catch","validationCode":"// Pre-validate generated files parse before running schematics/migrations:\nfor (const f of generatedFiles) {\n  try { ts.createSourceFile(f, readFileSync(f, 'utf8'), ts.ScriptTarget.Latest, true); }\n  catch (e) { throw new Error(`Generated file ${f} will fail formatting: ${e}`); }\n}","typeGuard":"function isBatchFormatError(e: unknown): e is Error {\n  return e instanceof Error && e.message.split('\\n').length > 1 && /format|parse|prettier/i.test(e.message);\n}","tryCatchPattern":"try {\n  await runSchematic(...);\n} catch (e) {\n  if (e instanceof Error) {\n    const perFileErrors = e.message.split('\\n'); // one entry per failed file\n    for (const msg of perFileErrors) console.error(msg);\n  } else { throw e; }\n}","preventionTips":["Read the joined message line-by-line: each line is one file's formatting error.","Run npx prettier --check on generated output in CI to catch failures early.","Fix templates/generators that emit syntactically invalid code.","Pin a Prettier version compatible with your syntax and keep it in sync with the CLI."],"tags":["prettier","formatting","schematic","angular-cli"],"backgroundTag":"formatter-failed","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}