diff --git a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Options.ts b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Options.ts index c8936f8032..438f918d5f 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Options.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Options.ts @@ -138,6 +138,11 @@ export type LoggerEvent = fnLoc: t.SourceLocation | null; fnName: string | null; memoSlots: number; + } + | { + kind: "PipelineError"; + fnLoc: t.SourceLocation | null; + data: any; }; export type Logger = { diff --git a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts index fb66c66f1e..18b92ee633 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts @@ -66,16 +66,31 @@ type CompileResult = { }; function handleError( - err: CompilerError, + err: unknown, pass: CompilerPass, fnLoc: t.SourceLocation | null ): void { if (pass.opts.logger) { - for (const detail of err.details) { + if (err instanceof CompilerError) { + for (const detail of err.details) { + pass.opts.logger.logEvent(pass.filename, { + kind: "CompileError", + fnLoc, + detail: detail.options, + }); + } + } else { + let stringifiedError; + if (err instanceof Error) { + stringifiedError = err.stack ?? err.message; + } else { + stringifiedError = err?.toString() ?? "[ null ]"; + } + pass.opts.logger.logEvent(pass.filename, { - kind: "CompileError", + kind: "PipelineError", fnLoc, - detail: detail.options, + data: stringifiedError, }); } }