Skip to content

Commit

Permalink
fs: Swallow error
Browse files Browse the repository at this point in the history
  • Loading branch information
dexterleng committed Dec 19, 2018
1 parent e657b86 commit 930c8d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
13 changes: 3 additions & 10 deletions lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,8 @@ ReadStream.prototype.open = function() {
this.fd = fd;

if (this.destroyed) {
closeFsStream(this, (er) => {
if (er) {
this.emit('error', er);
}
});
// swallow the error to prevent error from emitting after close.
closeFsStream(this, () => {});
return;
}

Expand Down Expand Up @@ -307,11 +304,7 @@ WriteStream.prototype.open = function() {
this.fd = fd;

if (this.destroyed) {
closeFsStream(this, (er) => {
if (er) {
this.emit('error', er);
}
});
closeFsStream(this, () => {});
return;
}

Expand Down
5 changes: 1 addition & 4 deletions test/parallel/test-fs-stream-no-events-after-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ const test = (stream) => {
stream.on('open', common.mustNotCall());
stream.on('ready', common.mustNotCall());
stream.on('close', common.mustCall());
stream.on('error', common.mustCall((er) => {
assert.strictEqual(err, er);
assert.strictEqual(stream.closed, false);
}));
stream.on('error', common.mustNotCall());
}

test(fs.createReadStream(__filename));
Expand Down

0 comments on commit 930c8d4

Please sign in to comment.