From 6cf32c0d0b41c532f97171c29a46c175ff0ebc66 Mon Sep 17 00:00:00 2001 From: Invidam Date: Sun, 6 Oct 2024 17:07:05 +0900 Subject: [PATCH] refactor: improve logging for unimplemented ErrorTranslator in TranslateError config --- gorm.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gorm.go b/gorm.go index 117d2fd07..84ff8ee39 100644 --- a/gorm.go +++ b/gorm.go @@ -189,6 +189,12 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) { _ = db.Close() } } + + if config.TranslateError { + if _, ok := db.Dialector.(ErrorTranslator); !ok { + config.Logger.Warn(context.Background(), "The TranslateError option is enabled, but the Dialector %s does not implement ErrorTranslator.", db.Dialector.Name()) + } + } } if config.PrepareStmt {