Skip to content

client.query breaks if null is passed into query #628

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

Closed
davidgbe opened this issue Aug 15, 2014 · 2 comments · Fixed by #1651
Closed

client.query breaks if null is passed into query #628

davidgbe opened this issue Aug 15, 2014 · 2 comments · Fixed by #1651

Comments

@davidgbe
Copy link

This isn't too much of a concern, but if the query param is passed into client.query as null, node crashes and the callback is never made. For instance:

var query = null
client.query(query, function(err, res) {
  if(err) { } //handle err
}) 

Produces:

/Users/dbell/work/curious/node_modules/pg/lib/client.js:323
  var query = (typeof config.submit == 'function') ? config :
                            ^
TypeError: Cannot read property 'submit' of null
    at Client.query (/Users/dbell/work/curious/node_modules/pg/lib/client.js:323:29)
@joskuijpers
Copy link
Contributor

I had this too, just a day ago. I passed undefined.

We could just assert(query != null) as passing such value is a developer error.

Before you pass a query, you should check it is a valid one. Either by having no code-path that creates an undefined/null query, or just placing some if statement or such.

@brianc
Copy link
Owner

brianc commented Sep 3, 2014

Yeah an assert would probably be good here to give a better indication of what exactly is going on.

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

Successfully merging a pull request may close this issue.

3 participants