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:
parent
4efe519456
commit
2978287f92
3 changed files with 10 additions and 3 deletions
5
.changeset/strong-peaches-learn.md
Normal file
5
.changeset/strong-peaches-learn.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"astro": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Handles `AstroUserError`s thrown while syncing content collections and exports `BaseSchema` and `CollectionConfig` types
|
|
@ -17,7 +17,7 @@ import { createNodeLogger } from '../config/logging.js';
|
||||||
import { createSettings } from '../config/settings.js';
|
import { createSettings } from '../config/settings.js';
|
||||||
import { createVite } from '../create-vite.js';
|
import { createVite } from '../create-vite.js';
|
||||||
import { collectErrorMetadata } from '../errors/dev/utils.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 type { Logger } from '../logger/core.js';
|
||||||
import { formatErrorMessage } from '../messages.js';
|
import { formatErrorMessage } from '../messages.js';
|
||||||
import { ensureProcessNodeEnv } from '../util.js';
|
import { ensureProcessNodeEnv } from '../util.js';
|
||||||
|
@ -159,9 +159,11 @@ export async function syncContentCollections(
|
||||||
if (isAstroError(e)) {
|
if (isAstroError(e)) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
const hint = AstroUserError.is(e) ? e.hint : AstroErrorData.GenerateContentTypesError.hint;
|
||||||
throw new AstroError(
|
throw new AstroError(
|
||||||
{
|
{
|
||||||
...AstroErrorData.GenerateContentTypesError,
|
...AstroErrorData.GenerateContentTypesError,
|
||||||
|
hint,
|
||||||
message: AstroErrorData.GenerateContentTypesError.message(safeError.message),
|
message: AstroErrorData.GenerateContentTypesError.message(safeError.message),
|
||||||
},
|
},
|
||||||
{ cause: e }
|
{ cause: e }
|
||||||
|
|
4
packages/astro/types/content.d.ts
vendored
4
packages/astro/types/content.d.ts
vendored
|
@ -26,7 +26,7 @@ declare module 'astro:content' {
|
||||||
| import('astro/zod').ZodDiscriminatedUnion<string, import('astro/zod').AnyZodObject[]>
|
| import('astro/zod').ZodDiscriminatedUnion<string, import('astro/zod').AnyZodObject[]>
|
||||||
| import('astro/zod').ZodIntersection<BaseSchemaWithoutEffects, BaseSchemaWithoutEffects>;
|
| import('astro/zod').ZodIntersection<BaseSchemaWithoutEffects, BaseSchemaWithoutEffects>;
|
||||||
|
|
||||||
type BaseSchema =
|
export type BaseSchema =
|
||||||
| BaseSchemaWithoutEffects
|
| BaseSchemaWithoutEffects
|
||||||
| import('astro/zod').ZodEffects<BaseSchemaWithoutEffects>;
|
| import('astro/zod').ZodEffects<BaseSchemaWithoutEffects>;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ declare module 'astro:content' {
|
||||||
schema?: S | ((context: SchemaContext) => S);
|
schema?: S | ((context: SchemaContext) => S);
|
||||||
};
|
};
|
||||||
|
|
||||||
type CollectionConfig<S extends BaseSchema> =
|
export type CollectionConfig<S extends BaseSchema> =
|
||||||
| ContentCollectionConfig<S>
|
| ContentCollectionConfig<S>
|
||||||
| DataCollectionConfig<S>;
|
| DataCollectionConfig<S>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue