Description
What is the issue with the HTML Standard?
In step 17 of StructuredSerializeInternal it's mentioned that, beside type
, message
and name
(not super useful for developers):
User agents should attach a serialized representation of any interesting accompanying data which are not yet specified, notably the stack property, to serialized
Now, the base Error class has only 2 fields: message
and cause.
The MDN description for cause
is:
It is used when catching and re-throwing an error with a more-specific or useful error message in order to still have access to the original error.
Accordingly, you can imagine my disappointment when I've realized that while Chrome/ium and Firefox clone that field too, WebKit doesn't clone it and it's impossible to attach relevant Error details to anything that is going to be forwarded via postMessage(thatError)
.
The test is pretty simple:
console.assert(
structuredClone(
new Error('reason', { cause: 123 })
).cause === 123
);
This fails in WebKit but it looks to me that field must be forwarded for cross platform, cross browser, and cross realm compatibility sake, so that having it unspecified as MUST like it is for message
, type
and name
feels like a bug/hazard when better error messages, propagation or handling, is desired in any program that works on the main or any other worker based thread.
/cc @rniwa here because both WebKit and Bun (or anything JSC based) is making it impossible for us to provide better errors when WASM non-blocking code generates errors within Workers (Service, Shared, or regular).
Thanks in advance for considering a fix to this part, it's the only field that currently gives developers any extra power to attach more to errors and having it unusable due lack of cross engine compatibilities feels like a huge mistake/limitation.