-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 errors for invalid IDs in content collections #12892
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 99397b0 The changes in this PR will be included in the next version bump. 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 |
CodSpeed Performance ReportMerging #12892 will not alter performanceComparing Summary
|
Great! A definite improvement. Could you add a test, checking that it throws the right error when passed a number for ID? Also can you add a |
@ascorbic Will do! |
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.
Just commenting on the error message for docs in general! I indicated a couple of places (but would apply throughout if appropriate) where this might be targeted specifically to IDs, if that is in fact what this is solely focused on.
I'll leave it to y'all, but just pointing out that if it makes sense to be more specific, it's often more helpful and informative to the user! (Also easier to come up with another error name in the case of a different kind of "invalid" result. 😄 )
Changes
This PR improves the error messages for IDs in content collections.
IDs in content collections have always been required to be strings, however the error message when passing (for example) a number would look like this:
This would even be the case if the original entry looked like this:
This PR changes these error messages so that they throw a new and more verbose AstroError based on the Zod validation.
For this to work, the parsing logic had to be moved from the functions return type schema to an external schema, and the validation had to be moved into the
simpleLoader
function itself due to performance issues with Zod when usingz.function().returns(...)
.Testing
The changes in this PR should be covered by the existing tests as no behavior has been added or changed.
Docs
/cc @withastro/maintainers-docs for feedback!
A docs PR has been made here