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.
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;
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)) {