-
Notifications
You must be signed in to change notification settings - Fork 467
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
Handling exceptions in callback API #56
Comments
Commit c007e43 adds error handling to the callback RPC machinery. Specifically, it redirects errors thrown in callbacks to channel 'error' events (thereby closing the channel). Arguably this diverges from the semantics of the promise API: there, an error thrown in a success continuation won't break the channel, though it will of course result in an error continuation being called. There's no obvious other way to surface errors in the callback API, but I wonder if it's appropriate for the promise API to do the analogous thing and close the channel, or even whether it's possible -- maybe not, thinking about it. |
Actually, I don't think redirecting errors is the right thing to do. If an error is thrown in callback code, it should crash. 'error' should be reserved for operational errors, that is, the socket closing and what have you. |
I agree, node-amqp does the former and it's difficult to tell whether an error is due to network conditions or you app level code sucking. Wrote some thoughts on this a few months back: https://gist.github.com/gjohnson/7566343 |
I reverted this in ae5a495 |
Many operations in the promise and the callback APIs can give rise to errors, either because
In general, 1. is handled by emitting an error from the channel; 2. is a bug, so bets are off.
With 3., the promises library will redirect an exception thrown in a success continuation to the (eventual) error continuation. However, this sort of behaviour isn't possible for the callback API, which essentially invokes callbacks in the top-level context.
The simplest solution is probably to wrap the outermost frame handlers in try-catch blocks, and redirect any exceptions as 'error' events.
The text was updated successfully, but these errors were encountered: