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

"There is no pool defined on the current client" is a bad error message #1583

Closed
krainboltgreene opened this issue Jul 19, 2016 · 9 comments
Closed

Comments

@krainboltgreene
Copy link

Search for this message in the issue list and you'll get quite a few issues where they ALL have entirely different source problems. Ranging from: No environment defined, bad client name, no client key defined, no connection defined, etc.

Instead we need better messages about our client, type constrained if possible. I should know when I accidentally type pgsql instead of pg or postgres. I should know when my configuration is missing the client key, a pretty freaking important key.

@hulbert
Copy link
Contributor

hulbert commented Jul 20, 2016

Can we outline specifically each case since they may need to be addressed separately? Starting with your list:

  1. No environment defined
  2. incorrect client name in knex configuration, e.g. psql instead of pg
  3. no client key defined -- not sure what this means?
  4. incorrect connection configuration
  5. there is also the case where the pool is destroyed; this is not a configuration issue and could potentially use a more descriptive error message potentially with a link to a wiki page like Angular & React do

I use Hapijs a lot and they do a good job of configuration checking. Keep in mind w/r/t configuration validation for knex, the docs list a supported case (see below) that makes this pretty darn hard (missing configuration, though perhaps it can be deferred until a query is issued to the datbase--i.e. with a promise or callback):

var knex = require('knex')({}); // configure w/ empty object
var pg = require('knex')({client: 'pg'}); // configure without connection

knex('table').insert({a: 'b'}).returning('*').toString();
pg('table').insert({a: 'b'}).returning('*').toString();

@krainboltgreene
Copy link
Author

Here's an example of "no client key defined"

var pg = require('knex')({adapter: 'pg'});

@gotoAndBliss
Copy link

"There is no pool defined on the current client" gets returned for any psql error. For example, a validation UNIQUE error would return this for me.

Knowing that this error is the catch all error for any error that comes from psql, I was curious if anyone had a way to step in before this error? Is there a way to log psql directly without knex failing generically ( and in this case incorrectly )?

@tgriesser
Copy link
Member

@gotoAndBliss this message has been changed to "Unable to acquire a connection" in 0.12 which is more indicative of the actual error. It should only occur if you have either not supplied a proper connection configuration or have already called knex.destroy() and the connection pool has drained and cleaned up.

I don't see how you'd be seeing this error if the client is properly configured.

@gotoAndBliss
Copy link

gotoAndBliss commented Sep 22, 2016

I'm using Knex@0.12.1 -- And can confirm it returns that same message There is no pool defined on the current client. This is a new PG install on a windows box where as I knew the same code worked for my Mac. So I'm guessing there's something corrupt about PG. I understand this is amiss from the OP, but any idea @tgriesser , how I could debug this? My PSQL server is running, I can log into it and add content with the same credentials supplied in my Knex config.

@tgriesser
Copy link
Member

@gotoAndBliss if you are on 0.12.1, the message couldn't be "There is no pool defined on the current client", that line is no longer anywhere in the codebase.

Maybe run setting env to DEBUG=knex:* to see if there's any output from the pool or otherwise that helps?

@gotoAndBliss
Copy link

@tgriesser That helped me solve it. Thanks so much for your help.

@tgriesser
Copy link
Member

Yep!

@krainboltgreene
Copy link
Author

🎉 Kudos on picking a more descriptive error message. This should definitely help future users avoid time wasted.

👍

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

No branches or pull requests

5 participants