Let's say you have some fairly complicated node.js service, and one day you'll see something like that in its logs:
Error: getaddrinfo ENOTFOUND not-existing-host.com not-existing-host.com:80
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
Note - there's no stack trace. How would you find the place error is generated, given that there are tons of places in your service that do http calls?
Is there any solution that would allow to keep the stack trace (I don't care about the performance implication, clean stack traces are way more important)?
Seems like require('longjohn') could help, but it somehow works not very reliably and sometimes not print the stack trace (can't create an example to demonstrate that) is there any other solutions?
Code example that would generate such error. I used http as an example, but it's true for any async function.
const request = require('request');
// Let's say we write some helper function that wraps "request.js"
async function get(url) {
return new Promise((resolve, reject) => {
request(url, function (error, response, body) {
error ? reject(error) : resolve(body)
})
})
}
// Running
async function run() {
console.log(await get('http://not-existing-host.com'))
}
run()
.catch((e) => {
console.log(e.stack)
process.exit()
})
P.S.
If it could help - I use TypeScript and it provides some ways to instrument async/await implementation. Currently I enabled ES8 output, so it TypeScripts outputs node.js native async/await.