diff options
author | Matthew Phillips | 2024-09-06 10:38:37 -0400 |
---|---|---|
committer | GitHub | 2024-09-06 16:38:37 +0200 |
commit | b15f725ead981387f80f089d0523d9c2748b184e (patch) | |
tree | 1f1da57b6276d3fa82491b8e9416547a450b6dca | |
parent | 771403dd9415e1f0d31efa326ade0593adcb936d (diff) | |
download | IT.starlight-b15f725ead981387f80f089d0523d9c2748b184e.tar.gz IT.starlight-b15f725ead981387f80f089d0523d9c2748b184e.tar.bz2 IT.starlight-b15f725ead981387f80f089d0523d9c2748b184e.zip |
Prevent Zod errors from crashing build (#2288)
-rw-r--r-- | .changeset/famous-glasses-clean.md | 7 | ||||
-rw-r--r-- | packages/starlight/utils/error-map.ts | 3 |
2 files changed, 9 insertions, 1 deletions
diff --git a/.changeset/famous-glasses-clean.md b/.changeset/famous-glasses-clean.md new file mode 100644 index 00000000..b5749f54 --- /dev/null +++ b/.changeset/famous-glasses-clean.md @@ -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. diff --git a/packages/starlight/utils/error-map.ts b/packages/starlight/utils/error-map.ts index 667a91af..9c7475a0 100644 --- a/packages/starlight/utils/error-map.ts +++ b/packages/starlight/utils/error-map.ts @@ -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': |