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.
pull/22966/head
isaacs 2011-02-15 21:34:30 -08:00 committed by Ryan Dahl
parent 2cfe7b847d
commit f3d364122d
2 changed files with 4 additions and 2 deletions

View File

@ -1027,7 +1027,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;

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)) {