From 8b88e4cf15c8bea7942b3985380164e0edf7250b Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Wed, 5 Apr 2023 17:12:35 +0200 Subject: [PATCH] Show the actual error when there was an error while generating types (#6762) --- .changeset/metal-lizards-arrive.md | 5 +++++ packages/astro/src/core/errors/errors-data.ts | 3 ++- packages/astro/src/core/sync/index.ts | 11 +++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .changeset/metal-lizards-arrive.md diff --git a/.changeset/metal-lizards-arrive.md b/.changeset/metal-lizards-arrive.md new file mode 100644 index 000000000000..aa3f6c10f6e2 --- /dev/null +++ b/.changeset/metal-lizards-arrive.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Improved error message when an error was encountered while generating types diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index c5a3b7fad919..bb9a8650666e 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -828,7 +828,8 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati GenerateContentTypesError: { title: 'Failed to generate content types.', code: 8001, - message: '`astro sync` command failed to generate content collection types.', + message: (errorMessage: string) => + `\`astro sync\` command failed to generate content collection types: ${errorMessage}`, hint: 'Check your `src/content/config.*` file for typos.', }, /** diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index 77dcccde22f6..ba55a22002a5 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -10,7 +10,7 @@ import { runHookConfigSetup } from '../../integrations/index.js'; import { setUpEnvTs } from '../../vite-plugin-inject-env-ts/index.js'; import { getTimeStat } from '../build/util.js'; import { createVite } from '../create-vite.js'; -import { AstroError, AstroErrorData } from '../errors/index.js'; +import { AstroError, AstroErrorData, createSafeError } from '../errors/index.js'; import { info, type LogOptions } from '../logger/core.js'; import { printHelp } from '../messages.js'; @@ -98,7 +98,14 @@ export async function sync( } } } catch (e) { - throw new AstroError(AstroErrorData.GenerateContentTypesError); + const safeError = createSafeError(e); + throw new AstroError( + { + ...AstroErrorData.GenerateContentTypesError, + message: AstroErrorData.GenerateContentTypesError.message(safeError.message), + }, + { cause: e } + ); } finally { await tempViteServer.close(); }