flightcontrolhq / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
https://www.flightcontrol.dev?ref=superjson
MIT License
4.01k stars 87 forks source link

Advanced Error support #294

Open shortercode opened 1 week ago

shortercode commented 1 week ago

First off this is a great library, has been a huge help for working with electron-trpc. One thing I noticed recently was that when we pass Error objects through the cause field is removed ( MDN Error: cause ). We use this quite a lot to add extra context. I found #91 which explained why, but that was in the context of stack, code, etc.

I've logged a ticket for our app to use the allowErrorProps to fix our issue but I wondered if you would consider adding support for cause out of the box. Additionally adding support for MDN AggregateError would be great as well.

const original = new Error('Network request failed')
const chained = new Error('Unable to get articles', { cause: original })

console.log(chained.cause)
const copy = deserialize(serialize({ chained }))
console.log(copy.chained.cause)
Skn0tt commented 1 week ago

cause should be safe to add. This is a great request! Feel free to open a pull request and I'll review it.