-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: add cache hint support to live loaders #13767
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1614,8 +1614,9 @@ export const InvalidContentEntryDataError = { | |||||
| title: 'Content entry data does not match schema.', | ||||||
| message(collection: string, entryId: string, error: ZodError) { | ||||||
| return [ | ||||||
| `**${String(collection)} → ${String(entryId)}** data does not match collection schema.`, | ||||||
| ...error.errors.map((zodError) => zodError.message), | ||||||
| `**${String(collection)} → ${String(entryId)}** data does not match collection schema.\n`, | ||||||
| ...error.errors.map((zodError) => ` **${zodError.path.join('.')}**: ${zodError.message}`), | ||||||
| '', | ||||||
| ].join('\n'); | ||||||
| }, | ||||||
| hint: 'See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas.', | ||||||
|
|
@@ -1665,13 +1666,39 @@ export const ContentEntryDataError = { | |||||
| title: 'Content entry data does not match schema.', | ||||||
| message(collection: string, entryId: string, error: ZodError) { | ||||||
| return [ | ||||||
| `**${String(collection)} → ${String(entryId)}** data does not match collection schema.`, | ||||||
| ...error.errors.map((zodError) => zodError.message), | ||||||
| `**${String(collection)} → ${String(entryId)}** data does not match collection schema.\n`, | ||||||
| ...error.errors.map((zodError) => ` **${zodError.path.join('.')}**: ${zodError.message}`), | ||||||
| '', | ||||||
| ].join('\n'); | ||||||
| }, | ||||||
| hint: 'See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas.', | ||||||
| } satisfies ErrorData; | ||||||
|
|
||||||
| /** | ||||||
| * @docs | ||||||
| * @message | ||||||
| * **Example error message:**<br/> | ||||||
| * **blog** → **post** returned an invalid cache hint.<br/> | ||||||
| * **maxAge**: Expected number, received string | ||||||
| * @description | ||||||
| * The loader for a live content collection returned an invalid cache hint. | ||||||
| * Make sure that if you are using a cache hint, it is a valid object. | ||||||
|
||||||
| * Make sure that if you are using a cache hint, it is a valid object. | |
| * Make sure that your cache hint object is properly formatted. |
Just two quick things jump to mind:
-
if an invalid cache hint was received, then presumably they are using a cache hint? So we can avoid that extra wording? (Or at least, safe enough? If someone reacts, "Wait, I didn't think I provided a cache hint..." then this message is also helpful to show them where to look for their error.)
-
"It's invalid. Make it valid" could be a tiny bit more helpful if instead of "make it valid", we can prompt with what's likely to make it invalid, or at the very least, not duplicate "valid" which can feel like a "duh!" kind of error message. 😅 Both
tagsandmaxAgeappear to be optional, so it's probably not e.g. that one is missing, but something like that the type or syntax was wrong?
The other alternative is to be more descriptive about the first sentence, like:
The loader for a live content collection could not determine a caching strategy (/how to cache your content). Make sure that your cache hint is a valid object.
I think either change to avoid duplication feels helpful!
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.
I suppose what I was trying to get at was "Your hint is invalid. Fix it or remove it", because it's optional
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.
How about Make sure that cacheHint is an object with the correct properties, or is undefined.
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.
When adding the new error I noticed that these were missing the path, which could cause unhelpful errors
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.
2 things:
String(...)when the type is alreadystring?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.
Can you provide two screenshots: one before and after the change?
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.
This is a very old error - I just added the
zodError.path.join('.')bit. I followed the same pattern for the one I added. You're right the string cast isn't needed, but I think that standardising the formatting of the zod error does make senseThere 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.
Before:

After:

See the field name
titlehas been addedThere 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.
Ah sorry I didn't notice it was an old one