0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

fix(astro): handle AstroUserError during sync and exports types (#10955)

Co-authored-by: Luiz Ferraz <luiz@lferraz.com>
This commit is contained in:
Florian Lefebvre 2024-05-06 17:35:17 +02:00 committed by GitHub
parent 4efe519456
commit 2978287f92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Handles `AstroUserError`s thrown while syncing content collections and exports `BaseSchema` and `CollectionConfig` types

View file

@ -17,7 +17,7 @@ import { createNodeLogger } from '../config/logging.js';
import { createSettings } from '../config/settings.js';
import { createVite } from '../create-vite.js';
import { collectErrorMetadata } from '../errors/dev/utils.js';
import { AstroError, AstroErrorData, createSafeError, isAstroError } from '../errors/index.js';
import { AstroError, AstroErrorData, AstroUserError, createSafeError, isAstroError } from '../errors/index.js';
import type { Logger } from '../logger/core.js';
import { formatErrorMessage } from '../messages.js';
import { ensureProcessNodeEnv } from '../util.js';
@ -159,9 +159,11 @@ export async function syncContentCollections(
if (isAstroError(e)) {
throw e;
}
const hint = AstroUserError.is(e) ? e.hint : AstroErrorData.GenerateContentTypesError.hint;
throw new AstroError(
{
...AstroErrorData.GenerateContentTypesError,
hint,
message: AstroErrorData.GenerateContentTypesError.message(safeError.message),
},
{ cause: e }

View file

@ -26,7 +26,7 @@ declare module 'astro:content' {
| import('astro/zod').ZodDiscriminatedUnion<string, import('astro/zod').AnyZodObject[]>
| import('astro/zod').ZodIntersection<BaseSchemaWithoutEffects, BaseSchemaWithoutEffects>;
type BaseSchema =
export type BaseSchema =
| BaseSchemaWithoutEffects
| import('astro/zod').ZodEffects<BaseSchemaWithoutEffects>;
@ -42,7 +42,7 @@ declare module 'astro:content' {
schema?: S | ((context: SchemaContext) => S);
};
type CollectionConfig<S extends BaseSchema> =
export type CollectionConfig<S extends BaseSchema> =
| ContentCollectionConfig<S>
| DataCollectionConfig<S>;