Skip to content

Commit edfae50

Browse files
[@astrojs/rss] Quality-of-Life Improvement to items property-related 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 <[email protected]> --------- Co-authored-by: Sarah Rainsberger <[email protected]>
1 parent eb94294 commit edfae50

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

.changeset/thirty-hairs-pump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/rss': patch
3+
---
4+
5+
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.

packages/astro-rss/src/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,21 @@ async function validateRssOptions(rssOptions: RSSOptions) {
110110
[
111111
`[RSS] Invalid or missing options:`,
112112
...parsedResult.error.errors.map(
113-
(zodError) => `${zodError.message} (${zodError.path.join('.')})`
114-
),
113+
(zodError) => {
114+
const path = zodError.path.join('.');
115+
const message = `${zodError.message} (${path})`;
116+
const code = zodError.code;
117+
118+
if (path === 'items' && code === 'invalid_union') {
119+
return [
120+
message,
121+
`The \`items\` property requires properly typed \`title\`, \`pubDate\`, and \`link\` keys.`,
122+
`Check your collection's schema, and visit https://docs.astro.build/en/guides/rss/#generating-items for more info.`
123+
].join('\n')
124+
}
125+
126+
return message;
127+
}),
115128
].join('\n')
116129
);
117130
throw formattedError;

0 commit comments

Comments
 (0)