Skip to content

Commit 590508a

Browse files
committed
prevent ErrBadConn from driver.Open()
because it seems this error is only meant to be internal, and if `ErrBadConn` is returned from here it can also be returned from the public api See some confusion about this here: go-sql-driver/mysql#1020 And a fix in the postgres driver here: lib/pq@04c77ed
1 parent 0f55994 commit 590508a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/database/sql/sql.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,11 @@ type dsnConnector struct {
685685
}
686686

687687
func (t dsnConnector) Connect(_ context.Context) (driver.Conn, error) {
688-
return t.driver.Open(t.dsn)
688+
conn, err := t.driver.Open(t.dsn)
689+
if err == driver.ErrBadConn {
690+
return conn, fmt.Errorf("sql: driver open() returned ErrBadConn. ErrBadConn should only be returned from existing connections")
691+
}
692+
return conn, err
689693
}
690694

691695
func (t dsnConnector) Driver() driver.Driver {

0 commit comments

Comments
 (0)