From 0ebb45cfe7606adf021ad359d6fbfcefc54360a5 Mon Sep 17 00:00:00 2001 From: delvh Date: Mon, 24 Oct 2022 21:29:17 +0200 Subject: Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) Found using `find . -type f -name '*.go' -print -exec vim {} -c ':%s/fmt\.Errorf(\(.*\)%v\(.*\)err/fmt.Errorf(\1%w\2err/g' -c ':wq' \;` Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Andrew Thornton Co-authored-by: wxiaoguang --- models/migrations/v115.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'models/migrations/v115.go') diff --git a/models/migrations/v115.go b/models/migrations/v115.go index b242ccf238..3e61cb6e0e 100644 --- a/models/migrations/v115.go +++ b/models/migrations/v115.go @@ -45,11 +45,11 @@ func renameExistingUserAvatarName(x *xorm.Engine) error { migrated := 0 for { if err := sess.Begin(); err != nil { - return fmt.Errorf("session.Begin: %v", err) + return fmt.Errorf("session.Begin: %w", err) } users := make([]*User, 0, 50) if err := sess.Table("user").Asc("id").Limit(50, start).Find(&users); err != nil { - return fmt.Errorf("select users from id [%d]: %v", start, err) + return fmt.Errorf("select users from id [%d]: %w", start, err) } if len(users) == 0 { _ = sess.Rollback() @@ -76,7 +76,7 @@ func renameExistingUserAvatarName(x *xorm.Engine) error { newAvatar, err := copyOldAvatarToNewLocation(user.ID, oldAvatar) if err != nil { _ = sess.Rollback() - return fmt.Errorf("[user: %s] %v", user.LowerName, err) + return fmt.Errorf("[user: %s] %w", user.LowerName, err) } else if newAvatar == oldAvatar { continue } @@ -84,7 +84,7 @@ func renameExistingUserAvatarName(x *xorm.Engine) error { user.Avatar = newAvatar if _, err := sess.ID(user.ID).Cols("avatar").Update(user); err != nil { _ = sess.Rollback() - return fmt.Errorf("[user: %s] user table update: %v", user.LowerName, err) + return fmt.Errorf("[user: %s] user table update: %w", user.LowerName, err) } deleteList.Add(filepath.Join(setting.Avatar.Path, oldAvatar)) @@ -104,7 +104,7 @@ func renameExistingUserAvatarName(x *xorm.Engine) error { } if err := sess.Commit(); err != nil { _ = sess.Rollback() - return fmt.Errorf("commit session: %v", err) + return fmt.Errorf("commit session: %w", err) } } @@ -138,13 +138,13 @@ func renameExistingUserAvatarName(x *xorm.Engine) error { func copyOldAvatarToNewLocation(userID int64, oldAvatar string) (string, error) { fr, err := os.Open(filepath.Join(setting.Avatar.Path, oldAvatar)) if err != nil { - return "", fmt.Errorf("os.Open: %v", err) + return "", fmt.Errorf("os.Open: %w", err) } defer fr.Close() data, err := io.ReadAll(fr) if err != nil { - return "", fmt.Errorf("io.ReadAll: %v", err) + return "", fmt.Errorf("io.ReadAll: %w", err) } newAvatar := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", userID, md5.Sum(data))))) @@ -153,7 +153,7 @@ func copyOldAvatarToNewLocation(userID int64, oldAvatar string) (string, error) } if err := os.WriteFile(filepath.Join(setting.Avatar.Path, newAvatar), data, 0o666); err != nil { - return "", fmt.Errorf("os.WriteFile: %v", err) + return "", fmt.Errorf("os.WriteFile: %w", err) } return newAvatar, nil -- cgit v1.2.3