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;