summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar liruifengv <liruifeng1024@gmail.com> 2024-06-06 19:33:49 +0800
committerGravatar GitHub <noreply@github.com> 2024-06-06 12:33:49 +0100
commit58b10a073192030a251cff8ad706ab5b015180c9 (patch)
tree0ba4b3f477c075186d729d61cba6608d5cd46d02
parent4ad1ce24e1306a8330fb6f77c8b13394704e1fef (diff)
downloadastro-58b10a073192030a251cff8ad706ab5b015180c9.tar.gz
astro-58b10a073192030a251cff8ad706ab5b015180c9.tar.zst
astro-58b10a073192030a251cff8ad706ab5b015180c9.zip
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>
-rw-r--r--.changeset/brave-pots-listen.md5
-rw-r--r--packages/astro/src/jsx/server.ts4
2 files changed, 8 insertions, 1 deletions
diff --git a/.changeset/brave-pots-listen.md b/.changeset/brave-pots-listen.md
new file mode 100644
index 000000000..bc6d58963
--- /dev/null
+++ b/.changeset/brave-pots-listen.md
@@ -0,0 +1,5 @@
+---
+"astro": patch
+---
+
+Improves DX by throwing the original `AstroUserError` when an error is thrown inside a `.mdx` file.
diff --git a/packages/astro/src/jsx/server.ts b/packages/astro/src/jsx/server.ts
index 2ed308c37..be55b0194 100644
--- a/packages/astro/src/jsx/server.ts
+++ b/packages/astro/src/jsx/server.ts
@@ -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,