From 2978287f92dbd135f5c3efc6a037ea1756064d35 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Mon, 6 May 2024 17:35:17 +0200 Subject: [PATCH] fix(astro): handle AstroUserError during sync and exports types (#10955) Co-authored-by: Luiz Ferraz --- .changeset/strong-peaches-learn.md | 5 +++++ packages/astro/src/core/sync/index.ts | 4 +++- packages/astro/types/content.d.ts | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changeset/strong-peaches-learn.md diff --git a/.changeset/strong-peaches-learn.md b/.changeset/strong-peaches-learn.md new file mode 100644 index 0000000000..263746d6be --- /dev/null +++ b/.changeset/strong-peaches-learn.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Handles `AstroUserError`s thrown while syncing content collections and exports `BaseSchema` and `CollectionConfig` types diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index a5763b68f3..b5cfc945b7 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -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 } diff --git a/packages/astro/types/content.d.ts b/packages/astro/types/content.d.ts index 45f0d4af79..e09bda6184 100644 --- a/packages/astro/types/content.d.ts +++ b/packages/astro/types/content.d.ts @@ -26,7 +26,7 @@ declare module 'astro:content' { | import('astro/zod').ZodDiscriminatedUnion | import('astro/zod').ZodIntersection; - type BaseSchema = + export type BaseSchema = | BaseSchemaWithoutEffects | import('astro/zod').ZodEffects; @@ -42,7 +42,7 @@ declare module 'astro:content' { schema?: S | ((context: SchemaContext) => S); }; - type CollectionConfig = + export type CollectionConfig = | ContentCollectionConfig | DataCollectionConfig;