{"record":{"id":"b145c066a465734f","repo":"angular/angular-cli","slug":"warning-formatting-of-files-failed-with-the-follo","errorCode":null,"errorMessage":"WARNING: Formatting of files failed with the following error: ${error.message}","messagePattern":"WARNING: Formatting of files failed with the following error: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/angular/cli/src/command-builder/schematics-command-module.ts","lineNumber":376,"sourceCode":"\n      if (!files.size) {\n        logger.info('Nothing to be done.');\n      }\n\n      if (executionOptions.dryRun) {\n        logger.warn(`\\nNOTE: The \"--dry-run\" option means no changes were made.`);\n\n        return 0;\n      }\n\n      if (files.size) {\n        // Note: we could use a task executor to format the files but this is simpler.\n        try {\n          await formatFiles(this.context.root, files);\n        } catch (error) {\n          assertIsError(error);\n\n          logger.warn(\n            `WARNING: Formatting of files failed with the following error: ${error.message}`,\n          );\n        }\n      }\n\n      return 0;\n    } catch (err) {\n      // In case the workflow was not successful, show an appropriate error message.\n      if (err instanceof UnsuccessfulWorkflowExecution) {\n        // \"See above\" because we already printed the error.\n        logger.fatal('The Schematic workflow failed. See above.');\n      } else {\n        assertIsError(err);\n        logger.fatal(err.message);\n      }\n\n      return 1;\n    } finally {","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/command-builder/schematics-command-module.ts#L358-L394","documentation":"After a schematic runs, the schematics command tries to format the touched files with the configured formatter (Prettier). If formatFiles throws, runSchematic does not fail the command; instead it logs this warning including the formatter error message, since formatting is a post-generation nicety, not a required step.","triggerScenarios":"Running `ng generate` where the generated/modified files cannot be formatted — e.g. Prettier hits a parse error on generated content, an unsupported/unreadable file, or the formatter misconfigures (bad .prettierrc, missing parser for extension).","commonSituations":"Custom schematics generating syntactically invalid placeholder code, files with unusual extensions lacking a Prettier parser, permission issues writing files, or a malformed prettier config in the repo.","solutions":["Inspect the error message appended after the warning — it identifies the file/format problem; fix that file or config.","Run the formatter directly on the affected files (`npx prettier --write <file>`) to see the full error and correct it.","Fix .prettierrc issues (invalid options, wrong parser overrides) or add a parser override for custom extensions.","If the generated code itself is malformed, fix the schematic/template producing it; formatting failure is a symptom."],"exampleFix":"// before (.prettierrc)\n{ \"parser\": \"babel\" }\n// after\n{ \"overrides\": [{ \"files\": \"*.ts\", \"options\": { \"parser\": \"typescript\" } }] }","handlingStrategy":"try-catch","validationCode":"// Validate prettier config parses before generating\nimport { resolveConfig } from 'prettier';\nconst cfg = await resolveConfig(process.cwd());\nif (cfg === null) console.warn('No prettier config found; formatting may behave unexpectedly');","typeGuard":null,"tryCatchPattern":"try {\n  await ngGenerate(['component', 'hero']);\n} catch (e) {\n  // this warning is logged, not thrown; detect it in CLI output\n  if (/Formatting of files failed/.test(String(e))) {\n    console.warn('Generation succeeded but formatting failed; run `npx prettier --write .` manually.');\n  } else throw e;\n}","preventionTips":["Keep a valid .prettierrc with parsers/overrides for every custom file extension schematics may emit.","Run `npx prettier --check .` in CI so formatting regressions surface early.","Treat the warning as non-fatal: files were generated; format them manually with `npx prettier --write .`.","Fix schematics/templates that emit syntactically invalid code, which is the usual root cause."],"tags":["formatting","prettier","schematics"],"backgroundTag":"file-formatting-failed","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}