mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
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>
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user