Turning an unknown thrown value into something readable.
catch (error) gives unknown, and the two obvious things to do with it are
both incomplete in the same place: String(error) on an Error yields
"Error: msg" but on a DOMException loses the name, while directly using
JSON.stringify on an Error yields "{}" because name / message /
stack are all non-enumerable.
That second one is not hypothetical — it is why a real bug report read
OPFSStore metadata save failed {} with the cause entirely absent.
The idiom was inlined ~31 times and file-private in a 32nd
(data/points/points-spatial-index-loader.ts); this is that helper promoted
so the console formatters and any log site can share one definition.
Turning an unknown thrown value into something readable.
catch (error)givesunknown, and the two obvious things to do with it are both incomplete in the same place:String(error)on anErroryields"Error: msg"but on aDOMExceptionloses the name, while directly usingJSON.stringifyon an Error yields"{}"becausename/message/stackare all non-enumerable. That second one is not hypothetical — it is why a real bug report readOPFSStore metadata save failed {}with the cause entirely absent.The idiom was inlined ~31 times and file-private in a 32nd (
data/points/points-spatial-index-loader.ts); this is that helper promoted so the console formatters and any log site can share one definition.