@samitouri / QOS-React-1 / commits / 9965db70bd

Revert "[babel] Remove unused PipelineError"

This reverts commit 10d129a8406e9d226abdb6943bf8512e34ce91db --- Reverts #2311 due to undocumented assumptions being broken. I also added some comments to `LoggerEvents` to explain each event type. In `Program.ts`, we have something like the following code. `compile` could produce any number of errors (not just expected errors / instances of `CompilerError`). As an example, we sometimes error in `Codegen` due to babel version incompatibilities (`Error: ObjectMethod: Too many arguments passed. Received 7 but can receive no more than 5`). ```js try { // any error could be thrown here compile(input); } catch (e) { // unknown type for e handleError(e, ...); } ```

Mofei Zhang committed Nov 10, 2023 at 17:09 UTC 9965db70bdb7b97a12e791e1463d67fe169c2b50
2 files changed +24 -4
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Options.ts
+5
@@ -138,6 +138,11 @@ export type LoggerEvent =
138 fnLoc: t.SourceLocation | null;
139 fnName: string | null;
140 memoSlots: number;
141 + }
142 + | {
143 + kind: "PipelineError";
144 + fnLoc: t.SourceLocation | null;
145 + data: any;
146 };
147
148 export type Logger = {
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+19 -4
@@ -66,16 +66,31 @@ type CompileResult = {
66 };
67
68 function handleError(
69 - err: CompilerError,
69 + err: unknown,
70 pass: CompilerPass,
71 fnLoc: t.SourceLocation | null
72 ): void {
73 if (pass.opts.logger) {
74 - for (const detail of err.details) {
74 + if (err instanceof CompilerError) {
75 + for (const detail of err.details) {
76 + pass.opts.logger.logEvent(pass.filename, {
77 + kind: "CompileError",
78 + fnLoc,
79 + detail: detail.options,
80 + });
81 + }
82 + } else {
83 + let stringifiedError;
84 + if (err instanceof Error) {
85 + stringifiedError = err.stack ?? err.message;
86 + } else {
87 + stringifiedError = err?.toString() ?? "[ null ]";
88 + }
89 +
90 pass.opts.logger.logEvent(pass.filename, {
76 - kind: "CompileError",
91 + kind: "PipelineError",
92 fnLoc,
78 - detail: detail.options,
93 + data: stringifiedError,
94 });
95 }
96 }