Skip to content

Commit

Permalink
fix(mysql): 权限申请单据报错返回 #8797
Browse files Browse the repository at this point in the history
  • Loading branch information
xfwduke committed Dec 24, 2024
1 parent 9eb1a55 commit 8dc3f96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions dbm-services/mysql/db-priv/service/v2/add_priv/add_priv.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"dbm-services/common/go-pubpkg/errno"
"dbm-services/mysql/priv-service/service"
"dbm-services/mysql/priv-service/service/v2/internal"
"encoding/json"
"errors"
"log/slog"
"strings"
Expand Down Expand Up @@ -139,12 +138,14 @@ func (c *PrivTaskPara) AddPriv(jsonPara, ticket string) (err error) {
}()

var errCollect error
var reportCollect map[string][]string
reportCollect := make(map[string][]string, 0)
for {
select {
case err := <-errChan:
slog.Error("add priv collect error", slog.String("err", err.Error()))
errCollect = errors.Join(errCollect, err)
case report := <-reportChan:
slog.Info("add priv collect report", slog.Any("report", report))
for k, v := range report {
if _, ok := reportCollect[k]; !ok {
reportCollect[k] = []string{}
Expand All @@ -156,17 +157,20 @@ func (c *PrivTaskPara) AddPriv(jsonPara, ticket string) (err error) {
slog.Info("receive quit signal")
if errCollect != nil {
slog.Error("add priv", slog.String("err", errCollect.Error()))
return errCollect
return errno.GrantPrivilegesFail.Add("\n" + errCollect.Error() + "\n")
}

if reportCollect != nil {
if len(reportCollect) > 0 {
slog.Error("add priv", slog.Any("reportCollect", reportCollect))
b, err := json.Marshal(reportCollect)
if err != nil {
slog.Error("add priv", slog.String("err", err.Error()))
return err
var errMsg []string
for _, v := range reportCollect {
errMsg = append(errMsg, v...)
}
return errors.New(string(b))
return errno.GrantPrivilegesFail.Add(
"\n" +
strings.Join(errMsg, "\n") +
"\n",
)
}
slog.Info("add priv finish")
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (c *MySQLCrondComp) Init() error {
if c.Params.NginxAddrs == nil || len(c.Params.NginxAddrs) <= 0 {
err := fmt.Errorf("nginx addresses are required")
logger.Error(err.Error())
return err
return nil
}

// 初始化 nginx addrs 配置文件
Expand Down

0 comments on commit 8dc3f96

Please sign in to comment.