Browse Source

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 14 years ago
committed by Ryan Dahl
parent
commit
11a06fe1e4
  1. 3
      lib/fs.js
  2. 3
      lib/tty_win32.js

3
lib/fs.js

@ -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;

3
lib/tty_win32.js

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

Loading…
Cancel
Save