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 2c9b7e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 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
9 changes: 8 additions & 1 deletion test/parallel/test-fs-write-stream-eagain.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as common from '../common/index.mjs';
import tmpdir from '../common/tmpdir.js';
import assert from 'node:assert';
import fs from 'node:fs';
import { describe, it, mock } from 'node:test';
import { afterEach, describe, it, mock } from 'node:test';
import { finished } from 'node:stream/promises';

tmpdir.refresh();
Expand All @@ -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 2c9b7e0

Please sign in to comment.