fix: MDX errors not having stack trace and a confusing name (#8438)

* fix(mdx): Fix errors having weird names and no stack trace

* chore: changeset
This commit is contained in:
Erika 2023-09-06 20:36:50 +02:00 committed by GitHub
parent eb7615f25a
commit 6df4f3bd9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/mdx': patch
---
Fix errors not having a stacktrace

View file

@ -153,7 +153,14 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
};
} catch (e: any) {
const err: SSRError = e;
// For some reason MDX puts the error location in the error's name, not very useful for us.
err.name = 'MDXError';
err.loc = { file: fileId, line: e.line, column: e.column };
// For another some reason, MDX doesn't include a stack trace. Weird
Error.captureStackTrace(err);
throw err;
}
},