优化error输出
This commit is contained in:
@@ -25,8 +25,7 @@ func RunScriptCreate(args ...string) error {
|
||||
luaName := paramName(fs)
|
||||
|
||||
if err := fs.Parse(args); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "command line parse error", "err", err)
|
||||
return err
|
||||
return fmt.Errorf("Command line parse error: %w", err)
|
||||
}
|
||||
|
||||
if fs.NArg() > 0 || len(*luaFile) == 0 || len(*luaName) == 0 {
|
||||
@@ -36,21 +35,18 @@ func RunScriptCreate(args ...string) error {
|
||||
|
||||
file, err := os.Open(*luaFile)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "lua file error", "err", err)
|
||||
return err
|
||||
return fmt.Errorf("Lua file open error: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
body, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "lua file read error", "err", err)
|
||||
return err
|
||||
return fmt.Errorf("Lua file read error: %w", err)
|
||||
}
|
||||
|
||||
cfg, err := LoadConfigFile(*cfgFile)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "LoadConfigFile error", "err", err)
|
||||
return err
|
||||
return fmt.Errorf("LoadConfigFile error: %w", err)
|
||||
}
|
||||
|
||||
scriptCreateParams := scriptCreateParams{
|
||||
@@ -78,13 +74,11 @@ func doScriptCreate(scriptCreateParams scriptCreateParams) error {
|
||||
|
||||
res, err := scriptCreateParams.saasHttp.ScriptCreate(saasReq)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "submit Create Script error", "err", err)
|
||||
return err
|
||||
return fmt.Errorf("Submit Command error: %w", err)
|
||||
}
|
||||
|
||||
if res.Code != saasapi.ErrorCode_SUCC {
|
||||
fmt.Fprintln(os.Stderr, "script create failed", "code", res.Code, "status", res.Status)
|
||||
return nil
|
||||
return fmt.Errorf("Command failed. code:%v, status:%v", res.Code, res.Status)
|
||||
}
|
||||
|
||||
scriptRes := res.GetScriptCreateRes()
|
||||
|
||||
Reference in New Issue
Block a user