From 58b10a073192030a251cff8ad706ab5b015180c9 Mon Sep 17 00:00:00 2001 From: liruifengv Date: Thu, 6 Jun 2024 19:33:49 +0800 Subject: [PATCH] Fix throw `AstroUserError` in mdx (#11192) * fix: throw original AstroUserError in mdx * add changeset * Update brave-pots-listen.md Co-authored-by: Emanuele Stoppa --------- Co-authored-by: Emanuele Stoppa --- .changeset/brave-pots-listen.md | 5 +++++ packages/astro/src/jsx/server.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) 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..bc6d589636bc --- /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 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,