Closed
Description
Version
v16.19.0, v19.3.0
Platform
Darwin Simens-MacBook-Pro.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 arm64
Subsystem
stream
What steps will reproduce the bug?
If passing an array of Promises to stream.Duplex.from
and one rejects before all others are settled, an uncaught error is emitted. If all promises except for the rejected one are settled, then it correctly emits an error event on the stream instead.
import { Duplex } from 'node:stream';
import getStream from 'get-stream';
process.on('uncaughtException', error => {
console.error('Got uncaught exception', error);
process.exit(1);
});
try {
const dup = Duplex.from([
'hello',
Promise.resolve('1'),
Promise.resolve('2'),
// Setting timeout to 500 correctly errors instead of emitting uncaught
new Promise(resolve => setTimeout(() => resolve('3'), 1500)),
'end',
new Promise((resolve, reject) =>
setTimeout(() => reject(new Error('booo')), 1000),
),
]);
const res = await getStream(dup);
console.log(res);
} catch (error) {
process.exitCode = 1;
console.error('Got error', error);
}
get-stream
: https://www.npmjs.com/package/get-stream (I don't know a good way with core stream
to get a promise of a stream).
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
There should never be an uncaught error, it should always be emitted as an error event on the stream.
What do you see instead?
Uncaught error emitted.
Additional information
No response