Node-postgres: Pool.query() does not throw error with full stack trace

Created on 5 Nov 2018  Â·  12Comments  Â·  Source: brianc/node-postgres

Issue of Pool.query().

Errors which are throw form Pool.query() does not contains full error stack trace. Please throw standard error with full stack trace.

Most helpful comment

maybe because node-pg doesn't use native promises or native async functions?

with the 9.0 internals re-write i'll be starting as soon as I can catch my emotional breath I'm going to investigate switching fully async/await (as much as possible) internally. We'll see how the perf of that is, but if that works you _might_ just get this (and every other feature ever since it's open source) for free!

All 12 comments

Hi, could you post the incomplete stack trace and the code that generates the error? Without knowing more about your case however, I’m guessing that it might have something to do with this infamous bug in node/V8, which can’t be fixed in this library

Hi Joe,

Yes, I got it, my case is similar like that. Now I know that we can't fix it in this library. What can we do in this case?, or just wait for node.js team?.

You can try some of the workarounds suggested in that issue:

const bluebird = require('bluebird');
const { Client, Pool } = require('pg');

const pool = new Pool({
  Promise: bluebird
});

// for this one, only available in [email protected] and up:
const client = new Client({
  Promise: bluebird
});

Thank Joel, I will try all of it. I also let this issue is open to show that it should be solve, some how.

@joelmukuthu’s covered it all; stack traces get lost by default in JavaScript when asynchronous tasks aren’t direct calls.

Now that zero-cost async stack traces are part of Node (v12) by default, it would be great if this could be reconsidered. I'm not sure what the reason is that this is still broken in node-pg, maybe because node-pg doesn't use native promises or native async functions?

I'm not sure what the reason is that this is still broken in node-pg

the reason is this project has been maintained almost entirely by myself and 1 other person for the past decade and we're buried under bug reports, feature requests, internal priorities. Also, the world has fallen into a global pandemic causing me significant anxiety attacks. Also, we still support versions of node back to 6.0.

maybe because node-pg doesn't use native promises or native async functions?

with the 9.0 internals re-write i'll be starting as soon as I can catch my emotional breath I'm going to investigate switching fully async/await (as much as possible) internally. We'll see how the perf of that is, but if that works you _might_ just get this (and every other feature ever since it's open source) for free!

No problem, sorry that I appeared to be demanding stuff for free. Mainly I think this issue could be reopened, since the original reason where this was not possible at all due to node restrictions is gone.

ah gotcha! Yeah no worries - I get a _lot_ of email and you know tone of
voice and stuff doesn't carry well over text. :p I'll definitely keep
this in mind when I'm working on performance over the next few months. I
also think the current stack traces are gross and hard to deal with so I'm
all for fixing them! First up I want to get perf up a bit - some benchmarks
locally w/ some experiments I've done are showing upwards of 40-50% speed
increase in some cases.

On Mon, Mar 30, 2020 at 10:37 AM phiresky notifications@github.com wrote:

No problem, sorry that I appeared to be demanding stuff for free. Mainly I
think this issue could be reopened, since the original reason where this
was not possible at all due to node restrictions is gone.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/brianc/node-postgres/issues/1762#issuecomment-606074863,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAMHINOVYGALRGTSRRGHWLRKC4DRANCNFSM4GBW5KYA
.

Not sure if I'm doing something wrong, but nothing in the above conversation or similar ones elsewhere worked.

This is what I did, works and doesn't require more dependencies. Dunno if it'll work on older Node versions.

const executeSql = async function(conn, q, args) {
  // gets the stack before the error, otherwise it's the emitResult stuff
  const stack = new Error().stack 
  try {
    return await conn.query(q, args)
  } catch(err) {
    console.error(stack)
    throw err
  }
}

I'm not sure what the reason is that this is still broken in node-pg

the reason is this project has been maintained almost entirely by myself and 1 other person for the past decade and we're buried under bug reports, feature requests, internal priorities. Also, the world has fallen into a global pandemic causing me significant anxiety attacks. Also, we still support versions of node back to 6.0.

A big thank you. I don't know how popular FOSS maintainers do it all 👍 .

I have the same problem. I am scared to use different types of promises and watnot. I am just going to try console logging before any DB operation, then I can see roughly when the EX happened. Obviously my use case is low volume!

Was this page helpful?
0 / 5 - 0 ratings