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

Iterator helpers throw the error too late #41648

Closed
benjamingr opened this issue Jan 22, 2022 · 9 comments · Fixed by #41652
Closed

Iterator helpers throw the error too late #41648

benjamingr opened this issue Jan 22, 2022 · 9 comments · Fixed by #41652
Labels
confirmed-bug Issues with confirmed bugs. stream Issues and PRs related to the stream subsystem.

Comments

@benjamingr
Copy link
Member

benjamingr commented Jan 22, 2022

Currently iterator helpers throw type errors on first iteration - they should likely do so synchronously.

For example:

Readable.from([1]).map(1); // returns a stream, for...awaiting it will throw the error

Instead I think we should throw synchronously, which is what I believe the spec says.

A fix would be to take the code in operators.js that does validations that is in an async generator and wrap it so that it does those validations in a function called before the async generator.

So instead of:

async function* map(...) {
  validateFoo(...);
}

We'd do:

function map(...) { // not async to throw synchronously
  validateFoo(...);
  return async function*() {

  }();
}

The test at test-stream-map would similarly need to be updated from rejecting asynchronously on iteration to throwing synchronously. I've opened an issue in the iterator helper proposal to be sure.

That's my understanding here: https://tc39.es/proposal-iterator-helpers/#sec-asynciteratorprototype.map

@targos
Copy link
Member

targos commented Jan 22, 2022

If you want to open an issue without using a template, you can go to https://github.com/nodejs/node/issues/new

@benjamingr
Copy link
Member Author

@targos TIL, thanks!

@benjamingr
Copy link
Member Author

I'm opening an issue rather than a fix since I think this issue is a good place for people other than myself and ronag to get involved with the iterator-helpers initiative :)

@benjamingr benjamingr added good first issue Issues that are suitable for first-time contributors. stream Issues and PRs related to the stream subsystem. labels Jan 22, 2022
@benjamingr benjamingr changed the title Iterator helpers throw the error too late? Iterator helpers throw the error too late Jan 22, 2022
@benjamingr
Copy link
Member Author

Confirmed the behavior should be to throw synchronously with the proposal - so this is a bug that should be fixed.

@ljharb
Copy link
Member

ljharb commented Jan 22, 2022

Is the intention for stream methods to match the iterator helpers interface?

@benjamingr
Copy link
Member Author

@ljharb the intention to add most iterator helper proposal methods to the node streams interface.

I intend Node to pass the tc39 tests as much as possible (read: all of them) and would strongly prefer not to move these methods out of "experimental" until the proposal gets to (at least) stage 3.

There are some divergences that exist (for example - tc39/proposal-iterator-helpers#162 which is why I asked for future-compatibility there).

In addition - if/when the spec changes I believe Node.js should change its implementation to align.

@benjamingr
Copy link
Member Author

(This is a good area to be involved in by the way!)

@iMoses
Copy link
Contributor

iMoses commented Jan 22, 2022

@benjamingr I'll happily take this, does seem like a great starting point to get involved :)

@benjamingr benjamingr removed the good first issue Issues that are suitable for first-time contributors. label Jan 22, 2022
@benjamingr
Copy link
Member Author

@iMoses great, let me know if you need help getting started - the sooner we land this the better since these APIs are shipping :)

iMoses added a commit to iMoses/node that referenced this issue Jan 22, 2022
`streams/operators/map` is no longer a generator function, instead it returns a called generator
so that validation can happen synchronously and not wait for the first iteration

Fixes: nodejs#41648
iMoses added a commit to iMoses/node that referenced this issue Jan 25, 2022
`streams/operators/map` is no longer a generator function,
instead it returns a called generator so that validation can be
synchronous and not wait for the first iteration

Fixes: nodejs#41648
iMoses added a commit to iMoses/node that referenced this issue Jan 26, 2022
`streams/operators/map` is no longer a generator function,
instead it returns a called generator so that validation can be
synchronous and not wait for the first iteration

Fixes: nodejs#41648
iMoses added a commit to iMoses/node that referenced this issue Jan 26, 2022
 is no longer a generator function,
instead it returns a called generator so that validation can be
synchronous and not wait for the first iteration

Fixes: nodejs#41648
iMoses added a commit to iMoses/node that referenced this issue Jan 26, 2022
 is no longer a generator function,
instead it returns a called generator so that validation can be
synchronous and not wait for the first iteration

Fixes: nodejs#41648
iMoses added a commit to iMoses/node that referenced this issue Jan 27, 2022
 is no longer a generator function,
instead it returns a called generator so that validation can be
synchronous and not wait for the first iteration

Fixes: nodejs#41648
nodejs-github-bot pushed a commit that referenced this issue Jan 27, 2022
 is no longer a generator function,
instead it returns a called generator so that validation can be
synchronous and not wait for the first iteration

Fixes: #41648

PR-URL: #41652
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Linkgoron pushed a commit to Linkgoron/node that referenced this issue Jan 31, 2022
 is no longer a generator function,
instead it returns a called generator so that validation can be
synchronous and not wait for the first iteration

Fixes: nodejs#41648

PR-URL: nodejs#41652
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
ruyadorno pushed a commit that referenced this issue Feb 8, 2022
 is no longer a generator function,
instead it returns a called generator so that validation can be
synchronous and not wait for the first iteration

Fixes: #41648

PR-URL: #41652
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
danielleadams pushed a commit to danielleadams/node that referenced this issue Apr 21, 2022
 is no longer a generator function,
instead it returns a called generator so that validation can be
synchronous and not wait for the first iteration

Fixes: nodejs#41648

PR-URL: nodejs#41652
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants