Show the actual error when there was an error while generating types (#6762)

This commit is contained in:
Erika 2023-04-05 17:12:35 +02:00 committed by GitHub
parent b96a129581
commit 8b88e4cf15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Improved error message when an error was encountered while generating types

View file

@ -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.',
},
/**

View file

@ -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();
}