15

I'm trying to log a statement in an async function as follows:

async generateCharts (insights) {
  const { url } = await this.reportsClient.createReport(insights)
  console.log('url from reports', url)
  return this.parse(url)
}

Log statement doesn't show up though, and I'm sure it's because of the async function. Is that correct? Anyway to work around this?

3
  • I just ran your code and it works fine. Have you tried forcing createReport to fulfill to verify this? Commented Jan 30, 2017 at 17:00
  • FYI, async functions are not part of ES6 (ES2015). They will part of thies year's release, ES2017. Commented Jan 30, 2017 at 19:46
  • @MikeC looks like that would be the issue! Commented Feb 7, 2017 at 10:32

2 Answers 2

6

Note that errors are swallowed "silently" within an async function – just like inside normal Promises. Unless we add try / catch blocks around await expressions, uncaught exceptions – regardless of whether they were raised in the body of your async function or while its suspended during await – will reject the promise returned by the async function.

javascript-async-await#error-handling

Sign up to request clarification or add additional context in comments.

Comments

4

Your example lacks of context but, IMHO, that's because your createReport function never fulfills. There are no other reasons why the console.log would not get executed.

1 Comment

Same here. I had two functions with the same name. The second one took priority while I was editing the first one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.