From 89a2a07c2e411cda32244b7b05d3c79e93f7dd84 Mon Sep 17 00:00:00 2001 From: Arsh <69170106+lilnasy@users.noreply.github.com> Date: Wed, 27 Dec 2023 17:56:42 +0000 Subject: [PATCH] fix(content): helpful message for DuplicateContentEntry (#9492) * helpful message for DuplicateContentEntry * add changeset --- .changeset/gold-zebras-burn.md | 5 +++++ .../astro/src/content/vite-plugin-content-virtual-mod.ts | 7 ++++++- packages/astro/src/core/errors/errors-data.ts | 8 ++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changeset/gold-zebras-burn.md diff --git a/.changeset/gold-zebras-burn.md b/.changeset/gold-zebras-burn.md new file mode 100644 index 000000000000..8cb15a42beaf --- /dev/null +++ b/.changeset/gold-zebras-burn.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Improves error message for the case where two similarly named files result in the same content entry. diff --git a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts index 92d47003e78d..7195ffffebe7 100644 --- a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts +++ b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts @@ -261,7 +261,12 @@ export async function generateLookupMap({ if (lookupMap[collection]?.entries?.[slug]) { throw new AstroError({ ...AstroErrorData.DuplicateContentEntrySlugError, - message: AstroErrorData.DuplicateContentEntrySlugError.message(collection, slug), + message: AstroErrorData.DuplicateContentEntrySlugError.message( + collection, + slug, + lookupMap[collection]!.entries[slug], + rootRelativePath(root, filePath), + ), hint: slug !== generatedSlug ? `Check the \`slug\` frontmatter property in **${id}**.` diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index 86ae6bbb5673..9e767e659837 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -1292,8 +1292,12 @@ export const DataCollectionEntryParseError = { export const DuplicateContentEntrySlugError = { name: 'DuplicateContentEntrySlugError', title: 'Duplicate content entry slug.', - message: (collection: string, slug: string) => { - return `**${collection}** contains multiple entries with the same slug: \`${slug}\`. Slugs must be unique.`; + message: (collection: string, slug: string, preExisting: string, alsoFound: string) => { + return `**${collection}** contains multiple entries with the same slug: \`${slug}\`. ` + + `Slugs must be unique.\n\n` + + `Entries: \n` + + `- ${preExisting}\n` + + `- ${alsoFound}`; }, } satisfies ErrorData;