You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stream: Readable iterator unhandled error when piping #28194
When using asyncIterator on a piped stream, the error is not handled correctly.
constfs=require('fs');const{ PassThrough }=require('stream');asyncfunctionprint(){constread=fs.createReadStream('file');constiterator=read.pipe(newPassThrough())forawait(constkofiterator){console.log(k);}}print().then(()=>console.log('done'))// never called.catch(console.log);// never called
In the above example, the .catch is not catching the error, and the script crashes.
I know, that I should catch the error of each stream, but if I do:
read.on('error',console.log);
The print function never resolves nor rejects. The only solution I've found is to emit the error to the piped stream.
When you have multiple pipes, this can get very ugly. I don't know if this is the intended behaviour, but makes it hard & ugly to work with async iterators.
No, it doesn't unfortunately, because the error is passed to the .pipeline callback, so the for await does not throw, and the print function resolves without iterating anything, instead of throwing.
asyncfunctionprint(){constread=fs.createReadStream('file');conststream=newPassThrough();constiterator=pipeline(read,stream,(err)=>{// I get the error here// print will resolve, without iterating.});forawait(constkofiterator){console.log(k);}}
Activity
Fishrock123 commentedon Jun 13, 2019
I don't know for sure, but does
stream.pipeline()solve this?marcosc90 commentedon Jun 13, 2019
No, it doesn't unfortunately, because the error is passed to the
.pipelinecallback, so thefor awaitdoes not throw, and theprintfunction resolves without iterating anything, instead of throwing.stream: propagate errors from src streams in async iterator
stream: make all streams error in a pipeline
stream: make all streams error in a pipeline
stream: make all streams error in a pipeline
stream: make all streams error in a pipeline