-
Notifications
You must be signed in to change notification settings - Fork 45
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
"An object could not be cloned" when promise is rejected with an error #44
Comments
- See #44 - Specifically pass message/stack and then catch on the other side
Thanks for reporting this. I'm not sure which is the best route to take here. Please see #45 and let me know if this fixes your case / and if you think that's a generally fair approach. |
I think that approach probably makes some sense. I'm wondering if it would be beneficial to also transfer the
Of course, we could wind up down a rabbit trail where we are building an ever-increasing list of things that we need to transfer. An alternative approach would be to simply pass back a JSON-encoded version of the error object. This will catch any attributes/structures that can be represented in JSON, which should be pretty much anything of value. (Usually we don't try to intentionally pass functions on Error objects.) |
Just released 0.4.6 which manually clones over any props on native Error objs. Hope that solves your use-case. See specs here: operative/test/operative.spec.js Lines 110 to 142 in b1353cb
(Thanks for reporting this, once again!) |
It's considered a best practice to only reject promises with an
Error
(or derived object). Unfortunately, this breaks operative as errors can't be cloned. This results in an uncaught error within operative'sreturnResult
in the context of the web worker, leaving the primary thread hanging waiting for a response that will never arrive.I believe that operative should handle this case somehow. If the error can't be cloned via
postMessage
then we need to do something to tell the main thread that the operation failed -- either transfer the error object using JSON (which can serialize errors, albeit without their functions/prototype) or some other kind of operative-specific error that wraps a structured-cloning-compatible version of the rejection error.As it stands right now, operative's promise interop is all but useless since it is completely unable to proxy rejections back to the main thread.
The text was updated successfully, but these errors were encountered: