mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 02:06:12 +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) {
|
while (count-- > 0) {
|
||||||
state.pendingcb--;
|
state.pendingcb--;
|
||||||
cb();
|
cb(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.destroyed) {
|
if (state.destroyed) {
|
||||||
@ -640,8 +640,10 @@ Writable.prototype.end = function(chunk, encoding, cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
if (err || state.finished) {
|
if (err) {
|
||||||
process.nextTick(cb, err);
|
process.nextTick(cb, err);
|
||||||
|
} else if (state.finished) {
|
||||||
|
process.nextTick(cb, null);
|
||||||
} else {
|
} else {
|
||||||
state[kOnFinished].push(cb);
|
state[kOnFinished].push(cb);
|
||||||
}
|
}
|
||||||
@ -742,7 +744,7 @@ function finish(stream, state) {
|
|||||||
|
|
||||||
const onfinishCallbacks = state[kOnFinished].splice(0);
|
const onfinishCallbacks = state[kOnFinished].splice(0);
|
||||||
for (let i = 0; i < onfinishCallbacks.length; i++) {
|
for (let i = 0; i < onfinishCallbacks.length; i++) {
|
||||||
onfinishCallbacks[i]();
|
onfinishCallbacks[i](null);
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.emit('finish');
|
stream.emit('finish');
|
||||||
|
@ -36,7 +36,7 @@ const stream = require('stream');
|
|||||||
let called = false;
|
let called = false;
|
||||||
writable.end('asd', common.mustCall((err) => {
|
writable.end('asd', common.mustCall((err) => {
|
||||||
called = true;
|
called = true;
|
||||||
assert.strictEqual(err, undefined);
|
assert.strictEqual(err, null);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
writable.on('error', common.mustCall((err) => {
|
writable.on('error', common.mustCall((err) => {
|
||||||
|
@ -194,7 +194,8 @@ for (let i = 0; i < chunks.length; i++) {
|
|||||||
{
|
{
|
||||||
// Verify write callbacks
|
// Verify write callbacks
|
||||||
const callbacks = chunks.map(function(chunk, i) {
|
const callbacks = chunks.map(function(chunk, i) {
|
||||||
return [i, function() {
|
return [i, function(err) {
|
||||||
|
assert.strictEqual(err, null);
|
||||||
callbacks._called[i] = chunk;
|
callbacks._called[i] = chunk;
|
||||||
}];
|
}];
|
||||||
}).reduce(function(set, x) {
|
}).reduce(function(set, x) {
|
||||||
@ -225,7 +226,9 @@ for (let i = 0; i < chunks.length; i++) {
|
|||||||
{
|
{
|
||||||
// Verify end() callback
|
// Verify end() callback
|
||||||
const tw = new TestWriter();
|
const tw = new TestWriter();
|
||||||
tw.end(common.mustCall());
|
tw.end(common.mustCall(function(err) {
|
||||||
|
assert.strictEqual(err, null);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
const helloWorldBuffer = Buffer.from('hello world');
|
const helloWorldBuffer = Buffer.from('hello world');
|
||||||
@ -233,7 +236,9 @@ const helloWorldBuffer = Buffer.from('hello world');
|
|||||||
{
|
{
|
||||||
// Verify end() callback with chunk
|
// Verify end() callback with chunk
|
||||||
const tw = new TestWriter();
|
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