diff --git a/lib/fs.js b/lib/fs.js index 3eb31a99fc..8350c6159c 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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; diff --git a/lib/tty_win32.js b/lib/tty_win32.js index 6ca011a333..7aa137a094 100644 --- a/lib/tty_win32.js +++ b/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)) {