GeezerVison is showing github.com — incomplete stack · Issue #31297 · nodejs/node
Labels invalidIssues and PRs that are invalid. Description
- Version: v10.15.2
- Platform: Linux cees-XPS-13-9380 4.15.0-1065-oem Deprecate domains #75-Ubuntu SMP Wed Nov 20 10:51:26 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
- Subsystem:
const http = require('http')
function includemeplz() {
//throw new Error() // works fine
http.request({}).on('error', err => console.log('onerror', err.stack)) // not in stack!
}
includemeplz()
Maybe a duplicate of #11865 but that's closed and the issue still occurs with Node 13 on https://npm.runkit.com/ Activitybnoordhuis commented on Jan 11, 2020 The Error object includes a stack trace up to but not including your callback. That's working as expected.
Think about it, if f calls g as infunction f() { var e = new Error(); g(e) }, how could g show up in the stack trace? It isn't on the stack yet when the stack trace is captured. Hakerh400 commented on Jan 11, 2020 I think OP is talking about includemeplz function missing from the stack, not the callback itself.
@CTimmerman The function is not in the stack trace because the error is thrown asynchronously, so the context where the error is constructed is outside your function. If you replace it with any asynchronous function that takes a callback (for example setTimeout) and throw an error directly from the callback, you will notice that the wrapper function is elided from the stack.
Theoretically, Node.js can internally save the call stack info upon an asynchronous function scheduling and, if an error occurs, throw the error with reconstructed stack trace, or use async stack traces. However, it may have a large performance impact (see #30944 for example).
Maybe a duplicate of #11865
No, that issue is unrelated. Reacted by Cees Timmerman CTimmerman commented on Jan 14, 2020 I don't see how remembering the place where the async function was started would cause a significant performance issue. bnoordhuis commented on Jan 14, 2020 Capturing call stacks isn't free: it takes time and memory linear to the depth of the stack. That memory is the sticking point: it needs to stay around until the promise isn't observable anymore; effectively, until the promise is garbage-collected. CTimmerman commented on Jan 14, 2020
Capturing call stacks isn't free: it takes time and memory linear to the depth of the stack. That memory is the sticking point: it needs to stay around until the promise isn't observable anymore; effectively, until the promise is garbage-collected.
True, hence adding a single line to the stack, and maybe a "..." for the millions of skipped ones you seem to imply, should make the stack useful again.
Also the same problem happens when the containing function is async:
const axios = require("axios")
process.on('unhandledRejection', (err, p) => console.log(err.stack))
;(async function includemeplz() {
await axios.get('/')
})()
bnoordhuis commented on Jan 14, 2020 Even a single-frame call stack isn't cheap (enough). If it was, we would have done it a long time ago.
There's plenty of infrastructure for long stack traces (async_hooks, the inspector) and several npm modules exist that utilize it but it's not enabled by default. See #31080 for a proposal. CTimmerman commented on Jan 14, 2020
Even a single-frame call stack isn't cheap (enough). If it was, we would have done it a long time ago.
Error: connect ECONNREFUSED 127.0.0.1:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1104:14)
That's a stack frame i don't care about so would prefer to see this:
Error: connect ECONNREFUSED 127.0.0.1:80
at includemeplz (/home/cees/code/tester/test.js:17:8)
MetadataMetadatainvalidIssues and PRs that are invalid. DevelopmentNo branches or pull requestsIssue actions
|