优化error输出

This commit is contained in:
algotao
2026-01-11 17:24:11 +08:00
parent 5e102ea8e7
commit 369023b81d
45 changed files with 304 additions and 552 deletions

View File

@@ -24,8 +24,7 @@ func RunTaskDownload(args ...string) error {
destPath := paramDestPath(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(*sha256) == 0 || len(*destPath) == 0 {
@@ -35,8 +34,7 @@ func RunTaskDownload(args ...string) error {
cfg, err := LoadConfigFile(*cfgFile)
if err != nil {
fmt.Fprintln(os.Stderr, "LoadConfigFile error", "err", err)
return err
return fmt.Errorf("LoadConfigFile error: %w", err)
}
downloadTaskParams := downloadTaskParams{
@@ -63,9 +61,7 @@ func doTaskDownload(downloadTaskParams downloadTaskParams) error {
}
if len(taskInfo.GetSourcePath()) == 0 {
err = fmt.Errorf("task download failed. task info source path is empty")
fmt.Fprintln(os.Stderr, err)
return err
return fmt.Errorf("download task failed: %w, task info source path is empty", err)
}
totalFiles := len(taskInfo.GetTaskFileInfos())
@@ -105,9 +101,7 @@ func doTaskDownload(downloadTaskParams downloadTaskParams) error {
}
if blockRes.GetCode() != saasapi.ErrorCode_SUCC {
err = fmt.Errorf("download block error, code %d, msg %s", blockRes.GetCode(), blockRes.GetStatus())
fmt.Fprintln(os.Stderr, err)
return err
return fmt.Errorf("download block error, code %d, msg %s", blockRes.GetCode(), blockRes.GetStatus())
} else {
fmt.Printf("download block success. file: %v, sha256 %v. block %v/%v, file %v/%v\n",
finfo.GetFileName(), binfo.GetBlockSha256(),