Skip to content

Commit

Permalink
fix: MDX errors not having stack trace and a confusing name (#8438)
Browse files Browse the repository at this point in the history
* fix(mdx): Fix errors having weird names and no stack trace

* chore: changeset
  • Loading branch information
Princesseuh committed Sep 6, 2023
1 parent eb7615f commit 6df4f3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-deers-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/mdx': patch
---

Fix errors not having a stacktrace
7 changes: 7 additions & 0 deletions packages/integrations/mdx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
},
Expand Down

0 comments on commit 6df4f3b

Please sign in to comment.