mirror of
https://github.com/withastro/astro.git
synced 2025-03-24 23:21:57 -05:00
fix(content): helpful message for DuplicateContentEntry (#9492)
* helpful message for DuplicateContentEntry * add changeset
This commit is contained in:
parent
7f7a7f1aea
commit
89a2a07c2e
3 changed files with 17 additions and 3 deletions
.changeset
packages/astro/src
5
.changeset/gold-zebras-burn.md
Normal file
5
.changeset/gold-zebras-burn.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Improves error message for the case where two similarly named files result in the same content entry.
|
|
@ -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}**.`
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue