Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: use null for the error argument #44312

Merged
merged 1 commit into from Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/internal/streams/writable.js
Expand Up @@ -497,7 +497,7 @@ function afterWrite(stream, state, count, cb) {

while (count-- > 0) {
state.pendingcb--;
cb();
cb(null);
}

if (state.destroyed) {
Expand Down Expand Up @@ -640,8 +640,10 @@ Writable.prototype.end = function(chunk, encoding, cb) {
}

if (typeof cb === 'function') {
if (err || state.finished) {
if (err) {
process.nextTick(cb, err);
} else if (state.finished) {
process.nextTick(cb, null);
} else {
state[kOnFinished].push(cb);
}
Expand Down Expand Up @@ -742,7 +744,7 @@ function finish(stream, state) {

const onfinishCallbacks = state[kOnFinished].splice(0);
for (let i = 0; i < onfinishCallbacks.length; i++) {
onfinishCallbacks[i]();
onfinishCallbacks[i](null);
}

stream.emit('finish');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-writable-end-cb-error.js
Expand Up @@ -36,7 +36,7 @@ const stream = require('stream');
let called = false;
writable.end('asd', common.mustCall((err) => {
called = true;
assert.strictEqual(err, undefined);
assert.strictEqual(err, null);
}));

writable.on('error', common.mustCall((err) => {
Expand Down
11 changes: 8 additions & 3 deletions test/parallel/test-stream2-writable.js
Expand Up @@ -194,7 +194,8 @@ for (let i = 0; i < chunks.length; i++) {
{
// Verify write callbacks
const callbacks = chunks.map(function(chunk, i) {
return [i, function() {
return [i, function(err) {
assert.strictEqual(err, null);
callbacks._called[i] = chunk;
}];
}).reduce(function(set, x) {
Expand Down Expand Up @@ -225,15 +226,19 @@ for (let i = 0; i < chunks.length; i++) {
{
// Verify end() callback
const tw = new TestWriter();
tw.end(common.mustCall());
tw.end(common.mustCall(function(err) {
assert.strictEqual(err, null);
}));
}

const helloWorldBuffer = Buffer.from('hello world');

{
// Verify end() callback with chunk
const tw = new TestWriter();
tw.end(helloWorldBuffer, common.mustCall());
tw.end(helloWorldBuffer, common.mustCall(function(err) {
assert.strictEqual(err, null);
}));
}

{
Expand Down