In UI process, I want to catch custom Error throw in Webworker with comlink.
The custom Error is extended Error, so comlink serialize/deserialize to Error not to custom Error.
serialize
if (value instanceof Error) {
serialized = {
isError: true,
value: {
message: value.message,
name: value.name,
stack: value.stack,
},
};
}
deserialize
if (serialized.isError) {
throw Object.assign(
new Error(serialized.value.message),
serialized.value
);
}
I tried to customize throwTransferHandler to throw custom Error, but It did not work. Because throwMarker is unique Symbol and not exported.
canHandle: (value): value is ThrownValue =>
isObject(value) && throwMarker in value,