Skip to content

Commit

Permalink
Fix throw AstroUserError in mdx (#11192)
Browse files Browse the repository at this point in the history
* fix: throw original AstroUserError in mdx

* add changeset

* Update brave-pots-listen.md

Co-authored-by: Emanuele Stoppa <[email protected]>

---------

Co-authored-by: Emanuele Stoppa <[email protected]>
  • Loading branch information
liruifengv and ematipico authored Jun 6, 2024
1 parent 4ad1ce2 commit 58b10a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/brave-pots-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Improves DX by throwing the original `AstroUserError` when an error is thrown inside a `.mdx` file.
4 changes: 3 additions & 1 deletion packages/astro/src/jsx/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AstroError } from '../core/errors/errors.js';
import { AstroError, AstroUserError } from '../core/errors/errors.js';
import { AstroJSX, jsx } from '../jsx-runtime/index.js';
import { renderJSX } from '../runtime/server/jsx.js';

Expand Down Expand Up @@ -52,6 +52,8 @@ function throwEnhancedErrorIfMdxComponent(error: Error, Component: any) {
// if the exception is from an mdx component
// throw an error
if (Component[Symbol.for('mdx-component')]) {
// if it's an AstroUserError, we don't need to re-throw, keep the original hint
if (AstroUserError.is(error)) return;
throw new AstroError({
message: error.message,
title: error.name,
Expand Down

0 comments on commit 58b10a0

Please sign in to comment.