Fix malformed error message in ReadableStream.getReader

The error message for an invalid 'mode' argument in ReadableStream.getReader
was missing the "must be" part, resulting in a confusing error message like:
"The argument 'mode' byob. Received 'invalid'"

This fix updates the error message to properly say:
"The argument 'mode' must be 'byob'. Received 'invalid'"

A regression test has been added to ensure the error message is correct.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2025-10-22 07:50:42 +00:00
parent 7662de9632
commit 4dd2b5989f
2 changed files with 15 additions and 1 deletions

View File

@@ -395,7 +395,7 @@ export function getReader(this, options) {
return new ReadableStreamBYOBReader(this);
}
throw $ERR_INVALID_ARG_VALUE("mode", mode, "byob");
throw $ERR_INVALID_ARG_VALUE("mode", mode, "must be 'byob'");
}
export function pipeThrough(this, streams, options) {

View File

@@ -1142,3 +1142,17 @@ it("pipeThrough doesn't cause unhandled rejections on readable errors", async ()
expect(unhandledRejectionCaught).toBe(false);
});
it("ReadableStream.getReader with invalid mode should show correct error message", () => {
const stream = new ReadableStream();
// Test with invalid mode value
try {
stream.getReader({ mode: "invalid" });
expect.unreachable("Should have thrown an error");
} catch (error) {
expect(error.code).toBe("ERR_INVALID_ARG_VALUE");
expect(error.message).toContain("must be 'byob'");
expect(error.message).toContain("mode");
}
});