Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced Error support #294

Open
shortercode opened this issue Sep 4, 2024 · 2 comments
Open

Advanced Error support #294

shortercode opened this issue Sep 4, 2024 · 2 comments

Comments

@shortercode
Copy link

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
Copy link
Collaborator

Skn0tt commented Sep 4, 2024

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

@Mansi1
Copy link

Mansi1 commented Oct 4, 2024

try out my implementation example @jsheaven/tjson https://github.com/jsheaven/tjson

 const TypedJSON = new TJSON().registerError()
    class CustomError extends Error {
      constructor(message: string, public test: string, public num: number) {
        super(message)
      }
    }
    const input = new CustomError('error', 'test', NaN)
    const tjson = TypedJSON.stringify(input)
    //{"content":{"name":"Error","message":"error","stack":"stack","test":"test","num":"NaN"},"type":{"":"js:error","num":"js:number:nan"}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants