I use readable and transform streams which I later consume using for await.
I cannot find a way to process callee's stream errors so they can be caught in the caller function.
For example if transform throws, it results in uncaught error.
If I add on error listener to transform, naturally it doesn't propagate the error to main's catch.
function handler(err) {
// Log the error here
// If throw from here it won't be cauch in main
// How do I propagate it to main?
}
function getStream() {
// transform1 and transform2 are custom transform streams
readable.pipe(csvParser).pipe(transform1).pipe(transform2);
readable.on('error', handler);
csvParser.on('error', handler);
transform1.on('error', handler);
transform2.on('error', handler);
return transform2;
}
async function main() {
try {
const stream = getStream();
for await(const chunk of stream) {
// process chunk
}
} catch (ex) {
// how to catch transform errors here?
}
}
Is there any way to do it?