Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b32985

Browse filesBrowse files
authored
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: #44290 PR-URL: #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>
1 parent 8e87299 commit 2b32985
Copy full SHA for 2b32985

File tree

Expand file treeCollapse file tree

3 files changed

+14
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+14
-7
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/writable.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/writable.js
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ function afterWrite(stream, state, count, cb) {
497497

498498
while (count-- > 0) {
499499
state.pendingcb--;
500-
cb();
500+
cb(null);
501501
}
502502

503503
if (state.destroyed) {
@@ -640,8 +640,10 @@ Writable.prototype.end = function(chunk, encoding, cb) {
640640
}
641641

642642
if (typeof cb === 'function') {
643-
if (err || state.finished) {
643+
if (err) {
644644
process.nextTick(cb, err);
645+
} else if (state.finished) {
646+
process.nextTick(cb, null);
645647
} else {
646648
state[kOnFinished].push(cb);
647649
}
@@ -742,7 +744,7 @@ function finish(stream, state) {
742744

743745
const onfinishCallbacks = state[kOnFinished].splice(0);
744746
for (let i = 0; i < onfinishCallbacks.length; i++) {
745-
onfinishCallbacks[i]();
747+
onfinishCallbacks[i](null);
746748
}
747749

748750
stream.emit('finish');
Collapse file

‎test/parallel/test-stream-writable-end-cb-error.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-writable-end-cb-error.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const stream = require('stream');
3636
let called = false;
3737
writable.end('asd', common.mustCall((err) => {
3838
called = true;
39-
assert.strictEqual(err, undefined);
39+
assert.strictEqual(err, null);
4040
}));
4141

4242
writable.on('error', common.mustCall((err) => {
Collapse file

‎test/parallel/test-stream2-writable.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream2-writable.js
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ for (let i = 0; i < chunks.length; i++) {
194194
{
195195
// Verify write callbacks
196196
const callbacks = chunks.map(function(chunk, i) {
197-
return [i, function() {
197+
return [i, function(err) {
198+
assert.strictEqual(err, null);
198199
callbacks._called[i] = chunk;
199200
}];
200201
}).reduce(function(set, x) {
@@ -225,15 +226,19 @@ for (let i = 0; i < chunks.length; i++) {
225226
{
226227
// Verify end() callback
227228
const tw = new TestWriter();
228-
tw.end(common.mustCall());
229+
tw.end(common.mustCall(function(err) {
230+
assert.strictEqual(err, null);
231+
}));
229232
}
230233

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

233236
{
234237
// Verify end() callback with chunk
235238
const tw = new TestWriter();
236-
tw.end(helloWorldBuffer, common.mustCall());
239+
tw.end(helloWorldBuffer, common.mustCall(function(err) {
240+
assert.strictEqual(err, null);
241+
}));
237242
}
238243

239244
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.