From f7390b076365eba409914d8fb391d0acb9191e16 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Tue, 8 Feb 2022 00:24:57 +0400 Subject: [PATCH] Wrap an error message. Return 0 size on error. --- pkg/utils/filesize.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/utils/filesize.go b/pkg/utils/filesize.go index 8b5dd4b..dc86630 100644 --- a/pkg/utils/filesize.go +++ b/pkg/utils/filesize.go @@ -6,6 +6,8 @@ import ( "path/filepath" "strconv" "strings" + + "github.com/pkg/errors" ) var sizeSuffixes = [...]string{"B", "KiB", "MiB", "GiB", "TiB"} @@ -30,7 +32,7 @@ func ConvertFileSize(size int64) (float64, string, string) { func DirectorySize(path string) (dirSz int64, err error) { err = filepath.Walk(path, func(_ string, info fs.FileInfo, err error) error { if err != nil { - return err + return errors.Wrapf(err, "failed to compute %s directory size", path) } dirSz += info.Size() @@ -39,7 +41,7 @@ func DirectorySize(path string) (dirSz int64, err error) { }) if err != nil { - return dirSz, err + return 0, err } return dirSz, nil