Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show file name with invalid frontmatter errors for MDX #12355

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-bulldogs-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Improves error reporting for invalid frontmatter in MDX files during the `astro build` command. The error message now includes the file path where the frontmatter parsing failed.
6 changes: 4 additions & 2 deletions packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
AstroUserError,
createSafeError,
isAstroError,
type ErrorWithMetadata,
} from '../errors/index.js';
import type { Logger } from '../logger/core.js';
import { formatErrorMessage } from '../messages.js';
Expand Down Expand Up @@ -223,7 +224,7 @@ async function syncContentCollections(
}
}
} catch (e) {
const safeError = createSafeError(e);
const safeError = createSafeError(e) as ErrorWithMetadata;
if (isAstroError(e)) {
throw e;
}
Expand All @@ -232,7 +233,8 @@ async function syncContentCollections(
{
...AstroErrorData.GenerateContentTypesError,
hint,
message: AstroErrorData.GenerateContentTypesError.message(safeError.message),
message: AstroErrorData.GenerateContentTypesError.message(`${safeError.message}`),
bluwy marked this conversation as resolved.
Show resolved Hide resolved
location: safeError.loc,
},
{ cause: e },
);
Expand Down
Loading