diff --git a/.changeset/thirty-hairs-pump.md b/.changeset/thirty-hairs-pump.md new file mode 100644 index 0000000000..acb4d1da23 --- /dev/null +++ b/.changeset/thirty-hairs-pump.md @@ -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. diff --git a/packages/astro-rss/src/index.ts b/packages/astro-rss/src/index.ts index 48c5defe85..738e696f39 100644 --- a/packages/astro-rss/src/index.ts +++ b/packages/astro-rss/src/index.ts @@ -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;