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: https://github.com/nodejs/node/issues/20303 PR-URL: https://github.com/nodejs/node/pull/20437 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
c2c9c0c3d3
commit
c1012b4402
@ -19,7 +19,10 @@ function once(callback) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function noop() {}
|
function noop(err) {
|
||||||
|
// Rethrow the error if it exists to avoid swallowing it
|
||||||
|
if (err) throw err;
|
||||||
|
}
|
||||||
|
|
||||||
function isRequest(stream) {
|
function isRequest(stream) {
|
||||||
return stream.setHeader && typeof stream.abort === 'function';
|
return stream.setHeader && typeof stream.abort === 'function';
|
||||||
|
@ -142,7 +142,7 @@ common.crashOnUnhandledRejection();
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pipeline(rs, res);
|
pipeline(rs, res, () => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(0, () => {
|
server.listen(0, () => {
|
||||||
@ -177,7 +177,7 @@ common.crashOnUnhandledRejection();
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
pipeline(rs, res);
|
pipeline(rs, res, () => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(0, () => {
|
server.listen(0, () => {
|
||||||
@ -206,7 +206,7 @@ common.crashOnUnhandledRejection();
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
pipeline(rs, res);
|
pipeline(rs, res, () => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
let cnt = 10;
|
let cnt = 10;
|
||||||
@ -481,3 +481,35 @@ common.crashOnUnhandledRejection();
|
|||||||
|
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const read = new Readable({
|
||||||
|
read() {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const transform = new Transform({
|
||||||
|
transform(data, enc, cb) {
|
||||||
|
cb(new Error('kaboom'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const write = new Writable({
|
||||||
|
write(data, enc, cb) {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
read.on('close', common.mustCall());
|
||||||
|
transform.on('close', common.mustCall());
|
||||||
|
write.on('close', common.mustCall());
|
||||||
|
|
||||||
|
process.on('uncaughtException', common.mustCall((err) => {
|
||||||
|
assert.deepStrictEqual(err, new Error('kaboom'));
|
||||||
|
}));
|
||||||
|
|
||||||
|
const dst = pipeline(read, transform, write);
|
||||||
|
|
||||||
|
assert.strictEqual(dst, write);
|
||||||
|
|
||||||
|
read.push('hello');
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user