mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-27 11:42:52 +00:00
fix(server): preserve compiler error metadata across workers
This commit is contained in:
@@ -10,6 +10,7 @@ export type CompilerReply =
|
||||
| {
|
||||
kind: "error";
|
||||
error: Error;
|
||||
properties: Record<string, unknown>;
|
||||
issues?: ZodIssue[];
|
||||
errors?: unknown[];
|
||||
warnings?: unknown[];
|
||||
@@ -50,6 +51,9 @@ async function run(task: CompilerTask): Promise<void> {
|
||||
port.postMessage({
|
||||
kind: "error",
|
||||
error,
|
||||
// Error cloning drops own metadata such as filesystem code/path. Zod's
|
||||
// readonly issues are reconstructed separately by the compiler owner.
|
||||
properties: Object.fromEntries(Object.entries(error).filter(([key]) => key !== "issues")),
|
||||
...("issues" in error ? { issues: error.issues as ZodIssue[] } : {}),
|
||||
...("errors" in error ? { errors: error.errors as unknown[] } : {}),
|
||||
...("warnings" in error ? { warnings: error.warnings as unknown[] } : {}),
|
||||
|
||||
@@ -1015,3 +1015,14 @@ it("preserves manifest validation errors across the compiler boundary", async ()
|
||||
await writeFile(path.join(directory, "paseo-plugin.json"), "{");
|
||||
await expect(compileDirectoryPlugin(directory, "0.13.2")).rejects.toBeInstanceOf(SyntaxError);
|
||||
});
|
||||
|
||||
it("preserves filesystem error metadata for a missing entry", async () => {
|
||||
const { server } = await createSplitPlugin();
|
||||
await rm(server);
|
||||
await expect(compilePlugin({ client: null, server })).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
errno: expect.any(Number),
|
||||
syscall: "realpath",
|
||||
path: server,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -111,6 +111,7 @@ class PluginCompiler {
|
||||
resolve(reply.value as TaskResult[T["kind"]]);
|
||||
} else {
|
||||
const error = reply.issues ? new ZodError(reply.issues) : reply.error;
|
||||
Object.assign(error, reply.properties);
|
||||
if (reply.errors) Object.assign(error, { errors: reply.errors });
|
||||
if (reply.warnings) Object.assign(error, { warnings: reply.warnings });
|
||||
// Promise.all can reject while the other target is still compiling.
|
||||
|
||||
Reference in New Issue
Block a user