ActiveRecord::NoDatabaseError is so scary and misleading

I was moving a large PostgreSQL database to a new machine.

After completing the operations I restarted the Rails application with the new database IP and I start getting this error:

ActiveRecord::NoDatabaseError We could not find your database

This is scary!

Fortunately I realized in a few minuets that the problem was that I modified the pg_hba.conf but I forgot to restart. After the restart the error was solved.

Maybe a much more useful error would have been:

We cannot connect to the postgresql database.

For debugging you can use psql -h HOST -p PORT -U USER DB

(replacing the uppercase variables with the actual values of the database.yml)

I’d say it’s a good idea to not expose any details in this error. The debugging effort would first check those things anyway. I don’t think it’s a good idea to expose this as a possible accidental disclosure of credentials.

Host, port, user, db name are not secrets.

The message above would be much more useful for debugging.

No, they’re not secrets, but they’re 3/4 of the way to getting in.

I 100% agree, yours would be more useful for debugging.

There will be a reason they’re not disclosed on the logs, and I’d bet my answer is pretty close to the mark.