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

ReadableStream.from({}) returns confusing error #53819

Closed
rotu opened this issue Jul 12, 2024 · 7 comments · Fixed by #53825
Closed

ReadableStream.from({}) returns confusing error #53819

rotu opened this issue Jul 12, 2024 · 7 comments · Fixed by #53825

Comments

@rotu
Copy link

rotu commented Jul 12, 2024

Version

v22.4.1

Platform

Darwin Hypothesis.local 24.0.0 Darwin Kernel Version 24.0.0: Mon Jul  1 21:58:28 PDT 2024; root:xnu-11215.0.132.501.1~1/RELEASE_ARM64_T8103 arm64

Subsystem

No response

What steps will reproduce the bug?

ReadableStream.from({})

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

It should show a more descriptive error message. Maybe "value is not iterable".

What do you see instead?

> ReadableStream.from({})
Uncaught TypeError: FunctionPrototypeCall is not a function
    at getIterator (node:internal/webstreams/util:246:20)
    at getIterator (node:internal/webstreams/util:238:36)
    at readableStreamFromIterable (node:internal/webstreams/readablestream:1315:26)
    at ReadableStream.from (node:internal/webstreams/readablestream:311:12)

Additional information

No response

@rotu
Copy link
Author

rotu commented Jul 12, 2024

Note there is another apparent bug here. For some reason, FunctionPrototypeCall is reporting its own name instead of its first argument. That is, the faulting line should probably print an error that says: "'method' is not a function"

https://github.com/nodejs/node/blob/fc233627ed447be0bb893d8cba8e3ff1eba58658/lib/internal/webstreams/util.js#L246C3-L246C55

  const iterator = FunctionPrototypeCall(method, obj);

Edit: reported issue in V8 https://issues.chromium.org/issues/352528966

@RedYetiDev
Copy link
Member

The way I see it, the error message content displayed is a V8 bug, but the fact that it even got to that error (and not a validation error) may be an issue with Node.js.

@RedYetiDev RedYetiDev added stream Issues and PRs related to the stream subsystem. web streams and removed stream Issues and PRs related to the stream subsystem. labels Jul 12, 2024
@jakecastelli
Copy link
Member

jakecastelli commented Jul 12, 2024

Had a quick look, I think something like this would prevent it:

diff --git a/lib/internal/webstreams/util.js b/lib/internal/webstreams/util.js
index cce67d5b04..2b043f987c 100644
--- a/lib/internal/webstreams/util.js
+++ b/lib/internal/webstreams/util.js
@@ -243,6 +243,10 @@ function getIterator(obj, kind = 'sync', method) {
     }
   }
 
+  if (method === undefined) {
+    throw new ERR_INVALID_STATE.TypeError('The object is not iterable');
+  }
+
   const iterator = FunctionPrototypeCall(method, obj);

@debadree25 any idea?

@debadree25
Copy link
Member

debadree25 commented Jul 12, 2024

I believe that method is a 1-1 mapping of https://tc39.es/ecma262/#sec-getiterator and we are missing Step 1.b.ii and Step 3. so i think you diff should solve it @jakecastelli

@jakecastelli
Copy link
Member

Thanks! I am not too familiar with webstream and wpt (roughly know the idea) do we need to add a test for this in our test/parallel or should this test be ideally in wpt upstream.

@debadree25
Copy link
Member

I think test/parallel should be fine

@rotu
Copy link
Author

rotu commented Jul 12, 2024

I believe that method is a 1-1 mapping of https://tc39.es/ecma262/#sec-getiterator and we are missing Step 1.b.ii and Step 3. so i think you diff should solve it

It seems to have started from GetIterator but it has an extra parameter and seems to have absorbed GetIteratorFromMethod. The recursive call here of getIterator seems to be a slight code smell.

targos pushed a commit that referenced this issue Aug 14, 2024
PR-URL: #53825
Fixes: #53819
Refs: #53819
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
targos pushed a commit that referenced this issue Sep 21, 2024
PR-URL: #53825
Fixes: #53819
Refs: #53819
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
targos pushed a commit that referenced this issue Oct 2, 2024
PR-URL: #53825
Fixes: #53819
Refs: #53819
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants