Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return init dialector error #7379

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) {
return isConfig && !isConfig2
})

var skipAfterInitialize bool
for _, opt := range opts {
if opt != nil {
if applyErr := opt.Apply(config); applyErr != nil {
return nil, applyErr
}
defer func(opt Option) {
if skipAfterInitialize {
return
}
if errr := opt.AfterInitialize(db); errr != nil {
err = errr
}
Expand Down Expand Up @@ -187,6 +191,10 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) {
if db, _ := db.DB(); db != nil {
_ = db.Close()
}

// DB is not initialized, so we skip AfterInitialize
skipAfterInitialize = true
return
}

if config.TranslateError {
Expand Down
Loading