Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/parser/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ParseError extends Error {
? `${message}. This error was caused by: ${options?.cause.message}.`
: message;
super(errorMessage);
this.cause = options?.cause;
Comment thread
dreamorosi marked this conversation as resolved.
Outdated
this.name = 'ParseError';
}
}
Expand Down
9 changes: 8 additions & 1 deletion packages/parser/tests/unit/envelope.test.ts
Comment thread
dreamorosi marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { z, ZodError } from 'zod';
import { Envelope } from '../../src/envelopes/envelope.js';
import { ParseError } from '../../src/errors.js';

Expand Down Expand Up @@ -74,5 +74,12 @@ describe('envelope: ', () => {
Envelope.parse({ name: 123 }, z.object({ name: z.string() }))
).toThrow();
});
it('the error has the cause attached to it', () => {
Comment thread
dreamorosi marked this conversation as resolved.
Outdated
try {
Envelope.parse('{"name": "John"}', z.object({ name: z.number() }));
} catch (error) {
expect((error as { cause: Error }).cause).toBeInstanceOf(ZodError);
Comment thread
dreamorosi marked this conversation as resolved.
Outdated
}
});
});
});