evanw/node-source-map-support

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

开放

#243 创建于 2019年5月28日

 (3 条评论) (6 个反应) (0 位负责人)JavaScript (221 个派生)batch import
bughelp wanted

仓库指标

星标
 (2,195 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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.

贡献者指南