Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit2b32985

Browse 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:#44290PR-URL:#44312Reviewed-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 parent8e87299 commit2b32985

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

‎lib/internal/streams/writable.js

Lines 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(typeofcb==='function'){
643-
if(err||state.finished){
643+
if(err){
644644
process.nextTick(cb,err);
645+
}elseif(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
constonfinishCallbacks=state[kOnFinished].splice(0);
744746
for(leti=0;i<onfinishCallbacks.length;i++){
745-
onfinishCallbacks[i]();
747+
onfinishCallbacks[i](null);
746748
}
747749

748750
stream.emit('finish');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const stream = require('stream');
3636
letcalled=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)=>{

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

Lines 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
constcallbacks=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
consttw=newTestWriter();
228-
tw.end(common.mustCall());
229+
tw.end(common.mustCall(function(err){
230+
assert.strictEqual(err,null);
231+
}));
229232
}
230233

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

233236
{
234237
// Verify end() callback with chunk
235238
consttw=newTestWriter();
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)

[8]ページ先頭

©2009-2025 Movatter.jp