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, ...); 

} 

```
This commit is contained in:
Mofei Zhang
2023-11-10 17:09:29 -05:00
parent bd3661020e
commit 9965db70bd
2 changed files with 24 additions and 4 deletions
@@ -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 = {
@@ -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,
});
}
}