Created
February 16, 2011 05:36
-
-
Save isaacs/828923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 2086f06e6cdbd4b46f8e9e90d44fc339cb8efbbd Mon Sep 17 00:00:00 2001 | |
From: isaacs <i@izs.me> | |
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 18cf7f1..500f0fa 100644 | |
--- a/lib/fs.js | |
+++ b/lib/fs.js | |
@@ -1021,7 +1021,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)) { | |
-- | |
1.7.2.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment