Stack traces are truncated / lack client side stack trace
See original GitHub issueWhen pg
throws an error, I often have trouble finding the place in my code where this is actually coming from. For some reasons the exceptions thrown by pg
seem to contain strange stack trace, and in particular, the stack trace doesn’t contain any client side code. I’m actually on TypeScript running through ts-node
, but I think I can reproduce the behavior with plain JS. Here is a minimal example:
const pg = require("pg");
async function provokeExceptionPg() {
let client = new pg.Client();
await client.connect();
}
provokeExceptionPg().catch((err) => console.log(err));
The output of running node index.js
is just:
Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432
}
Note that the output is completely lacking any information of client side code, which in this case would just be my index.js
. To demonstrate the kind of traceback I’d expect, I can for instance replace new pg.Client()
by something broken like new pg.ClientNonexisting()
. This results in a stack trace that clearly shows the client side stack leading to the error:
TypeError: pg.ClientNonexisting is not a constructor
at provokeExceptionPg (/tmp/test_project/index.js:4:16)
at Object.<anonymous> (/tmp/test_project/index.js:8:1)
[...]
The lack of client side stack traces makes it very hard to understand where errors are coming from in a more complex code base. Is there any way to get more meaningful stack traces out of pg
or would that make sense as a feature request?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:7 (1 by maintainers)
Top GitHub Comments
It seems that using bluebird is not a future-proof solution. Take a look at this warning.
As a workaround, here is this wrapper around native promises to augment stack traces
It can be used with node-postgres as follows
Bring your own promise -
Bluebird
, and enable Long Stack Traces.