diff --git a/packages/starlight/user-components/LinkCard.astro b/packages/starlight/user-components/LinkCard.astro index f9c50f30ba..5e647f1d7e 100644 --- a/packages/starlight/user-components/LinkCard.astro +++ b/packages/starlight/user-components/LinkCard.astro @@ -4,6 +4,7 @@ import Badge from '../components/Badge.astro'; import { BadgeConfigSchema, type BadgeUserConfig } from '../schemas/badge'; import { errorMap } from '../utils/error-map'; import type { HTMLAttributes } from 'astro/types'; +import { AstroError } from 'astro/errors'; interface Props extends Omit, 'title'> { title: string; @@ -13,7 +14,17 @@ interface Props extends Omit, 'title'> { const { title, badge, description, ...attributes } = Astro.props; -const badgeData = BadgeConfigSchema().parse(badge, { errorMap }); +const badgeData = BadgeConfigSchema().safeParse(badge, { errorMap }); + +if (!badgeData.success) { + throw new AstroError( + 'Invalid `badge` prop passed to `` for route `' + + Astro.url.pathname + + '`.\n\n' + + badgeData.error.issues.map((i) => i.message).join('\n'), + 'Find out more at https://starlight.astro.build/reference/frontmatter/#badge' + ); +} ---
@@ -26,7 +37,7 @@ const badgeData = BadgeConfigSchema().parse(badge, { errorMap }); badge && ( <> {' '} - + ) }