From edfae50e6ea494f49c6d4fbf4bd4481870f994b1 Mon Sep 17 00:00:00 2001 From: Charles Villard Date: Wed, 6 Dec 2023 07:13:15 -0500 Subject: [PATCH] [@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 --------- Co-authored-by: Sarah Rainsberger --- .changeset/thirty-hairs-pump.md | 5 +++++ packages/astro-rss/src/index.ts | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 .changeset/thirty-hairs-pump.md 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;