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:
2026-06-29 17:50:31 -07:00
parent 8d697eda5b
commit 63187ee905
5 changed files with 105 additions and 5 deletions
+9 -1
View File
@@ -45,6 +45,11 @@ var (
state = dbState{}
)
// CurrentDialect returns the SQL dialect configured by [ModuleDB].
func CurrentDialect() Dialect {
return state.dialect
}
// SQLO returns the current SQL database handle.
func SQLO() *sql.DB {
dbxshared.DBModule.RequireLoaded("dbx.SQLO requires database module")
@@ -118,7 +123,10 @@ func setupDB(m *app.Module) error {
)
if state.debugLog {
dbxshared.InitLogger(state.dialect)
if err := dbxshared.InitLogger(state.dialect); err != nil {
m.Logger().Error("Couldn't initialize Jet query debug logger", "err", err)
return err
}
}
return nil