Skip to content

Commit e6cd117

Browse files
committed
include cause property in communicated error fields
1 parent 082b625 commit e6cd117

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/comlink.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ const throwTransferHandler: TransferHandler<
256256
message: value.message,
257257
name: value.name,
258258
stack: value.stack,
259+
cause: value.cause,
259260
},
260261
};
261262
} else {

tests/same_window.comlink.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ describe("Comlink in the same realm", function () {
9898
expect(await thing.x).to.be.undefined;
9999
});
100100

101-
it("can keep the stack and message of thrown errors", async function () {
101+
it("can keep the stack, message and cause of thrown errors", async function () {
102102
let stack;
103103
const thing = Comlink.wrap(this.port1);
104104
Comlink.expose((_) => {
105-
const error = Error("OMG");
105+
const error = Error("OMG", { cause: "the cause" });
106106
stack = error.stack;
107107
throw error;
108108
}, this.port2);
@@ -113,6 +113,7 @@ describe("Comlink in the same realm", function () {
113113
expect(err).to.not.eq("Should have thrown");
114114
expect(err.message).to.equal("OMG");
115115
expect(err.stack).to.equal(stack);
116+
expect(err.cause).to.equal("the cause");
116117
}
117118
});
118119

0 commit comments

Comments
 (0)