From f8403dac454493235e36ae304cad665110df7b86 Mon Sep 17 00:00:00 2001 From: xfwduke Date: Tue, 24 Dec 2024 13:37:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(mysql):=20=E6=9D=83=E9=99=90=E7=94=B3?= =?UTF-8?q?=E8=AF=B7=E5=8D=95=E6=8D=AE=E6=8A=A5=E9=94=99=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=20#8797?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db-priv/service/v2/add_priv/add_priv.go | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/dbm-services/mysql/db-priv/service/v2/add_priv/add_priv.go b/dbm-services/mysql/db-priv/service/v2/add_priv/add_priv.go index bf9962a01f..882a83aab0 100644 --- a/dbm-services/mysql/db-priv/service/v2/add_priv/add_priv.go +++ b/dbm-services/mysql/db-priv/service/v2/add_priv/add_priv.go @@ -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" @@ -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{} @@ -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 { 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