Skip to content

Commit

Permalink
Prevent Zod errors from crashing build (#2288)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Sep 6, 2024
1 parent 771403d commit b15f725
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/famous-glasses-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astrojs/starlight': patch
---

Safely handle Zod errors

Prevents bugs where errors without the `.received` props would through and cause builds to fail unnecessarily.
3 changes: 2 additions & 1 deletion packages/starlight/utils/error-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ const errorMap: z.ZodErrorMap = (baseError, ctx) => {
};

const getTypeOrLiteralMsg = (error: TypeOrLiteralErrByPathEntry): string => {
if (error.received === 'undefined') return 'Required';
// received could be `undefined` or the string `'undefined'`
if (typeof error.received === 'undefined' || error.received === 'undefined') return 'Required';
const expectedDeduped = new Set(error.expected);
switch (error.code) {
case 'invalid_type':
Expand Down

0 comments on commit b15f725

Please sign in to comment.