Когда я делаю
conn = PGconn.connect("localhost", 5432, "" , "", db_name, postgres_username, postgres_password)
и пароль неверный, выдается исключение (PG :: ConnectionBad) (чего я и ожидал)
begin
conn = PGconn.connect("localhost", 5432, "" , "", db_name, postgres_username, postgres_password)
# Do some stuff
rescue PG::ConnectionBad => e
puts e
raise # reraise exception
rescue Exception => e
puts e
raise # reraise exception
ensure
conn.close if conn
end
когда я делаю "ставит е", я получаю
FATAL: password authentication failed for user "[email protected]"
FATAL: password authentication failed for user "[email protected]"
То есть сообщение об ошибке повторяется.
я использую
PostgreSQL 9.6.3 на x86_64-pc-linux-gnu, скомпилирован gcc (Ubuntu 5.4.0-6ubuntu1 ~ 16.04.4) 5.4.0 20160609, 64-разрядная версия
ruby 2.4.1p111 (22.03.2017 редакция 58053) [x86_64-linux]
Ubuntu 16.04
Это ошибка? Этого следовало ожидать?

Следующее - это хитрость и не раскрывает сути вопроса. Это просто устраняет симптом проблемы.
«Ответ» намеренно многословен.
begin
conn = PGconn.connect("localhost", 5432, "" , "", db_name, postgres_username, postgres_password)
# Do some stuff
rescue PG::ConnectionBad => e
# There seems to be a bug in PG::ConnectionBad where the error message is doubled. Get only a single error message
puts e
theDoubledMsg = e.to_s
theSingleMsg = theDoubledMsg.split("\n")[0]
# See https://stackoverflow.com/questions/2823748/how-do-i-add-information-to-an-exception-message-in-ruby
raise $!, theSingleMsg, $!.backtrace
rescue Exception => e
puts e
raise # reraise exception
ensure
conn.close if conn
end
Язык программирования - Ruby. Мои извинения за то, что не разъяснили это.