Skip to content

Commit

Permalink
fix(content): helpful message for DuplicateContentEntry (#9492)
Browse files Browse the repository at this point in the history
* helpful message for DuplicateContentEntry

* add changeset
  • Loading branch information
lilnasy authored Dec 27, 2023
1 parent 7f7a7f1 commit 89a2a07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-zebras-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Improves error message for the case where two similarly named files result in the same content entry.
Original file line number Diff line number Diff line change
Expand Up @@ -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}**.`
Expand Down
8 changes: 6 additions & 2 deletions packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 89a2a07

Please sign in to comment.