-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Fix pipeline promise and handle errors #21
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test that call the callback with an error
@mcollina Tests are fine but I see a rejection error.
That rejection is thrown when |
Code looks good, but the unhandledRejection should be fixed. |
@mcollina The problem with the test that never exit is in aedes-persistence abstract test, some tests doens't call inbstance.destroy at the end. I will submit a PR for this
I have no clue who is sending that rejection, It should not be thrown because I catch the error correctly but seems that when I call UPDATE: I have found this: #17 |
@mcollina Please make a new release after this merge so I can also fix this in |
@mcollina Could you review this and if ok merge and release a new version? So I can go on with aedes-persistence-redis PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
mqemitter-redis.js
Outdated
@@ -33,6 +34,14 @@ function MQEmitterRedis (opts) { | |||
|
|||
var that = this | |||
|
|||
function onError (err) { | |||
if (err) { | |||
that.state.emit('emitError', err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why its this not error
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcollina Because 'error' throws unhandled rejections on emit, check #15 and #21 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to track down why this is happening wqithout changing event name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcollina I have no clue Matteo... I have try to debug this but I can only tell you when this happens:
If emit throws an error and cb is not defined the unhandled rejection is thrown after I call this.state.emit('error')
, it is like that emit throws an error instead of just emit it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I have found this in docs: https://nodejs.org/api/events.html#events_class_events_eventemitter
If an EventEmitter does not have at least one listener registered for the 'error' event, and an 'error' event is emitted, the error is thrown, a stack trace is printed, and the Node.js process exits.
So the solutions are: change the event name or create a default event listener for 'error' (noop) like I did in my latest commit 464e7ed
The problem is not avoiding the unhandledRejection, but rather understading where it come from and handle it there. |
@mcollina It comes from: https://github.com/mcollina/mqemitter/blob/master/abstractTest.js#L139 Close is called immediatly after emit and this causes that error. Should I fix that test? If yes, how? I mean I could add an |
Which operation is missing a |
Please check my prev comment https://github.com/mcollina/mqemitter- In the abstract test it is thrown here: https://github.com/mcollina/mqemitter/blob/master/abstractTest.js#L148 Because this test throws close after emit and this will make pipeline in mqemitter redis to throw an error that is catched but once I call 'emit('error')` on the catch this thows an error as there is no error listener and this is the default behaviour of event emitter |
Which promise is rejecting? Which line of code creates that promise? Why does it not have a .catch() handler attached? |
@mcollina This is the promise: It has a catch block that calls done that in this case is not a user callback but will be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@mcollina Remember to create a release after the merge so I can go on with aedes-persistence-redis 😄 |
Fixes #20 #15