got
got copied to clipboard
Stack trace back to client code
What problem are you trying to solve?
When a got request throws, I would like to see a stack trace back to the line in my code that generates the error.
I'm using got v13.0.0 with the node16 settings in tsconfig.json.
Describe the feature
import got from 'got';
const response = await got('http://127.0.0.1:3000').text();
console.log(response);
The output doesn't point to any line in my code:
file:///home/dandv/node_modules/got/dist/source/core/index.js:792
error = error instanceof TimedOutTimeoutError ? new TimeoutError(error, this.timings, this) : new RequestError(error.message, error, this);
^
RequestError: connect ECONNREFUSED 127.0.0.1:3000
at ClientRequest.<anonymous> (file:///home/dandv/node_modules/got/dist/source/core/index.js:792:107)
at Object.onceWrapper (node:events:629:26)
at ClientRequest.emit (node:events:526:35)
at ClientRequest.emit (node:domain:489:12)
at Socket.socketErrorListener (node:_http_client:501:9)
at Socket.emit (node:events:514:28)
at Socket.emit (node:domain:489:12)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) {
input: undefined,
code: 'ECONNREFUSED',
timings: {
start: 1693228883449,
// ...
}
},
options: Options {
_unixOptions: undefined,
_internals: {
// ...
},
_merging: false,
_init: []
}
}
Checklist
- [x] I have read the documentation and made sure this feature doesn't already exist.
- [x] I have checked related issues:
- #2277
- #1736
- #1077
Request.<anonymous> file:///Users/frank/Developer/punkpeye/glama/node_modules/.pnpm/[email protected]/node_modules/got/dist/source/as-promise/index.js:92:42\n' +
'Object.onceWrapper node:events:633:26\n' +
'Request.emit node:events:530:35\n' +
'Request._onResponseBase file:///Users/frank/Developer/punkpeye/glama/node_modules/.pnpm/[email protected]/node_modules/got/dist/source/core/index.js:609:22\n' +
'processTicksAndRejections node:internal/process/task_queues:105:5\n' +
'Request._onResponse file:///Users/frank/Developer/punkpeye/glama/node_modules/.pnpm/[email protected]/node_modules/got/dist/source/core/index.js:649:13
Same issue.
Is there a way to get a better stack trace? @sindresorhus
@dandv Looks like one of these might be the solution:
- https://github.com/sindresorhus/got/issues/1077#issuecomment-1133327848
- https://github.com/sindresorhus/got/blob/main/documentation/async-stack-traces.md#conclusion
Closing as this is a JS limitation, not a problem with Got.