Skip to content

Commit d1e81b0

Browse files
phatedaddaleax
authored andcommitted
stream: ensure Stream.pipeline re-throws errors without callback
Fixes an issue where Stream.pipeline wouldn't re-throw errors on a stream if no callback was specified, thus swallowing said errors. Fixes: #20303 PR-URL: #20437 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent af06581 commit d1e81b0

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

‎lib/internal/streams/pipeline.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ function once(callback) {
1919
};
2020
}
2121

22-
functionnoop(){}
22+
functionnoop(err){
23+
// Rethrow the error if it exists to avoid swallowing it
24+
if(err)throwerr;
25+
}
2326

2427
functionisRequest(stream){
2528
returnstream.setHeader&&typeofstream.abort==='function';

‎test/parallel/test-stream-pipeline.js‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ common.crashOnUnhandledRejection();
142142
}
143143
});
144144

145-
pipeline(rs,res);
145+
pipeline(rs,res,()=>{});
146146
});
147147

148148
server.listen(0,()=>{
@@ -177,7 +177,7 @@ common.crashOnUnhandledRejection();
177177
})
178178
});
179179

180-
pipeline(rs,res);
180+
pipeline(rs,res,()=>{});
181181
});
182182

183183
server.listen(0,()=>{
@@ -206,7 +206,7 @@ common.crashOnUnhandledRejection();
206206
})
207207
});
208208

209-
pipeline(rs,res);
209+
pipeline(rs,res,()=>{});
210210
});
211211

212212
letcnt=10;
@@ -481,3 +481,35 @@ common.crashOnUnhandledRejection();
481481

482482
run();
483483
}
484+
485+
{
486+
constread=newReadable({
487+
read(){}
488+
});
489+
490+
consttransform=newTransform({
491+
transform(data,enc,cb){
492+
cb(newError('kaboom'));
493+
}
494+
});
495+
496+
constwrite=newWritable({
497+
write(data,enc,cb){
498+
cb();
499+
}
500+
});
501+
502+
read.on('close',common.mustCall());
503+
transform.on('close',common.mustCall());
504+
write.on('close',common.mustCall());
505+
506+
process.on('uncaughtException',common.mustCall((err)=>{
507+
assert.deepStrictEqual(err,newError('kaboom'));
508+
}));
509+
510+
constdst=pipeline(read,transform,write);
511+
512+
assert.strictEqual(dst,write);
513+
514+
read.push('hello');
515+
}

0 commit comments

Comments
 (0)