joyent/node — pull request #2848 by jmar777 (2012-02-29 17:59:43+00:00)
Title: net.js: emit errors when pipe is unavailable, instead of throw

There are two locations in net.js that throw an error when a pipe is unavailable for interaction. This is a legitimate error condition, but throwing instead of emitting an error seems inconsistent in this situation.

Throughout the remainder of the file, errors are only thrown due to obvious programmer errors (e.g., TypeErrors, deprecated APIs, etc.). In the case of an unavailable `_handle`, however, the situation may have been caused by network/connectivity issues, rather than programmer error. Developers can mitigate this situation by extremely defensively and frequently checking the `writable` flag (assuming `writable == !!_handle` in all cases), but given the high traffic nature of this code it is a difficult situation to guard against. Other error conditions caused by network conditions (e.g., failed dns lookups) emit an error as well, and I believe this is generally the expected behavior.

This pull request simply addresses these two locations where the errors are being thrown, by replacing the throws with emitted errors.