From 9a300dae6e843a39f3d6bd7f976f4a960b088f2e Mon Sep 17 00:00:00 2001 From: liruifengv Date: Thu, 6 Jun 2024 17:46:32 +0800 Subject: [PATCH 1/3] fix: throw original AstroUserError in mdx --- packages/astro/src/jsx/server.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/astro/src/jsx/server.ts b/packages/astro/src/jsx/server.ts index 2ed308c37e82..be55b0194b21 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, From e894bee6f135b1de2f3764957caaaa4209acdc6e Mon Sep 17 00:00:00 2001 From: liruifengv Date: Thu, 6 Jun 2024 17:47:13 +0800 Subject: [PATCH 2/3] add changeset --- .changeset/brave-pots-listen.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/brave-pots-listen.md diff --git a/.changeset/brave-pots-listen.md b/.changeset/brave-pots-listen.md new file mode 100644 index 000000000000..577a442f9c22 --- /dev/null +++ b/.changeset/brave-pots-listen.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +throw original AstroUserError in mdx From de5e0d7bb9da1f1d9bff970a9d5e123d3ff07aaf Mon Sep 17 00:00:00 2001 From: liruifengv Date: Thu, 6 Jun 2024 18:44:36 +0800 Subject: [PATCH 3/3] Update brave-pots-listen.md Co-authored-by: Emanuele Stoppa --- .changeset/brave-pots-listen.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/brave-pots-listen.md b/.changeset/brave-pots-listen.md index 577a442f9c22..bc6d589636bc 100644 --- a/.changeset/brave-pots-listen.md +++ b/.changeset/brave-pots-listen.md @@ -2,4 +2,4 @@ "astro": patch --- -throw original AstroUserError in mdx +Improves DX by throwing the original `AstroUserError` when an error is thrown inside a `.mdx` file.