!138 fix: 后端数据连接断开后报空指针异常后程序中断问题

* fix(connection):fix the bug for nil error in connection when connection reset
* fix(sqleditor): fix the spell error in sql editor
This commit is contained in:
davidathena
2025-10-18 03:15:25 +00:00
committed by Coder慌
parent 4ac57cd140
commit 4e30bdb7cc
5 changed files with 45 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package mgm
import (
"context"
"fmt"
"mayfly-go/pkg/logx"
"go.mongodb.org/mongo-driver/v2/mongo"
@@ -28,5 +29,14 @@ func (mc *MongoConn) Close() error {
}
func (mc *MongoConn) Ping() error {
// 首先检查mc是否为nil
if mc == nil {
return fmt.Errorf("mc connection is nil")
}
// 然后检查mc.Cli是否为nil这是避免空指针异常的关键
if mc.Cli == nil {
return fmt.Errorf("mc client is nil")
}
return mc.Cli.Ping(context.Background(), nil)
}