From 3c2e94ac8ab80680ec8296e6f343a56914ef7f58 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Tue, 25 Jun 2024 14:21:38 +0800 Subject: [PATCH] optimize(glance): wrap error of saving image (#20634) --- pkg/image/models/images.go | 2 +- pkg/util/procutils/remote_stat.go | 2 +- pkg/util/qemuimg/qemuimg.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/image/models/images.go b/pkg/image/models/images.go index 521a173c6ba..f410f649d14 100644 --- a/pkg/image/models/images.go +++ b/pkg/image/models/images.go @@ -537,7 +537,7 @@ func (self *SImage) SaveImageFromStream(reader io.Reader, totalSize int64, calCh format := "" img, err := qemuimg.NewQemuImage(localPath) if err != nil { - return err + return errors.Wrapf(err, "NewQemuImage %s", localPath) } format = string(img.Format) virtualSizeBytes = img.SizeBytes diff --git a/pkg/util/procutils/remote_stat.go b/pkg/util/procutils/remote_stat.go index 57b9fd42ad2..04298d79bf3 100644 --- a/pkg/util/procutils/remote_stat.go +++ b/pkg/util/procutils/remote_stat.go @@ -71,7 +71,7 @@ func RemoteStat(filename string) (os.FileInfo, error) { if strings.Contains(strings.ToLower(string(output)), "no such file or directory") { return nil, os.ErrNotExist } - return nil, errors.Wrap(err, "NewRemoteCommandAsFarAsPossible") + return nil, errors.Wrapf(err, "NewRemoteCommandAsFarAsPossible with stat %v: %s", args, output) } json, err := jsonutils.Parse(output) if err != nil { diff --git a/pkg/util/qemuimg/qemuimg.go b/pkg/util/qemuimg/qemuimg.go index a652ca6ee1f..7fd96511b9a 100644 --- a/pkg/util/qemuimg/qemuimg.go +++ b/pkg/util/qemuimg/qemuimg.go @@ -101,7 +101,7 @@ func (img *SQemuImage) parse() error { fileInfo, err := procutils.RemoteStat(img.Path) if err != nil { if !os.IsNotExist(err) { - return err + return errors.Wrapf(err, "remote stat of %s", img.Path) } else { // not created yet return nil