comlink icon indicating copy to clipboard operation
comlink copied to clipboard

Use `serialize-error` for error serialization

Open safareli opened this issue 3 years ago • 4 comments

If you are using custom error classes with custom properties or even more or less standard cause then you would loose some data here: https://github.com/GoogleChromeLabs/comlink/blob/4ba8162f6c28fb1bf53b491565ef9a3ae42b72d3/src/comlink.ts#L249-L256

Instead I'm proposing to use serialize-error that works better then what we have currently.

I can create PR if this is approved.

Meanwhile you can do this as a workaround

safareli avatar Jun 20 '22 14:06 safareli

Given the workaround is sufficient here, and adding the serialization would for most folks be unnecessary additional payload do you think this is actually worth adding to the library, or should we just document the workaround for those folk that need it?

benjamind avatar Jan 24 '23 22:01 benjamind

The workaround depends on internal api and needs unsafe type casts. it would be nice to just use serialize-error but if adding dependency is a problem then making API of swapping out transferHandlers in a nicer way would be one option.

Maybe some sort of plugin api could be implemented here. and there would be a plugin that uses serialize-error for errors

safareli avatar Jan 25 '23 09:01 safareli

I guess I missed the usage of an internal api, which part uses that?

If you want to put up a PR to use serialize-error so we can compare payload impact that'd be the best path forward here. Besides that I think we would need more indication of this being a consistent problem for users to determine if its worth addng the additional payload for this.

benjamind avatar Jan 25 '23 17:01 benjamind