Skip to content
This repository has been archived by the owner on Feb 1, 2025. It is now read-only.

Failed await should fall through to catch statement. #135

Closed
bolinfest opened this issue Nov 5, 2014 · 4 comments
Closed

Failed await should fall through to catch statement. #135

bolinfest opened this issue Nov 5, 2014 · 4 comments

Comments

@bolinfest
Copy link
Contributor

I'm not sure if this is expected to work today, but I would hope that I could do:

async function f() {
  return Promise.reject(new Error('oh no!'));
}

async function main() {
  try {
    await f();
  } catch (e) {
    // This line should print out the Error from f().
    console.error('Error: %s', e);
  }
}

main();

Ultimately, this should work with multiple await statements:

async function main() {
  try {
    var a = await b();
    var c = await d(a);
    var e = await f(c);
    // etc.
  } catch (e) {
    // This line should print out the Error from f().
    console.error('Error: %s', e);
  }
}

I put together some sample code that chains a handful of transforms together. I would really like to use async/await along with jsx and harmony features.

@bolinfest
Copy link
Contributor Author

I also hope that, once combined with jstransform, the following works:

var [first, second] = await Promise.all([getFirstPromise(), getSecondPromise()]);

though it would be even more slick if we could remove some of that syntax.

@benjamn benjamn closed this as completed in 20f0518 Nov 6, 2014
@benjamn
Copy link
Contributor

benjamn commented Nov 6, 2014

@bolinfest thank you very much for drawing my attention to this bug! As you can see from the fix (20f0518), the mistake was simple but the consequences were profound.

@bolinfest
Copy link
Contributor Author

Gotta love a two line fix! I don't know how hard it is to set up, but I'd humbly request a unit test for that one.

bolinfest added a commit to bolinfest/es-next-fun that referenced this issue Nov 6, 2014
Now that facebook/regenerator#135 is fixed,
this works like a charm.
@benjamn
Copy link
Contributor

benjamn commented Nov 6, 2014

@bolinfest 40384de ;)

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants