Conversation
Greptile SummaryRemoves the
Confidence Score: 5/5
Important Files Changed
Last reviewed commit: 8d76b6f |
| kind: 'err', | ||
| msg: | ||
| `Compiler pass(es) threw instead of recording errors:\n` + | ||
| unexpectedThrows.map(l => (l.event as any).data).join('\n'), |
There was a problem hiding this comment.
Unnecessary as any cast
Since the unexpectedThrows array is already filtered to log.event.kind === 'CompileUnexpectedThrow', TypeScript should be able to narrow the event type to CompileUnexpectedThrowEvent which has a data property. You could replace the as any cast with a proper type narrowing or type assertion to CompileUnexpectedThrowEvent for better type safety.
| unexpectedThrows.map(l => (l.event as any).data).join('\n'), | |
| unexpectedThrows.map(l => (l.event as {data: string}).data).join('\n'), |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/snap/src/compiler.ts
Line: 389
Comment:
**Unnecessary `as any` cast**
Since the `unexpectedThrows` array is already filtered to `log.event.kind === 'CompileUnexpectedThrow'`, TypeScript should be able to narrow the event type to `CompileUnexpectedThrowEvent` which has a `data` property. You could replace the `as any` cast with a proper type narrowing or type assertion to `CompileUnexpectedThrowEvent` for better type safety.
```suggestion
unexpectedThrows.map(l => (l.event as {data: string}).data).join('\n'),
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.| if (cx.errors.hasAnyErrors()) { | ||
| return Err(cx.errors); | ||
| fn.env.recordErrors(cx.errors); | ||
| } |
There was a problem hiding this comment.
Codegen continues after recording errors
After cx.errors are recorded on fn.env at line 351, codegenReactiveFunction continues to build and return the CodegenFunction object (lines 357-378). This is by design for the fault-tolerance model, but it means the returned AST was generated from a reactive function that had codegen errors (e.g. unsupported for-in/for-of patterns that emitted t.emptyStatement()). The caller codegenFunction then proceeds to process outlined functions, add hook guards, etc. using this potentially-malformed AST.
This is fine because Pipeline.ts checks env.hasErrors() at the end and returns Err(...) if any errors were recorded, so the malformed AST is never emitted. Just flagging for awareness — if any future code path were to use the returned CodegenFunction without checking env.hasErrors(), it could emit incorrect code.
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts
Line: 350-352
Comment:
**Codegen continues after recording errors**
After `cx.errors` are recorded on `fn.env` at line 351, `codegenReactiveFunction` continues to build and return the `CodegenFunction` object (lines 357-378). This is by design for the fault-tolerance model, but it means the returned AST was generated from a reactive function that had codegen errors (e.g. unsupported for-in/for-of patterns that emitted `t.emptyStatement()`). The caller `codegenFunction` then proceeds to process outlined functions, add hook guards, etc. using this potentially-malformed AST.
This is fine because `Pipeline.ts` checks `env.hasErrors()` at the end and returns `Err(...)` if any errors were recorded, so the malformed AST is never emitted. Just flagging for awareness — if any future code path were to use the returned `CodegenFunction` without checking `env.hasErrors()`, it could emit incorrect code.
How can I resolve this? If you propose a fix, please make it concise.…ing throws Remove `tryRecord()` from the compilation pipeline now that all passes record errors directly via `env.recordError()` / `env.recordErrors()`. A single catch-all try/catch in Program.ts provides the safety net for any pass that incorrectly throws instead of recording. Key changes: - Remove all ~64 `env.tryRecord()` wrappers in Pipeline.ts - Delete `tryRecord()` method from Environment.ts - Add `CompileUnexpectedThrow` logger event so thrown errors are detectable - Log `CompileUnexpectedThrow` in Program.ts catch-all for non-invariant throws - Fail snap tests on `CompileUnexpectedThrow` to surface pass bugs in dev - Convert throwTodo/throwDiagnostic calls in HIRBuilder (fbt, this), CodegenReactiveFunction (for-in/for-of), and BuildReactiveFunction to record errors or use invariants as appropriate - Remove try/catch from BuildHIR's lower() since inner throws are now recorded - CollectOptionalChainDependencies: return null instead of throwing on unsupported optional chain patterns (graceful optimization skip)
|
Upstream PR was closed or merged. Code is synced via branch mirror. |
Mirror of facebook/react#35881
Original author: josephsavona
Remove
tryRecord()from the compilation pipeline now that all passes recorderrors directly via
env.recordError()/env.recordErrors(). A singlecatch-all try/catch in Program.ts provides the safety net for any pass that
incorrectly throws instead of recording.
Key changes:
env.tryRecord()wrappers in Pipeline.tstryRecord()method from Environment.tsCompileUnexpectedThrowlogger event so thrown errors are detectableCompileUnexpectedThrowin Program.ts catch-all for non-invariant throwsCompileUnexpectedThrowto surface pass bugs in devCodegenReactiveFunction (for-in/for-of), and BuildReactiveFunction to
record errors or use invariants as appropriate
unsupported optional chain patterns (graceful optimization skip)
Stack created with Sapling. Best reviewed with ReviewStack.