14

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?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
SamAko
  • 3,485
  • 7
  • 41
  • 77

2 Answers2

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

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.

Traan
  • 134
  • 1
  • 4
  • Same here. I had two functions with the same name. The second one took priority while I was editing the first one. – Max Mar 15 '23 at 10:02