got: Async stack traces for callback errors
What problem are you trying to solve?
I need to know the caller that generated a given http error.
Describe the feature
I use node 13 which has async stack traces but I don’t have the caller stack trace when using got. Instead I get this stack:
err HTTPError: Response code 404 (Not Found)
at EventEmitter.<anonymous> (.../node_modules/got/dist/
source/as-promise.js:118:31)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
name: 'HTTPError'
}
I guess this happens because the connection can be used by multiple callers but there should be a way to have the whole stack.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 23 (3 by maintainers)
Commits related to this issue
- Fix `options.context` being not extensible Fixes #1077 — committed to bruceauyeung/got by szmarczak 4 years ago
async_hooksis now [almost] stable >=13.10.0 https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V13.md/#notable-changes-1Could we use
async_hookssomehow to improve the stack traces?Also in case it’s helpful to any future readers using TypeScript, here’s my working TypeScript version
Adding the
sourceproperty to the error object was causing issues so I just decided to append to the existing stack.https://github.com/sindresorhus/got/blob/main/documentation/async-stack-traces.md#conclusion
@szmarczak thank you for crafting this document!
@szmarczak This approach works. Our team used in many projects that involved multiplexing a connection or a event emitter. The only think I would worry about is the CPU load associated with generating the stack.
Maybe stack trace generation performance has improved in the last years. I have seen some articles talking about zero cost async stack traces but I’m not sure if it applies:
We could, but:
I think we should create another
.mdfile and show how to achieve the desired result step-by-step.