node icon indicating copy to clipboard operation
node copied to clipboard

stream: catch and forward error from dest.write

Open jakecastelli opened this issue 4 months ago • 30 comments

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);

jakecastelli avatar Oct 05 '24 05:10 jakecastelli