Conversation
Add detailed plan for making the React Compiler fault-tolerant by accumulating errors across all passes instead of stopping at the first error. This enables reporting multiple compilation errors at once.
Add error accumulation methods to the Environment class: - #errors field to accumulate CompilerErrors across passes - recordError() to record a single diagnostic (throws if Invariant) - recordErrors() to record all diagnostics from a CompilerError - hasErrors() to check if any errors have been recorded - aggregateErrors() to retrieve the accumulated CompilerError - tryRecord() to wrap callbacks and catch CompilerErrors
Greptile SummaryThis PR adds Phase 1 of the React Compiler fault tolerance initiative: error accumulation infrastructure on the
Confidence Score: 4/5
Important Files Changed
Last reviewed commit: af88b0b |
| hasErrors(): boolean { | ||
| return this.#errors.hasAnyErrors(); | ||
| } |
There was a problem hiding this comment.
hasErrors() returns true for warnings and hints too
hasErrors() delegates to CompilerError.hasAnyErrors(), which returns true when details.length > 0 — this includes diagnostics of any severity (Error, Warning, Hint). This is different from CompilerError.hasErrors() (no "Any" prefix) which only checks for ErrorSeverity.Error.
In Phase 2 (per the plan doc), the pipeline will use env.hasErrors() to decide between Ok(ast) and Err(aggregatedErrors). If a pass records only warnings/hints, hasErrors() will return true and the pipeline will return Err(...), potentially causing a bailout for non-error diagnostics. If this is intentional (i.e., any recorded diagnostic should prevent emitting compiled output), the naming may be worth a doc comment clarifying the semantics. If not, consider delegating to this.#errors.hasErrors() instead.
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts
Line: 1011-1013
Comment:
**`hasErrors()` returns true for warnings and hints too**
`hasErrors()` delegates to `CompilerError.hasAnyErrors()`, which returns `true` when `details.length > 0` — this includes diagnostics of any severity (Error, Warning, Hint). This is different from `CompilerError.hasErrors()` (no "Any" prefix) which only checks for `ErrorSeverity.Error`.
In Phase 2 (per the plan doc), the pipeline will use `env.hasErrors()` to decide between `Ok(ast)` and `Err(aggregatedErrors)`. If a pass records only warnings/hints, `hasErrors()` will return `true` and the pipeline will return `Err(...)`, potentially causing a bailout for non-error diagnostics. If this is intentional (i.e., any recorded diagnostic should prevent emitting compiled output), the naming may be worth a doc comment clarifying the semantics. If not, consider delegating to `this.#errors.hasErrors()` instead.
How can I resolve this? If you propose a fix, please make it concise.|
Upstream PR was closed or merged. Code is synced via branch mirror. |
Mirror of facebook/react#35829
Original author: josephsavona
Add error accumulation methods to the Environment class:
Stack created with Sapling. Best reviewed with ReviewStack.