Skip to content

Commit

Permalink
* [fix#54304] refactor error handling and add translations
Browse files Browse the repository at this point in the history
  • Loading branch information
ysicing committed Aug 26, 2024
1 parent 6dbc76e commit 04ba06e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
9 changes: 8 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ tasks:

prepare:
desc: start prepare res
run: once
# run: once
deps:
- install
# - compile_ui
Expand Down Expand Up @@ -95,6 +95,13 @@ tasks:
- cp -a ../../../client/out/ztf-{{.GOOS}}-{{.GOARCH}} gui


dev:
desc: dev
cmds:
- task: fmt
- make prepare
- make compile_command_linux

default:
cmds:
# - task: prepare
Expand Down
7 changes: 6 additions & 1 deletion internal/command/action/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
configHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/config"
scriptHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/script"
zentaoHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/zentao"
i118Utils "github.com/easysoft/zentaoatf/pkg/lib/i118"
logUtils "github.com/easysoft/zentaoatf/pkg/lib/log"
stdinUtils "github.com/easysoft/zentaoatf/pkg/lib/stdin"
stringUtils "github.com/easysoft/zentaoatf/pkg/lib/string"
Expand Down Expand Up @@ -40,8 +41,12 @@ func Checkout(productId, moduleId, suiteId, taskId string, independentFile bool,

_, err := zentaoHelper.Checkout(settings, config, commConsts.WorkDir)
if err != nil {
if err.Error() == "no_cases_found" {
logUtils.Info(i118Utils.Sprintf("no_cases"))
return
}
logUtils.Errorf("checkout failed: %v", err)
return
}
logUtils.Info("checkout success")
logUtils.Info(i118Utils.Sprintf("checkout_success"))
}
18 changes: 10 additions & 8 deletions pkg/lib/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/easysoft/zentaoatf/pkg/consts"

commonUtils "github.com/easysoft/zentaoatf/pkg/lib/common"
i118Utils "github.com/easysoft/zentaoatf/pkg/lib/i118"
logUtils "github.com/easysoft/zentaoatf/pkg/lib/log"
cp "github.com/otiai10/copy"
)

Expand All @@ -42,16 +44,16 @@ func ReadFileBuf(filePath string) []byte {

func WriteFile(filePath string, content string) {
dir := filepath.Dir(filePath)
MkDirIfNeeded(dir)
if err := MkDirIfNeeded(dir); err != nil {
logUtils.Error(i118Utils.Sprintf("mkdir_failed", dir, err.Error()))
os.Exit(1)
return
}

var d1 = []byte(content)
err2 := os.WriteFile(filePath, d1, 0666) //写入文件(字节数组)
check(err2)
}

func check(e error) {
if e != nil {
panic(e)
if err := os.WriteFile(filePath, d1, 0666); err != nil {
logUtils.Error(i118Utils.Sprintf("writefile_failed", filePath, err.Error()))
os.Exit(1)
}
}

Expand Down
12 changes: 12 additions & 0 deletions res/server/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,18 @@
{
"id": "jacoco_report",
"translation": "Jacoco Coverage Report"
},
{
"id": "mkdir_failed",
"translation": "Make dir %s failed, err: %s"
},
{
"id": "writefile_failed",
"translation": "Write file %s failed, err: %s"
},
{
"id": "checkout_success",
"translation": "Checkout success."
}
]
}
12 changes: 12 additions & 0 deletions res/server/zh/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,18 @@
{
"id": "jacoco_report",
"translation": "Jacoco覆盖率报告"
},
{
"id": "mkdir_failed",
"translation": "创建目录 %s 失败, err: %s"
},
{
"id": "writefile_failed",
"translation": "写文件 %s 失败, err: %s"
},
{
"id": "checkout_success",
"translation": "同步完成"
}
]
}

0 comments on commit 04ba06e

Please sign in to comment.