From bb8e0a9d84643e98a488f34f0d0086d463b8e30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=88r=20Karlsson?= Date: Tue, 28 Jul 2015 16:29:56 +0200 Subject: [PATCH] Fixed issue https://github.com/jinzhu/gorm/issues/151 where postgresql connection problems fail silently --- main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.go b/main.go index aba51fc4..1490b43d 100644 --- a/main.go +++ b/main.go @@ -59,6 +59,13 @@ func Open(dialect string, args ...interface{}) (DB, error) { driver = "postgres" // FoundationDB speaks a postgres-compatible protocol. } dbSql, err = sql.Open(driver, source) + + // For some reason, postgres does not throw an connection error. + // Sending a ping request after the connection is made is a quick workaround for this + if driver == "postgres" && err != nil { + err = db.DB().Ping() + } + case sqlCommon: source = reflect.Indirect(reflect.ValueOf(value)).FieldByName("dsn").String() dbSql = value