porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.09k stars 259 forks source link

`console.log(error)` doesn't show full Postgres error #767

Open nikhilro opened 6 months ago

nikhilro commented 6 months ago

Hey, not an issue since I solved it but think others might run into this.

I was trying to access the Postgres error for a foreign key constraint violation. I wasn't sure of the schema. So, I thought to print it but nothing worked:

      console.log(
        Object.keys(e),
        Object.getOwnPropertyNames(e),
        Object.getOwnPropertyDescriptors(e),
        Reflect.ownKeys(e),
      )

These all outputted: [ 'stack', 'query', 'parameters', 'args', 'types' ].

Ultimately looking at the type helped: https://github.com/porsager/postgres/blob/6f20a4820c683b33e7670b606d8daf5670f4b973/types/index.d.ts#L201