EventEmitter2
EventEmitter2 copied to clipboard
Error events are lost of the EventEmitter is not properly initialized
I had a situation where something was inheriting from EventEmitter, however the constructor forgot to call the superclass constructor and no event listeners were added on that emitter (which would also have initialized the emitter). So on line 932, it simply returns false when an error is raised. This should be updated to throw the error if an error is being raised, rather than silently ignoring it.
Hmm, I'm not sure if this is a real bug since this issue does not actually arise if the constructor chain was called properly. With ES6 classes, which are currently the main way of inheritance for typical users, it's not possible to inherit a class without calling its super constructor. Generally a class should not guarantee proper work if its constructor has not been called.
I think that's usually a reasonable take. However, usually when something isn't properly set up, an error will happen when methods are called, etc. In this case, it silently fails. And the fix is pretty easy - just throw an error if its not properly set up instead of returning false. Is there a reason its returning false instead of throwing an error?