mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 03:31:35 +00:00
stream: use null for the error argument
When no error occurs, use `null` instead of `undefined` for the `error` argument of the `writable.write()` and `writable.end()` callbacks. Fixes: https://github.com/nodejs/node/issues/44290 PR-URL: https://github.com/nodejs/node/pull/44312 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
This commit is contained in:
parent
8e872999c4
commit
2b32985c62
@ -497,7 +497,7 @@ function afterWrite(stream, state, count, cb) {
|
||||
|
||||
while (count-- > 0) {
|
||||
state.pendingcb--;
|
||||
cb();
|
||||
cb(null);
|
||||
}
|
||||
|
||||
if (state.destroyed) {
|
||||
@ -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);
|
||||
}
|
||||
@ -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');
|
||||
|
@ -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) => {
|
||||
|
@ -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) {
|
||||
@ -225,7 +226,9 @@ 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');
|
||||
@ -233,7 +236,9 @@ 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);
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user