[be] Flag and test for unexpected exceptions during compilations
Mofei Zhang committed
Nov 12, 2023 at 14:56 UTC
f47685c6020cf3a9b5cec21e2c6eef02c7303ec6
4 files changed
+46
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Pipeline.ts
+9
@@ -361,6 +361,15 @@ function* runWithEnvironment(
361
const ast = codegenReactiveFunction(reactiveFunction).unwrap();
362
yield log({ kind: "ast", name: "Codegen", value: ast });
363
364
+ /**
365
+ * This flag should be only set for unit / fixture tests to check
366
+ * that Forget correctly handles unexpected errors (e.g. exceptions
367
+ * thrown by babel functions or other unexpected exceptions).
368
+ */
369
+ if (env.config.throwUnknownException__testonly) {
370
+ throw new Error("unexpected error");
371
+ }
372
+
373
return ast;
374
}
375
compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts
+6
@@ -281,6 +281,12 @@ const EnvironmentConfigSchema = z.object({
281
* Intended for use in demo purposes (incl playground)
282
*/
283
enableMemoizationComments: z.boolean().default(false),
284
+
285
+ /**
286
+ * [TESTING ONLY] Throw an unknown exception during compilation to
287
+ * simulate unexpected exceptions e.g. errors from babel functions.
288
+ */
289
+ throwUnknownException__testonly: z.boolean().default(false),
290
});
291
292
export type EnvironmentConfig = z.infer<typeof EnvironmentConfigSchema>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.handle-unexpected-exception-pipeline.expect.md
new
+23
@@ -0,0 +1,23 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+// @throwUnknownException__testonly:true
6
+
7
+function Component() {}
8
+
9
+export const FIXTURE_ENTRYPOINT = {
10
+ fn: Component,
11
+ params: [],
12
+};
13
+
14
+```
15
+
16
+
17
+## Error
18
+
19
+```
20
+unexpected error
21
+```
22
+
23
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.handle-unexpected-exception-pipeline.ts
new
+8
@@ -0,0 +1,8 @@
1
+// @throwUnknownException__testonly:true
2
+
3
+function Component() {}
4
+
5
+export const FIXTURE_ENTRYPOINT = {
6
+ fn: Component,
7
+ params: [],
8
+};