fix: harden module lifecycle and debug log setup
Export CurrentDialect(), return setup errors when debug logger is not registered, and guard DestName logging when the module is uninitialized. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -20,14 +20,14 @@ func DestName(destTypeStruct any, path ...string) string {
|
||||
|
||||
for i, p := range path {
|
||||
if v.Kind() != reflect.Struct {
|
||||
dbxshared.DBModule.Logger().Error("DestName: path parent is not a struct", "path", destIdent+"."+strings.Join(path[:i+1], "."))
|
||||
destNameLogError("DestName: path parent is not a struct", destIdent+"."+strings.Join(path[:i+1], "."))
|
||||
return ""
|
||||
}
|
||||
|
||||
v = v.FieldByName(p)
|
||||
|
||||
if !v.IsValid() {
|
||||
dbxshared.DBModule.Logger().Error("DestName: field does not exist", "path", destIdent+"."+strings.Join(path[:i+1], "."))
|
||||
destNameLogError("DestName: field does not exist", destIdent+"."+strings.Join(path[:i+1], "."))
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -36,3 +36,10 @@ func DestName(destTypeStruct any, path ...string) string {
|
||||
|
||||
return destIdent
|
||||
}
|
||||
|
||||
func destNameLogError(msg, path string) {
|
||||
if dbxshared.DBModule == nil {
|
||||
return
|
||||
}
|
||||
dbxshared.DBModule.Logger().Error(msg, "path", path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user