From f3d364122dc12f13cbfb848576a8b152849452ea 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 3eb31a9..8350c61 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 6ca011a..7aa137a 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)) { -- 2.7.4