Skip to content

Commit beeeff1

Browse files
committed
Update errors
1 parent 56fcf3f commit beeeff1

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

packages/astro/src/content/config.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,18 @@ export function defineCollection<S extends BaseSchema>(
182182
});
183183
}
184184

185-
// TODO: add links to the migration guide in these errors
186185
if (!('loader' in config)) {
187-
throw new AstroUserError(
188-
`Collections must have a \`loader\` defined. Check your collection definitions in ${importerFilename ?? 'your content config file'}. `,
189-
);
186+
throw new AstroError({
187+
...AstroErrorData.ContentCollectionMissingLoader,
188+
message: AstroErrorData.ContentCollectionMissingLoader.message(importerFilename),
189+
});
190190
}
191191

192192
if (config.type && config.type !== CONTENT_LAYER_TYPE) {
193-
throw new AstroUserError(
194-
`Invalid collection type "${config.type}". Remove the type from your collection definition in ${importerFilename ?? 'your content config file'}.`,
195-
);
193+
throw new AstroError({
194+
...AstroErrorData.ContentCollectionInvalidType,
195+
message: AstroErrorData.ContentCollectionInvalidType.message(config.type, importerFilename),
196+
});
196197
}
197198

198199
if (

packages/astro/src/content/runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,13 @@ export function createGetEntry({ liveCollections }: { liveCollections: LiveColle
210210
...entry,
211211
collection,
212212
} as DataEntryResult | ContentEntryResult;
213+
// TODO: remove in Astro 7
213214
warnForPropertyAccess(
214215
result.data,
215216
'slug',
216217
`[content] Attempted to access deprecated property on "${collection}" entry.\nThe "slug" property is no longer automatically added to entries. Please use the "id" property instead.`,
217218
);
219+
// TODO: remove in Astro 7
218220
warnForPropertyAccess(
219221
result,
220222
'render',

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,42 @@ export const LegacyContentConfigError = {
16701670
hint: 'See https://docs.astro.build/en/guides/upgrade-to/v6/#removed-legacy-content-collections for more information on updating collections.',
16711671
} satisfies ErrorData;
16721672

1673+
/**
1674+
* @docs
1675+
* @message
1676+
* **Example error message:**<br/>
1677+
* Collections must have a `loader` defined. Check your collection definitions in your content config file.<br/>
1678+
* @description
1679+
* A content collection is missing a `loader` definition. Make sure that each collection in your content config file has a `loader`.
1680+
* See the [Content collections documentation](https://docs.astro.build/en/guides/content-collections/) for more information.
1681+
*/
1682+
1683+
export const ContentCollectionMissingLoader = {
1684+
name: 'ContentCollectionMissingLoader',
1685+
title: 'Content collection is missing a `loader` definition.',
1686+
message: (file = 'your content config file') =>
1687+
`Collections must have a \`loader\` defined. Check your collection definitions in ${file}.`,
1688+
hint: 'See https://docs.astro.build/en/guides/content-collections/ for more information on content loaders and https://docs.astro.build/en/guides/upgrade-to/v6/#removed-legacy-content-collections for more information on migrating from legacy collections.',
1689+
} satisfies ErrorData;
1690+
1691+
/**
1692+
* @docs
1693+
* @message
1694+
* **Example error message:**<br/>
1695+
* Invalid collection type "data". Remove the type from your collection definition in your content config file.
1696+
* @description
1697+
* Content collections should no longer have a `type` field. Remove this field from your content config file.
1698+
* See the [Astro 6 migration guide](https://docs.astro.build/en/guides/upgrade-to/v6/#removed-legacy-content-collections) for more information.
1699+
*/
1700+
1701+
export const ContentCollectionInvalidType = {
1702+
name: 'ContentCollectionInvalidType',
1703+
title: 'Content collection has an invalid `type` field.',
1704+
message: (type: string, file = 'your content config file') =>
1705+
`Invalid collection type "${type}". Remove the type from your collection definition in ${file}.`,
1706+
hint: 'See https://docs.astro.build/en/guides/upgrade-to/v6/#removed-legacy-content-collections for more information on migrating from legacy collections.',
1707+
} satisfies ErrorData;
1708+
16731709
/**
16741710
* @docs
16751711
* @message

packages/astro/templates/content/module.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export const getLiveEntry = createGetLiveEntry({
3838
liveCollections,
3939
});
4040

41+
// TODO: remove in Astro 7
4142
export const getEntryBySlug = createDeprecatedFunction('getEntryBySlug');
4243

44+
// TODO: remove in Astro 7
4345
export const getDataEntryById = createDeprecatedFunction('getDataEntryById');

0 commit comments

Comments
 (0)