Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection error messages stacks only contain functions in node-postgres #1794

Closed
jonganc opened this issue Dec 24, 2018 · 5 comments
Closed

Comments

@jonganc
Copy link

jonganc commented Dec 24, 2018

For example

const db = new Pool({
  connectionString: 'postgresql://...@localhost:5432/...'
});
db.query('SELECT, * FROM test1');

generates the rather unhelpful stack

{ error: syntax error at or near ","
    at Connection.parseE (.../node_modules/pg/lib/connection.js:554:11)
    at Connection.parseMessage (.../node_modules/pg/lib/connection.js:379:19)
    at Socket.<anonymous> (.../node_modules/pg/lib/connection.js:119:22)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  [stack]:
   'error: syntax error at or near ","\n    at Connection.parseE (.../node_modules/pg/lib/connection.js:554:11)\n    at Connection.parseMessage (.../node_modules/pg/lib/connection.js:379:19)\n    at Socket.<anonymous> (.../node_modules/pg/lib/connection.js:119:22)\n    at Socket.emit (events.js:182:13)\n    at addChunk (_stream_readable.js:283:12)\n    at readableAddChunk (_stream_readable.js:264:11)\n    at Socket.Readable.push (_stream_readable.js:219:10)\n    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)',
  [message]: 'syntax error at or near ","',
  ...}

Note, in particular, the absense of line numbers in my code, only in the node-postgres code.

It's easy enough to fix this outside of the package. I can just add something like

function withError(queryFunc) {
  return async function(query) {
    try {
      const res = await queryFunc.call(this, query);
    } catch (e) {
      throw new VError(e, 'pg error');
    }
  };
}
db.query = withError(db.query);

and then we get the error info.

I'm guessing this has something to do with the error being thrown by a listener or something (?)?

@joelmukuthu
Copy link

It’s a Node.js issue, see
#1762

@jonganc
Copy link
Author

jonganc commented Dec 24, 2018

Huh. Yeah, I suppose it is due to nodejs/node#11865 ultimately. But I do wonder if there's a workaround, since it's quite simple to wrap query so you get the error stack (as I show above)...

@joelmukuthu
Copy link

I’m not a maintainer so I can’t say for certain, but I think this shouldn’t be handled in this library. It has actually been fixed in Node v12 (atm behind a feature flag I think) so I’d recommend your own workaround for now. Once again, just my opinion :)

@jonganc
Copy link
Author

jonganc commented Dec 24, 2018

Yeah, if the only way to do it is to wrap it using something like VError on the package-level, I could see how the package would rather avoid that. Still, I'm curious if a maintainer will chime in, if only for future reference.

@jonganc
Copy link
Author

jonganc commented Jan 8, 2019

So yeah, my workaround doesn't work. It's an underlying Node issue (that actually has been fixed). So... I'll close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants