mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user