Skip to content

Commit f3d3641

Browse files
isaacsry
authored andcommitted
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.
1 parent 2cfe7b8 commit f3d3641

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/fs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,8 @@ WriteStream.prototype.flush = function() {
10271027

10281028
WriteStream.prototype.write = function(data) {
10291029
if (!this.writable) {
1030-
throw new Error('stream not writable');
1030+
this.emit("error", new Error('stream not writable'));
1031+
return false;
10311032
}
10321033

10331034
this.drainable = true;

lib/tty_win32.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ WriteStream.prototype.isTTY = true;
9999

100100
WriteStream.prototype.write = function(data, encoding) {
101101
if (!this.writable) {
102-
throw new Error('stream not writable');
102+
this.emit("error", new Error('stream not writable'));
103+
return false;
103104
}
104105

105106
if (Buffer.isBuffer(data)) {

0 commit comments

Comments
 (0)