提交 6e2c910c 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

fix sonar issues

上级 50132847
package execHelper
import (
commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts"
websocketHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/websocket"
logUtils "github.com/easysoft/zentaoatf/pkg/lib/log"
"github.com/fatih/color"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/websocket"
)
func PrintErrMsg(key string, err error, wsMsg *websocket.Message) (
stdOutput string, errOutput string) {
if commConsts.ExecFrom == commConsts.FromClient {
websocketHelper.SendOutputMsg(err.Error(), "", iris.Map{"key": key}, wsMsg)
}
logUtils.ExecConsolef(color.FgRed, err.Error())
logUtils.ExecFilef(err.Error())
return "", err.Error()
}
......@@ -38,7 +38,7 @@ func RunFile(filePath, workspacePath string, conf commDomain.WorkspaceConf,
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(timeout))
defer cancel()
cmd := setScriptInterpreter(filePath, lang, uuidString, conf, ctx, wsMsg)
cmd := getCommand(filePath, lang, uuidString, conf, ctx, wsMsg)
if cmd == nil {
msgStr := i118Utils.Sprintf("cmd_empty")
......@@ -60,21 +60,9 @@ func RunFile(filePath, workspacePath string, conf commDomain.WorkspaceConf,
stderr, err2 := cmd.StderrPipe()
if err1 != nil {
if commConsts.ExecFrom == commConsts.FromClient {
websocketHelper.SendOutputMsg(err1.Error(), "", iris.Map{"key": key}, wsMsg)
}
logUtils.ExecConsolef(color.FgRed, err1.Error())
logUtils.ExecFilef(err1.Error())
return "", err1.Error()
return PrintErrMsg(key, err1, wsMsg)
} else if err2 != nil {
if commConsts.ExecFrom == commConsts.FromClient {
websocketHelper.SendOutputMsg(err2.Error(), "", iris.Map{"key": key}, wsMsg)
}
logUtils.ExecConsolef(color.FgRed, err2.Error())
logUtils.ExecFilef(err2.Error())
return "", err2.Error()
return PrintErrMsg(key, err2, wsMsg)
}
cmd.Start()
......
......@@ -25,7 +25,7 @@ import (
"strings"
)
func setScriptInterpreter(filePath, lang, uuidString string, conf commDomain.WorkspaceConf, ctx context.Context, wsMsg *websocket.Message) (
func getCommand(filePath, lang, uuidString string, conf commDomain.WorkspaceConf, ctx context.Context, wsMsg *websocket.Message) (
cmd *exec.Cmd) {
if commonUtils.IsWin() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册