browserify / events

Node's event emitter for all engines.
MIT License
1.38k stars 173 forks source link

unhandled 'error' events should throw the error on next tick (setTimeout or setImmediate) #68

Closed koush closed 4 years ago

koush commented 4 years ago

When EventEmitter.emit('error', error) is called in node, and goes unhandled, node will throw the error on the next tick, where it can't be handled by the current call stack. This library throws the error during the emit call itself, which makes the error end up being thrown into a call stack that is not expecting it. This is particularly odd, because the caller is attempting to report the error, and it gets thrown back. I believe this behavior is incorrect.

I think the correct behavior, to mimic node, would be report the error using setTimeout or setImmediate, to clear the call stack before throwing. That way, the error will actually make it into the browser console output, which is generally benign.

koush commented 4 years ago

actually this seems to be some repl vs script execution difference, nevermind.

goto-bus-stop commented 4 years ago

ahh ok, i was surprised to see this issue because i was pretty sure we copy-pasted the node.js events module verbatim and only tweaked it to add support for older browser environments. thanks for the report anyways!