mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-01 23:10:26 +08:00
!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:
@@ -88,7 +88,7 @@
|
||||
</template>
|
||||
|
||||
<el-row>
|
||||
<span v-if="dt.hasUpdatedFileds" class="mt-1">
|
||||
<span v-if="dt.hasUpdatedFields" class="mt-1">
|
||||
<span>
|
||||
<el-link type="success" underline="never" @click="submitUpdateFields(dt)"
|
||||
><span style="font-size: 12px">{{ $t('common.submit') }}</span></el-link
|
||||
@@ -200,7 +200,7 @@ class ExecResTab {
|
||||
/**
|
||||
* 是否有更新字段
|
||||
*/
|
||||
hasUpdatedFileds: boolean;
|
||||
hasUpdatedFields: boolean;
|
||||
|
||||
errorMsg: string;
|
||||
|
||||
@@ -783,7 +783,7 @@ const getUploadSqlFileUrl = () => {
|
||||
|
||||
const changeUpdatedField = (updatedFields: any, dt: ExecResTab) => {
|
||||
// 如果存在要更新字段,则显示提交和取消按钮
|
||||
dt.hasUpdatedFileds = updatedFields && updatedFields.size > 0;
|
||||
dt.hasUpdatedFields = updatedFields && updatedFields.size > 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,15 @@ func (d *DbConn) Close() error {
|
||||
}
|
||||
|
||||
func (d *DbConn) Ping() error {
|
||||
// 首先检查d是否为nil
|
||||
if d == nil {
|
||||
return fmt.Errorf("d is nil")
|
||||
}
|
||||
|
||||
// 然后检查d.db是否为nil,这是避免空指针异常的关键
|
||||
if d.db == nil {
|
||||
return fmt.Errorf("db is nil")
|
||||
}
|
||||
return d.db.Ping()
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,15 @@ func (d *EsConn) Close() error {
|
||||
}
|
||||
|
||||
func (d *EsConn) Ping() error {
|
||||
// 首先检查d是否为nil
|
||||
if d == nil {
|
||||
return fmt.Errorf("es connection is nil")
|
||||
}
|
||||
|
||||
// 然后检查d.Info是否为nil,这是避免空指针异常的关键
|
||||
if d.Info == nil {
|
||||
return fmt.Errorf("es Info is nil")
|
||||
}
|
||||
_, err := d.Info.Ping()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package rdm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"mayfly-go/pkg/errorx"
|
||||
"mayfly-go/pkg/logx"
|
||||
|
||||
@@ -41,7 +42,19 @@ func (r *RedisConn) Close() error {
|
||||
}
|
||||
|
||||
func (r *RedisConn) Ping() error {
|
||||
_, err := r.Cli.Ping(context.Background()).Result()
|
||||
// 首先检查r是否为nil
|
||||
if r == nil {
|
||||
return fmt.Errorf("redis connection is nil")
|
||||
}
|
||||
// 然后检查r.Cli是否为nil,这是避免空指针异常的关键
|
||||
if r.Cli == nil {
|
||||
return fmt.Errorf("redis client is nil")
|
||||
}
|
||||
cmd := r.Cli.Ping(context.Background())
|
||||
if cmd == nil {
|
||||
return fmt.Errorf("the ping cmd is nil")
|
||||
}
|
||||
_, err := cmd.Result()
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user