aboutsummaryrefslogtreecommitdiffstats
path: root/models/migrations/v115.go
diff options
context:
space:
mode:
authordelvh <leon@kske.dev>2022-10-24 21:29:17 +0200
committerGitHub <noreply@github.com>2022-10-24 20:29:17 +0100
commit0ebb45cfe7606adf021ad359d6fbfcefc54360a5 (patch)
tree541b75d083213e93bbbfadbdc5d560c739543903 /models/migrations/v115.go
parent7c11a73833f3aa9783015e5e13871d3c298d3ef6 (diff)
downloadgitea-0ebb45cfe7606adf021ad359d6fbfcefc54360a5.tar.gz
gitea-0ebb45cfe7606adf021ad359d6fbfcefc54360a5.zip
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 <art27@cantab.net> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'models/migrations/v115.go')
-rw-r--r--models/migrations/v115.go16
1 files changed, 8 insertions, 8 deletions
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