Skip to content

Stack traces are truncated / lack client side stack trace #2470

Closed
@bluenote10

Description

@bluenote10

When 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions