Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AstroError if content directory is empty #8382

Merged
merged 6 commits into from
Sep 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use logger instead of zod error
  • Loading branch information
DerTimonius committed Sep 14, 2023
commit e26a89f3f46dab0534cd90c148efbdc096025be4
21 changes: 15 additions & 6 deletions packages/astro/src/content/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type AstroComponentFactory,
} from '../runtime/server/index.js';
import type { ContentLookupMap } from './utils.js';
import type { AstroIntegration } from '../@types/astro.js';

type LazyImport = () => Promise<any>;
type GlobResult = Record<string, LazyImport>;
Expand Down Expand Up @@ -55,12 +56,7 @@ export function createGetCollection({
} else if (collection in dataCollectionToEntryMap) {
type = 'data';
} else {
return zodString().transform((_, ctx) => {
ctx.addIssue({
code: ZodIssueCode.custom,
message: `The collection **${collection}** does not exist. Ensure a collection directory with this name exists.`,
});
});
return warnOfEmptyCollection(collection)
}
const lazyImports = Object.values(
type === 'content'
Expand Down Expand Up @@ -394,3 +390,16 @@ 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.`
);
},
},
};
}