Skip to content

Commit 6e9b6d5

Browse files
authored
fix(runtime): preserve error.stack instead of throwing new error (#2153)
1 parent 3a45d99 commit 6e9b6d5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

.changeset/warm-berries-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/runtime': patch
3+
---
4+
5+
fix(runtime): preserve error.stack instead of throwing new error

packages/runtime/src/utils/logger.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@ export function assert(condition: any, msg: string): asserts condition {
88
}
99

1010
export function error(msg: string | Error | unknown): never {
11+
if (msg instanceof Error) {
12+
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
13+
throw msg;
14+
}
1115
throw new Error(`${LOG_CATEGORY}: ${msg}`);
1216
}
1317

1418
export function warn(msg: Parameters<typeof console.warn>[0]): void {
15-
console.warn(`${LOG_CATEGORY}: ${msg}`);
19+
if (msg instanceof Error) {
20+
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
21+
console.warn(msg);
22+
} else {
23+
console.warn(`${LOG_CATEGORY}: ${msg}`);
24+
}
1625
}

0 commit comments

Comments
 (0)