Skip to content

Commit

Permalink
destroyed err
Browse files Browse the repository at this point in the history
  • Loading branch information
atlowChemi committed Aug 23, 2023
1 parent 8bdfd1f commit 20d51d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const {

const {
ERR_INVALID_ARG_TYPE,
ERR_OUT_OF_RANGE,
ERR_METHOD_NOT_IMPLEMENTED,
ERR_OUT_OF_RANGE,
ERR_STREAM_DESTROYED,
ERR_SYSTEM_ERROR,
} = require('internal/errors').codes;
const {
Expand Down Expand Up @@ -402,7 +403,7 @@ function writeAll(data, size, pos, cb, retries = 0) {
}

if (this.destroyed || er) {
return cb(er);
return cb(er || new ERR_STREAM_DESTROYED('write'));
}

this.bytesWritten += bytesWritten;
Expand Down Expand Up @@ -431,7 +432,7 @@ function writevAll(chunks, size, pos, cb, retries = 0) {
}

if (this.destroyed || er) {
return cb(er);
return cb(er || new ERR_STREAM_DESTROYED('writev'));
}

this.bytesWritten += bytesWritten;
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-fs-write-stream-eagain.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ describe('WriteStream EAGAIN', { concurrency: true }, () => {
assert.strictEqual(mockWrite.mock.callCount(), 2);
assert.strictEqual(fs.readFileSync(file, 'utf8'), 'foo');
});

it('_write', async () => {
const stream = fs.createWriteStream(file);
mock.getter(stream, 'destroyed', () => true);
stream.end('foo');
await finished(stream).catch(common.mustCall());
});
});

0 comments on commit 20d51d2

Please sign in to comment.