Bug Description: Uncatchable error thrown during piping if source and dest don't have same objectMode setting. #54955
Labels
duplicate
Issues and PRs that are duplicates of other issues or PRs.
Version
v22.8.0
Platform
Subsystem
No response
What steps will reproduce the bug?
Bug Reproduction Steps:
Create a Readable stream in object mode using Readable.from().
Create a Transform stream with objectMode set to false.
Pipe the Readable stream to the Transform stream using pipe().
Consume the output of the Transform stream using a for await loop.
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
Expected Behavior: The pipe() method should throw an error or the Transform stream should emit an error when the objectMode settings of the source and destination streams do not match.
Actual Behavior: An uncatchable TypeError is thrown with the message "The 'chunk' argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object".
What do you see instead?
Solution: Ensure that both the Readable and Transform streams have the same objectMode setting. In this case, set objectMode to true for the Transform stream.
Additional information
code '''
async function main() {
const objectReadable = Readable.from([
{ hello: "world" },
{ goodbye: "world" }
]);
objectReadable.on("error", err => {
console.log("objectReadable error", err);
});
const passThrough = new Transform({
transform(chunk, _encoding, cb) {
this.push(chunk);
cb(null);
},
objectMode: true // Set objectMode to true
});
passThrough.on("error", err => {
console.log("passThrough error", err);
});
try {
console.assert(objectReadable.readableObjectMode, "objectReadable is not in object mode");
console.assert(passThrough.writableObjectMode, "passThrough is not in object mode write side");
} catch (e) {
console.error("caught error when calling pipe", e);
return;
}
try {
console.log("beginning consume of passThrough");
const output = [];
for await (const v of passThrough) {
output.push(v);
}
console.log("output", output);
} catch (e) {
console.error("caught error while consuming output ", e);
return;
}
console.log("done");
}
process.setUncaughtExceptionCaptureCallback(err => {
console.error("uncaught exception", err);
});
main();
'''
The text was updated successfully, but these errors were encountered: