Skip to content

Commit d812ba2

Browse files
authored
fix: error stack is empty (#2716)
1 parent 0a3cca7 commit d812ba2

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/core/src/node/mdx/loader.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,23 @@ export default async function mdxLoader(
5454
} catch (e) {
5555
if (e instanceof Error) {
5656
// Enhance the message with filepath context for better error reporting
57-
e.message = `MDX compile error: ${e.message} in ${filepath}`;
57+
const message = `MDX compile error: ${e.message} in ${filepath}`;
58+
let stack: string | undefined = e.stack;
5859
// Truncate stack trace to first 10 lines for better readability
59-
if (e.stack) {
60-
const stackLines = e.stack.split('\n');
60+
if (stack) {
61+
const stackLines = stack.split('\n');
6162
if (stackLines.length > 10) {
62-
e.stack =
63-
stackLines.slice(0, 10).join('\n') + '\n ... (truncated)';
63+
stack = stackLines.slice(0, 10).join('\n') + '\n ... (truncated)';
6464
}
6565
}
66-
callback(e);
66+
// why not `callback(e)` ?
67+
// https://github.com/web-infra-dev/rspack/issues/12080
68+
callback({
69+
message,
70+
...(stack ? { stack } : {}),
71+
name: e.name,
72+
cause: e.cause,
73+
} as Error);
6774
}
6875
}
6976
}

0 commit comments

Comments
 (0)