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.
v0.7.4-release
isaacs 2011-02-15 21:34:30 -08:00 committed by Ryan Dahl
parent 1d5ff15a46
commit 11a06fe1e4
2 changed files with 4 additions and 2 deletions

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;

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