Warn on empty content collections (#8640)
* Warn on empty content collections * Update packages/astro/src/core/errors/errors-data.ts Co-authored-by: Reuben Tier <64310361+TheOtterlord@users.noreply.github.com> --------- Co-authored-by: Reuben Tier <64310361+TheOtterlord@users.noreply.github.com>
This commit is contained in:
parent
974d5117ab
commit
f36c4295be
3 changed files with 9 additions and 15 deletions
5
.changeset/spotty-jokes-arrive.md
Normal file
5
.changeset/spotty-jokes-arrive.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Warn on empty content collections
|
|
@ -1,6 +1,5 @@
|
|||
import type { MarkdownHeading } from '@astrojs/markdown-remark';
|
||||
import { ZodIssueCode, string as zodString } from 'zod';
|
||||
import type { AstroIntegration } from '../@types/astro.js';
|
||||
import { AstroError, AstroErrorData } from '../core/errors/index.js';
|
||||
import { prependForwardSlash } from '../core/path.js';
|
||||
import {
|
||||
|
@ -56,7 +55,9 @@ export function createGetCollection({
|
|||
} else if (collection in dataCollectionToEntryMap) {
|
||||
type = 'data';
|
||||
} else {
|
||||
return warnOfEmptyCollection(collection);
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(`The collection **${collection}** does not exist or is empty. Ensure a collection directory with this name exists.`);
|
||||
return;
|
||||
}
|
||||
const lazyImports = Object.values(
|
||||
type === 'content'
|
||||
|
@ -390,16 +391,3 @@ type PropagatedAssetsModule = {
|
|||
function isPropagatedAssetsModule(module: any): module is PropagatedAssetsModule {
|
||||
return typeof module === 'object' && module != null && '__astroPropagation' in module;
|
||||
}
|
||||
|
||||
function warnOfEmptyCollection(collection: string): AstroIntegration {
|
||||
return {
|
||||
name: 'astro-collection',
|
||||
hooks: {
|
||||
'astro:server:start': ({ logger }) => {
|
||||
logger.warn(
|
||||
`The collection **${collection}** does not exist or is empty. Ensure a collection directory with this name exists.`
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1158,6 +1158,7 @@ export const ContentSchemaContainsSlugError = {
|
|||
/**
|
||||
* @docs
|
||||
* @message A collection queried via `getCollection()` does not exist.
|
||||
* @deprecated Collections that do not exist no longer result in an error. A warning is omitted instead.
|
||||
* @description
|
||||
* When querying a collection, ensure a collection directory with the requested name exists under `src/content/`.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue