Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Description: Uncatchable error thrown during piping if source and dest don't have same objectMode setting. #54955

Closed
kunal7216 opened this issue Sep 15, 2024 · 1 comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.

Comments

@kunal7216
Copy link

Version

v22.8.0

Platform

"$([Environment]::OSVersion.VersionString) $(('x86', 'x64')[[Environment]::Is64BitOperatingSystem])"

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 '''

    import { Readable, Transform } from "node:stream";

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

console.log("beginning pipe");
objectReadable.pipe(passThrough);

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

'''

@RedYetiDev RedYetiDev closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2024
@RedYetiDev RedYetiDev added the duplicate Issues and PRs that are duplicates of other issues or PRs. label Sep 15, 2024
@RedYetiDev
Copy link
Member

Duplicate of #54945

@RedYetiDev RedYetiDev marked this as a duplicate of #54945 Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.
Projects
None yet
Development

No branches or pull requests

2 participants