[be] Flag and test for unexpected exceptions during compilations

This commit is contained in:
Mofei Zhang
2023-11-12 14:56:10 -05:00
parent 7db2388fff
commit f47685c602
4 changed files with 46 additions and 0 deletions
@@ -361,6 +361,15 @@ function* runWithEnvironment(
const ast = codegenReactiveFunction(reactiveFunction).unwrap();
yield log({ kind: "ast", name: "Codegen", value: ast });
/**
* This flag should be only set for unit / fixture tests to check
* that Forget correctly handles unexpected errors (e.g. exceptions
* thrown by babel functions or other unexpected exceptions).
*/
if (env.config.throwUnknownException__testonly) {
throw new Error("unexpected error");
}
return ast;
}
@@ -281,6 +281,12 @@ const EnvironmentConfigSchema = z.object({
* Intended for use in demo purposes (incl playground)
*/
enableMemoizationComments: z.boolean().default(false),
/**
* [TESTING ONLY] Throw an unknown exception during compilation to
* simulate unexpected exceptions e.g. errors from babel functions.
*/
throwUnknownException__testonly: z.boolean().default(false),
});
export type EnvironmentConfig = z.infer<typeof EnvironmentConfigSchema>;
@@ -0,0 +1,23 @@
## Input
```javascript
// @throwUnknownException__testonly:true
function Component() {}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [],
};
```
## Error
```
unexpected error
```
@@ -0,0 +1,8 @@
// @throwUnknownException__testonly:true
function Component() {}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [],
};