From 11a06fe1e4c5f499fa2ce64acf2f5fe93c29ec5f Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 15 Feb 2011 21:34:30 -0800 Subject: [PATCH] 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. --- lib/fs.js | 3 ++- lib/tty_win32.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 244923fb94..fccbfd2551 100644 --- a/lib/fs.js +++ b/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; 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)) {