Skip to content

Commit 89a2a07

Browse files
authoredDec 27, 2023
fix(content): helpful message for DuplicateContentEntry (#9492)
* helpful message for DuplicateContentEntry * add changeset
1 parent 7f7a7f1 commit 89a2a07

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed
 

‎.changeset/gold-zebras-burn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Improves error message for the case where two similarly named files result in the same content entry.

‎packages/astro/src/content/vite-plugin-content-virtual-mod.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ export async function generateLookupMap({
261261
if (lookupMap[collection]?.entries?.[slug]) {
262262
throw new AstroError({
263263
...AstroErrorData.DuplicateContentEntrySlugError,
264-
message: AstroErrorData.DuplicateContentEntrySlugError.message(collection, slug),
264+
message: AstroErrorData.DuplicateContentEntrySlugError.message(
265+
collection,
266+
slug,
267+
lookupMap[collection]!.entries[slug],
268+
rootRelativePath(root, filePath),
269+
),
265270
hint:
266271
slug !== generatedSlug
267272
? `Check the \`slug\` frontmatter property in **${id}**.`

‎packages/astro/src/core/errors/errors-data.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1292,8 +1292,12 @@ export const DataCollectionEntryParseError = {
12921292
export const DuplicateContentEntrySlugError = {
12931293
name: 'DuplicateContentEntrySlugError',
12941294
title: 'Duplicate content entry slug.',
1295-
message: (collection: string, slug: string) => {
1296-
return `**${collection}** contains multiple entries with the same slug: \`${slug}\`. Slugs must be unique.`;
1295+
message: (collection: string, slug: string, preExisting: string, alsoFound: string) => {
1296+
return `**${collection}** contains multiple entries with the same slug: \`${slug}\`. ` +
1297+
`Slugs must be unique.\n\n` +
1298+
`Entries: \n` +
1299+
`- ${preExisting}\n` +
1300+
`- ${alsoFound}`;
12971301
},
12981302
} satisfies ErrorData;
12991303

0 commit comments

Comments
 (0)
Please sign in to comment.