fix: Resolve inconsistent usage of error variables (#10060)

* fix: Resolve inconsistent usage of error variables

* mysql2: guard nil DB on open failure and wrap connect error

---------

Co-authored-by: muminglei <muminglei@cmict.chinamobile.com>
Co-authored-by: Chris Lu <chris.lu@gmail.com>
This commit is contained in:
mumingl
2026-06-23 01:25:02 -07:00
committed by GitHub
co-authored by muminglei Chris Lu
parent 6de283ccaa
commit 16c3f5c816
+4 -2
View File
@@ -80,9 +80,11 @@ func (store *MysqlStore2) initialize(createTable, upsertQuery string, enableUpse
var dbErr error
store.DB, dbErr = sql.Open("mysql", sqlUrl)
if dbErr != nil {
store.DB.Close()
if store.DB != nil {
store.DB.Close()
}
store.DB = nil
return fmt.Errorf("can not connect to %s error:%v", adaptedSqlUrl, err)
return fmt.Errorf("can not connect to %s error:%w", adaptedSqlUrl, dbErr)
}
store.DB.SetMaxIdleConns(maxIdle)