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

How to return an error from a child #9

Closed
ryandesign opened this issue Jun 27, 2013 · 5 comments
Closed

How to return an error from a child #9

ryandesign opened this issue Jun 27, 2013 · 5 comments

Comments

@ryandesign
Copy link

Could you add an example showing how to return an error from a child? I'm trying to call the callback function with a new Error('...') object in the first parameter as usual, but although the master process recognizes that there's something in err, it appears to be an empty object, so I can't get any details about the error that occurred.

This is with node 0.10.12 on OS X 10.8.4.

@rvagg
Copy link
Owner

rvagg commented Jun 27, 2013

@ryandesign fyi I've seen the issues you've submitted here and I'd love to address them but I'm a little busy right at this moment but I will get to them! You're welcome to open pull requests to try and deal with the things you've raised and I'm happy to steer you through the process of getting it right.

@ryandesign
Copy link
Author

According to a comment in nodejs/node-v0.x-archive#5727 the communication channel employed by process.send() converts everything to JSON first. So custom object types (like Errors) can't possibly work, since object types aren't represented in JSON. And this pretty much invalidates worker-farm's promise to pass along the arguments unchanged.

@ryandesign
Copy link
Author

So there seem to be two problems.

  1. Since process.send() uses JSON, any object you send will become a generic object. This can be addressed by making "reviver" functions, but these seem to require some participation of the particular object types being revived; developers using worker-farm would have to be aware of this requirement and provide for it. Or worker-farm could try to install private revivers into each type of object being used, but these wouldn't work in all cases.
  2. The Error object does not serialize to JSON properly. See JSON.stringify(new Error('hello')). I don't know if this is considered a bug or a feature.

@rvagg
Copy link
Owner

rvagg commented Jun 29, 2013

suggestions for solutions?

@rvagg
Copy link
Owner

rvagg commented Sep 17, 2013

fixed by doing a custom serialisation and deserialisation of Error objects.

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

2 participants