Skip to content

Commit

Permalink
refactor: create error data entry
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Jun 8, 2023
1 parent 1320649 commit 32219eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/astro/src/content/vite-plugin-content-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,8 @@ function stringifyEntryData(data: Record<string, any>): 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 {
Expand Down
15 changes: 15 additions & 0 deletions packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down

0 comments on commit 32219eb

Please sign in to comment.