Skip to content

Commit

Permalink
Show the actual error when there was an error while generating types (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh authored Apr 5, 2023
1 parent b96a129 commit 8b88e4c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-lizards-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Improved error message when an error was encountered while generating types
3 changes: 2 additions & 1 deletion packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
},
/**
Expand Down
11 changes: 9 additions & 2 deletions packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

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

0 comments on commit 8b88e4c

Please sign in to comment.