Skip to content

Commit 20d51d2

Browse files
committed
destroyed err
1 parent 8bdfd1f commit 20d51d2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/internal/fs/streams.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ const {
1313

1414
const {
1515
ERR_INVALID_ARG_TYPE,
16-
ERR_OUT_OF_RANGE,
1716
ERR_METHOD_NOT_IMPLEMENTED,
17+
ERR_OUT_OF_RANGE,
18+
ERR_STREAM_DESTROYED,
1819
ERR_SYSTEM_ERROR,
1920
} = require('internal/errors').codes;
2021
const {
@@ -402,7 +403,7 @@ function writeAll(data, size, pos, cb, retries = 0) {
402403
}
403404

404405
if (this.destroyed || er) {
405-
return cb(er);
406+
return cb(er || new ERR_STREAM_DESTROYED('write'));
406407
}
407408

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

433434
if (this.destroyed || er) {
434-
return cb(er);
435+
return cb(er || new ERR_STREAM_DESTROYED('writev'));
435436
}
436437

437438
this.bytesWritten += bytesWritten;

test/parallel/test-fs-write-stream-eagain.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ describe('WriteStream EAGAIN', { concurrency: true }, () => {
2929
assert.strictEqual(mockWrite.mock.callCount(), 2);
3030
assert.strictEqual(fs.readFileSync(file, 'utf8'), 'foo');
3131
});
32+
33+
it('_write', async () => {
34+
const stream = fs.createWriteStream(file);
35+
mock.getter(stream, 'destroyed', () => true);
36+
stream.end('foo');
37+
await finished(stream).catch(common.mustCall());
38+
});
3239
});

0 commit comments

Comments
 (0)