0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Fix throw AstroUserError in mdx (#11192)

* fix: throw original AstroUserError in mdx

* add changeset

* Update brave-pots-listen.md

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

---------

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
This commit is contained in:
liruifengv 2024-06-06 19:33:49 +08:00 committed by GitHub
parent 4ad1ce24e1
commit 58b10a0731
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Improves DX by throwing the original `AstroUserError` when an error is thrown inside a `.mdx` file.

View file

@ -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';
@ -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,