From 32219eb5bc5d5fe54bcc12ef212204b301861c68 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 8 Jun 2023 13:37:42 -0400 Subject: [PATCH] refactor: create error data entry --- .../src/content/vite-plugin-content-imports.ts | 6 ++---- packages/astro/src/core/errors/errors-data.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/astro/src/content/vite-plugin-content-imports.ts b/packages/astro/src/content/vite-plugin-content-imports.ts index 6bc50512be98c..aa2fec1797a56 100644 --- a/packages/astro/src/content/vite-plugin-content-imports.ts +++ b/packages/astro/src/content/vite-plugin-content-imports.ts @@ -365,10 +365,8 @@ function stringifyEntryData(data: Record): string { } catch (e) { if (e instanceof Error) { throw new AstroError({ - code: 99999, - title: 'Invalid Zod transform()', - message: `\`transform()\` functions in your content config must return valid JSON, or data types compatible with the devalue library (including Dates, Maps, and Sets).\nFull error: ${e.message}`, - hint: 'See the Devalue library for all supported types: https://github.com/rich-harris/devalue', + ...AstroErrorData.UnsupportedConfigTransformError, + message: AstroErrorData.UnsupportedConfigTransformError.message(e.message), stack: e.stack, }); } else { diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index 0425eb22e0602..17a5db4fef567 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -1113,6 +1113,21 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati hint: 'Ensure your data entry is an object with valid JSON (for `.json` entries) or YAML (for `.yaml` entries).', }, + /** + * @docs + * @see + * - [devalue library](https://github.com/rich-harris/devalue) + * @description + * `transform()` functions in your content config must return valid JSON, or data types compatible with the devalue library (including Dates, Maps, and Sets). + */ + UnsupportedConfigTransformError: { + title: 'Unsupported transform in content config.', + code: 9008, + message: (parseError: string) => + `\`transform()\` functions in your content config must return valid JSON, or data types compatible with the devalue library (including Dates, Maps, and Sets).\nFull error: ${parseError}`, + hint: 'See the devalue library for all supported types: https://github.com/rich-harris/devalue', + }, + // Generic catch-all - Only use this in extreme cases, like if there was a cosmic ray bit flip UnknownError: { title: 'Unknown Error.',