node
node copied to clipboard
stream: catch and forward error from dest.write
Fixes: https://github.com/nodejs/node/issues/54945
Wanted to give a quick mention why checking object modes at the start of the pipe function wouldn't work (even though I liked the idea). Because if the chunk from the source stream is not object while source stream is in object mode and destination stream is not in object mode, it should still work.
Consider the following example:
const { Readable, Writable } = require("node:stream");
const write = new Writable({
write(data, enc, cb) {
// do something with the data
cb();
},
});
write.on("error", (err) => {
console.log(err);
});
Readable.from("hello hello").pipe(write);