Skip to content

Commit

Permalink
fix(runtime): preserve error.stack instead of throwing new error (mod…
Browse files Browse the repository at this point in the history
  • Loading branch information
2heal1 authored Mar 6, 2024
1 parent 3a45d99 commit 6e9b6d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/warm-berries-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/runtime': patch
---

fix(runtime): preserve error.stack instead of throwing new error
11 changes: 10 additions & 1 deletion packages/runtime/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ export function assert(condition: any, msg: string): asserts condition {
}

export function error(msg: string | Error | unknown): never {
if (msg instanceof Error) {
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
throw msg;
}
throw new Error(`${LOG_CATEGORY}: ${msg}`);
}

export function warn(msg: Parameters<typeof console.warn>[0]): void {
console.warn(`${LOG_CATEGORY}: ${msg}`);
if (msg instanceof Error) {
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
console.warn(msg);
} else {
console.warn(`${LOG_CATEGORY}: ${msg}`);
}
}

0 comments on commit 6e9b6d5

Please sign in to comment.