Node: Async generator: catched error on last yield is wrongly rethrown

Created on 19 Feb 2020  路  3Comments  路  Source: nodejs/node

  • Version: v13.9.0
  • Platform: Linux and MacOS
  • Subsystem: ?

Also reproduced in v12 but not in v10 or v11.

What steps will reproduce the bug?

async function* gen() {
  try {
    yield 42
  } catch(e) {
    console.log('Error caught!')
  }
}

(async () => {
  const g = gen()
  await g.next() // go to yield 42
  try {
    await g.throw(new Error()) // throw error from the yield
  } catch (e) {
    console.error('e has been rethrown !')
  }
})()

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

This happens only:

  • with async generators
  • on the last yield
  • without any explicit return (in the generator)

What is the expected behavior?

g.throw() should return a result { done: true, value: undefined }

What do you see instead?

g.throw() rethrows the error.

Additional information

V8 Engine confirmed-bug

All 3 comments

Was this page helpful?
0 / 5 - 0 ratings