node-source-map-support icon indicating copy to clipboard operation
node-source-map-support copied to clipboard

Node 12 "async" annotations are lost when using this package

Open alcuadrado opened this issue 6 years ago • 3 comments
trafficstars

Node 12 added some limited support for async stack traces. I'm impressed that this package supports them, but it removes a useful annotation from them:

Given this file:

function p() {
  return new Promise(resolve => setTimeout(resolve, 0))
}

async function f() {
  await p()
  throw Error("")
}

async function main() {
  await f()
}

main()
  .catch(console.error)

The stack traces without registering source-map-support is:

Error
    at f (/private/tmp/async-stack-traces/index.js:9:9)
    at async main (/private/tmp/async-stack-traces/index.js:13:3)

With source-map-support registered is:

Error:
    at f (/private/tmp/async-stack-traces/index.js:9:9)
    at main (/private/tmp/async-stack-traces/index.js:13:3)

I think the async annotation there is useful, as this stack trace is not the actual one as seen by v8, but an augmented one. This augmentation doesn't always work, and it would be surprising to the user if they look like normal stack traces.

alcuadrado avatar May 28 '19 01:05 alcuadrado

Can confirm, this is super confusing as I wasn't sure what was causing it and I wasn't sure if my stack traces were actually working. Several hours later I found this issue.

justinmchase avatar Aug 03 '20 17:08 justinmchase

Would love a PR addressing this 🚀

LinusU avatar Nov 16 '20 10:11 LinusU

To fix this, the implementation of CallSiteToString -- which is copy-pasted from V8 source code -- must be updated to match the latest V8 implementation.

https://github.com/v8/v8/blob/dc712da548c7fb433caed56af9a021d964952728/src/objects/stack-frame-info.cc#L344-L393

cspotcode avatar Jul 20 '21 05:07 cspotcode