Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Emit errors consistently #4897

Closed
isaacs opened this issue Mar 2, 2013 · 0 comments
Closed

Emit errors consistently #4897

isaacs opened this issue Mar 2, 2013 · 0 comments

Comments

@isaacs
Copy link

isaacs commented Mar 2, 2013

Throughout the codebase, there are some cases where we emit('error') right away on some user action, and other cases where we defer the error emit call until nextTick.

For example, Writable streams emit the error right away if you call write(chunk) after calling end(). However, there are many other cases where the error is deferred until nextTick (qv almost every error in lib/net.js).

On the one hand, you already have the object if you're calling write() on it, so you've had a chance to add an error listener. On the other hand, actual write() errors (EPIPE, etc.) usually don't happen synchronously, so it's odd to sometimes have to put the listener on before calling write() and other times not.

Since we can't make all errors synchronous, for obvious reasons, we may as well make all errors async, and defer emit('error', er) calls until nextTick. The throw site is already garbage, since it throws from inside events.js, so there's really no cost to deferring consistently.

At least, these probably need fixing:

  • lib/_stream_* (especially writable)
  • lib/fs.js (not sure if it's actually in there, but there is at least a test verifying that write-after-end throws)
  • dgram.js maybe
  • tls.js
  • Several tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants