Skip to content

Conversation

@matthewp
Copy link
Contributor

@matthewp matthewp commented Feb 2, 2026

Changes

  • When a file has a closing frontmatter fence (---) without an opening fence, the parser would panic with originalIM was set twice
  • This change detects that invalid state in inBodyIM and returns a helpful diagnostic error instead of panicking
  • Added new error code ERROR_MISSING_FRONTMATTER_FENCE (1006)
  • The error message includes a hint telling users to add --- at the beginning of their file

Fixes #1133
Fixes #1038
Fixes #1094
Fixes #1107

Testing

Added test case in packages/compiler/test/errors/missing-frontmatter-fence.ts that verifies:

  • The compiler no longer panics
  • A diagnostic with code 1006 is returned
  • The error text and hint are correct

Docs

Bug fix only - no documentation changes needed.

When a file has a closing frontmatter fence (---) without an opening fence,
the parser would panic with 'originalIM was set twice'. This change detects
that condition and returns a helpful diagnostic error instead.

Fixes #1133, #1038. May also help with #1094, #1107.
@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2026

🦋 Changeset detected

Latest commit: 9dbe356

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/compiler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines +1112 to +1115
Range: loc.Range{
Loc: p.tok.Loc,
Len: 3,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have snapshot tests so that we can verify that the range is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a way to do snapshots of errors, so instead I added an assertion to the test I created here: 9dbe356

@matthewp matthewp merged commit 357b8fe into main Feb 3, 2026
5 checks passed
@matthewp matthewp deleted the fix/issue-1133 branch February 3, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants