-
-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Zod errors #1542
Improve Zod errors #1542
Conversation
🦋 Changeset detectedLatest commit: fa1cd88 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
size-limit report 📦
|
Includes support for setting custom snapshot serializers globally, see vitest-dev/vitest#5092
Co-Authored-By: HiDeoo <494699+HiDeoo@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AstroError
✨ 🤩
* main: [ci] format [ci] release (withastro#1555) Update lockfile & patch version of EC to latest (withastro#1553) [ci] format [ci] release (withastro#1546) Improve Zod errors (withastro#1542) Update `astro-expressive-code` dependency to `^0.33.2` (withastro#1541) i18n(ja): Update pages.mdx (withastro#1551) i18n(es): update `plugins` (withastro#1548)
Description
Improves our Zod error map:
Better handling of unions.
Previously they logged only “Did not match union” and no further information.
An example of the new format:
Better formatting of expected values.
Stringified objects/arrays now have some whitespace around items, e.g.
{ "label": "Text" }
instead of{"label":"Text"}
. They are also now wrapped in code backticks so they render as code in Astro’s error screens.Better handling of deeply nested issues. (Thanks @HiDeoo!)
Union errors that were found deep in a schema previously only reported the top-level path, e.g.
sidebar.0
. We are now able to show the full path, e.g.sidebar.0.items.1
.Refactors all
safeParse()
calls on Zod schemas to use a newparseWithFriendlyErrors()
utility which bundles up our logic for throwing an error with the error map.When throwing errors, uses
AstroError
for nicer formatting:Testing error messages is improved with a Vitest custom snapshot serializer, which captures both the
message
and thehint
fields onAstroError
. I updated Vitest to 1.3 to be able to configure this for all tests in one place (this feature was added in feat(config): addsnapshotSerializers
option vitest-dev/vitest#5092).