Skip to content

Commit

Permalink
fix(astro): handle AstroUserError during sync and exports types (#10955)
Browse files Browse the repository at this point in the history
Co-authored-by: Luiz Ferraz <luiz@lferraz.com>
  • Loading branch information
florian-lefebvre and Fryuni committed May 6, 2024
1 parent 4efe519 commit 2978287
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-peaches-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Handles `AstroUserError`s thrown while syncing content collections and exports `BaseSchema` and `CollectionConfig` types
4 changes: 3 additions & 1 deletion packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/types/content.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

Expand All @@ -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>;

Expand Down

0 comments on commit 2978287

Please sign in to comment.