Skip to content

Commit

Permalink
[@astrojs/rss] Quality-of-Life Improvement to items property-relate…
Browse files Browse the repository at this point in the history
…d error (#9299)

* This commit addresses a quality-of-life concern when setting up a RSS feed
when using collections. Specifically, it provides more context to the error
message thrown when the object passed to the `items` property is missing any
of the three required keys or if one of those keys is mistyped.

* Add changeset

* Update .changeset with properly formatted update structure

@sarah11918 suggested a change to the verbiage that properly formatted the update detail in question. Accepting the suggestion.

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

---------

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
  • Loading branch information
cdvillard and sarah11918 authored Dec 6, 2023
1 parent eb94294 commit edfae50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-hairs-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/rss': patch
---

Improves the `@astrojs/rss` error message thrown when the object passed to the `items` property is missing any of the three required keys or if one of those keys is mistyped.
17 changes: 15 additions & 2 deletions packages/astro-rss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,21 @@ async function validateRssOptions(rssOptions: RSSOptions) {
[
`[RSS] Invalid or missing options:`,
...parsedResult.error.errors.map(
(zodError) => `${zodError.message} (${zodError.path.join('.')})`
),
(zodError) => {
const path = zodError.path.join('.');
const message = `${zodError.message} (${path})`;
const code = zodError.code;

if (path === 'items' && code === 'invalid_union') {
return [
message,
`The \`items\` property requires properly typed \`title\`, \`pubDate\`, and \`link\` keys.`,
`Check your collection's schema, and visit https://docs.astro.build/en/guides/rss/#generating-items for more info.`
].join('\n')
}

return message;
}),
].join('\n')
);
throw formattedError;
Expand Down

0 comments on commit edfae50

Please sign in to comment.