Closes GH-85 Emit error rather than throwing.

Since "error" events will throw when unhandled anyhow, it makes no sense
to throw from an EventEmitter's method, especially for such a minor
misdemeanor as attempting to write to a non-writable stream.
This commit is contained in:
isaacs authored and Ryan Dahl committed 2011-03-02 22:09:39 -08:00
1 parent 1d5ff15a46
commit 11a06fe1e4
2 files changed
+4 -2

No files matched your search

+2 -1
View File
@@ -1066,7 +1066,8 @@ WriteStream.prototype.flush = function() {
WriteStream.prototype.write = function(data) {
if (!this.writable) {
throw new Error('stream not writable');
this.emit("error", new Error('stream not writable'));
return false;
}
this.drainable = true;
+2 -1
View File
@@ -99,7 +99,8 @@ WriteStream.prototype.isTTY = true;
WriteStream.prototype.write = function(data, encoding) {
if (!this.writable) {
throw new Error('stream not writable');
this.emit("error", new Error('stream not writable'));
return false;
}
if (Buffer.isBuffer(data)) {