summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Arsh <69170106+lilnasy@users.noreply.github.com> 2023-12-27 17:56:42 +0000
committerGravatar GitHub <noreply@github.com> 2023-12-27 12:56:42 -0500
commit89a2a07c2e411cda32244b7b05d3c79e93f7dd84 (patch)
tree7f3862625f328c0d20d7c59052090c633ed793b3
parent7f7a7f1aeaec6b327ae0e5e7470a4f46174bf8ae (diff)
downloadastro-89a2a07c2e411cda32244b7b05d3c79e93f7dd84.tar.gz
astro-89a2a07c2e411cda32244b7b05d3c79e93f7dd84.tar.zst
astro-89a2a07c2e411cda32244b7b05d3c79e93f7dd84.zip
fix(content): helpful message for DuplicateContentEntry (#9492)
* helpful message for DuplicateContentEntry * add changeset
-rw-r--r--.changeset/gold-zebras-burn.md5
-rw-r--r--packages/astro/src/content/vite-plugin-content-virtual-mod.ts7
-rw-r--r--packages/astro/src/core/errors/errors-data.ts8
3 files changed, 17 insertions, 3 deletions
diff --git a/.changeset/gold-zebras-burn.md b/.changeset/gold-zebras-burn.md
new file mode 100644
index 000000000..8cb15a42b
--- /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 92d47003e..7195ffffe 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 86ae6bbb5..9e767e659 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;