diff options
author | delvh <leon@kske.dev> | 2022-10-24 21:29:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-24 20:29:17 +0100 |
commit | 0ebb45cfe7606adf021ad359d6fbfcefc54360a5 (patch) | |
tree | 541b75d083213e93bbbfadbdc5d560c739543903 /models/user | |
parent | 7c11a73833f3aa9783015e5e13871d3c298d3ef6 (diff) | |
download | gitea-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/user')
-rw-r--r-- | models/user/avatar.go | 4 | ||||
-rw-r--r-- | models/user/email_address.go | 10 | ||||
-rw-r--r-- | models/user/list.go | 4 | ||||
-rw-r--r-- | models/user/search.go | 2 | ||||
-rw-r--r-- | models/user/user.go | 4 |
5 files changed, 12 insertions, 12 deletions
diff --git a/models/user/avatar.go b/models/user/avatar.go index 1c75c7406b..f73ac56c5e 100644 --- a/models/user/avatar.go +++ b/models/user/avatar.go @@ -35,7 +35,7 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error { img, err := avatar.RandomImage([]byte(seed)) if err != nil { - return fmt.Errorf("RandomImage: %v", err) + return fmt.Errorf("RandomImage: %w", err) } u.Avatar = avatars.HashEmail(seed) @@ -47,7 +47,7 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error { } return err }); err != nil { - return fmt.Errorf("Failed to create dir %s: %v", u.CustomAvatarRelativePath(), err) + return fmt.Errorf("Failed to create dir %s: %w", u.CustomAvatarRelativePath(), err) } if _, err := db.GetEngine(ctx).ID(u.ID).Cols("avatar").Update(u); err != nil { diff --git a/models/user/email_address.go b/models/user/email_address.go index 964e7ae08c..d6279b6639 100644 --- a/models/user/email_address.go +++ b/models/user/email_address.go @@ -264,7 +264,7 @@ func AddEmailAddresses(emails []*EmailAddress) error { } if err := db.Insert(db.DefaultContext, emails); err != nil { - return fmt.Errorf("Insert: %v", err) + return fmt.Errorf("Insert: %w", err) } return nil @@ -485,7 +485,7 @@ func SearchEmails(opts *SearchEmailOptions) ([]*SearchEmailResult, int64, error) count, err := db.GetEngine(db.DefaultContext).Join("INNER", "`user`", "`user`.ID = email_address.uid"). Where(cond).Count(new(EmailAddress)) if err != nil { - return nil, 0, fmt.Errorf("Count: %v", err) + return nil, 0, fmt.Errorf("Count: %w", err) } orderby := opts.SortType.String() @@ -530,7 +530,7 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) { } if activate { if used, err := IsEmailActive(ctx, email, addr.ID); err != nil { - return fmt.Errorf("unable to check isEmailActive() for %s: %v", email, err) + return fmt.Errorf("unable to check isEmailActive() for %s: %w", email, err) } else if used { return ErrEmailAlreadyUsed{Email: email} } @@ -551,10 +551,10 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) { if user.IsActive != activate { user.IsActive = activate if user.Rands, err = GetUserSalt(); err != nil { - return fmt.Errorf("unable to generate salt: %v", err) + return fmt.Errorf("unable to generate salt: %w", err) } if err = UpdateUserCols(ctx, &user, "is_active", "rands"); err != nil { - return fmt.Errorf("unable to updateUserCols() for user ID: %d: %v", userID, err) + return fmt.Errorf("unable to updateUserCols() for user ID: %d: %w", userID, err) } } } diff --git a/models/user/list.go b/models/user/list.go index 68e62ca15d..6c43c961c8 100644 --- a/models/user/list.go +++ b/models/user/list.go @@ -55,7 +55,7 @@ func (users UserList) loadTwoFactorStatus(ctx context.Context) (map[int64]*auth. userIDs := users.GetUserIDs() tokenMaps := make(map[int64]*auth.TwoFactor, len(userIDs)) if err := db.GetEngine(ctx).In("uid", userIDs).Find(&tokenMaps); err != nil { - return nil, fmt.Errorf("find two factor: %v", err) + return nil, fmt.Errorf("find two factor: %w", err) } return tokenMaps, nil } @@ -66,7 +66,7 @@ func (users UserList) userIDsWithWebAuthn(ctx context.Context) ([]int64, error) } ids := make([]int64, 0, len(users)) if err := db.GetEngine(ctx).Table(new(auth.WebAuthnCredential)).In("user_id", users.GetUserIDs()).Select("user_id").Distinct("user_id").Find(&ids); err != nil { - return nil, fmt.Errorf("find two factor: %v", err) + return nil, fmt.Errorf("find two factor: %w", err) } return ids, nil } diff --git a/models/user/search.go b/models/user/search.go index 0aa9949367..fa4a021a47 100644 --- a/models/user/search.go +++ b/models/user/search.go @@ -105,7 +105,7 @@ func SearchUsers(opts *SearchUserOptions) (users []*User, _ int64, _ error) { defer sessCount.Close() count, err := sessCount.Count(new(User)) if err != nil { - return nil, 0, fmt.Errorf("Count: %v", err) + return nil, 0, fmt.Errorf("Count: %w", err) } if len(opts.OrderBy) == 0 { diff --git a/models/user/user.go b/models/user/user.go index a3c10c2492..9a2da6dbc1 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -827,12 +827,12 @@ func ChangeUserName(u *User, newUserName string) (err error) { } if _, err = db.GetEngine(ctx).Exec("UPDATE `repository` SET owner_name=? WHERE owner_name=?", newUserName, oldUserName); err != nil { - return fmt.Errorf("Change repo owner name: %v", err) + return fmt.Errorf("Change repo owner name: %w", err) } // Do not fail if directory does not exist if err = util.Rename(UserPath(oldUserName), UserPath(newUserName)); err != nil && !os.IsNotExist(err) { - return fmt.Errorf("Rename user directory: %v", err) + return fmt.Errorf("Rename user directory: %w", err) } if err = NewUserRedirect(ctx, u.ID, oldUserName, newUserName); err != nil { |