aboutsummaryrefslogtreecommitdiffstats
path: root/services/user
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 /services/user
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 'services/user')
-rw-r--r--services/user/user.go28
1 files changed, 14 insertions, 14 deletions
diff --git a/services/user/user.go b/services/user/user.go
index dab9ac61a4..c8b497a5c4 100644
--- a/services/user/user.go
+++ b/services/user/user.go
@@ -78,14 +78,14 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
Actor: u,
})
if err != nil {
- return fmt.Errorf("SearchRepositoryByName: %v", err)
+ return fmt.Errorf("SearchRepositoryByName: %w", err)
}
if len(repos) == 0 {
break
}
for _, repo := range repos {
if err := models.DeleteRepository(u, u.ID, repo.ID); err != nil {
- return fmt.Errorf("unable to delete repository %s for %s[%d]. Error: %v", repo.Name, u.Name, u.ID, err)
+ return fmt.Errorf("unable to delete repository %s for %s[%d]. Error: %w", repo.Name, u.Name, u.ID, err)
}
}
}
@@ -107,7 +107,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
IncludePrivate: true,
})
if err != nil {
- return fmt.Errorf("unable to find org list for %s[%d]. Error: %v", u.Name, u.ID, err)
+ return fmt.Errorf("unable to find org list for %s[%d]. Error: %w", u.Name, u.ID, err)
}
if len(orgs) == 0 {
break
@@ -118,7 +118,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
err = organization.DeleteOrganization(ctx, org)
}
if err != nil {
- return fmt.Errorf("unable to remove user %s[%d] from org %s[%d]. Error: %v", u.Name, u.ID, org.Name, org.ID, err)
+ return fmt.Errorf("unable to remove user %s[%d] from org %s[%d]. Error: %w", u.Name, u.ID, org.Name, org.ID, err)
}
}
}
@@ -145,7 +145,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
// Check ownership of repository.
count, err := repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{OwnerID: u.ID})
if err != nil {
- return fmt.Errorf("GetRepositoryCount: %v", err)
+ return fmt.Errorf("GetRepositoryCount: %w", err)
} else if count > 0 {
return models.ErrUserOwnRepos{UID: u.ID}
}
@@ -153,20 +153,20 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
// Check membership of organization.
count, err = organization.GetOrganizationCount(ctx, u)
if err != nil {
- return fmt.Errorf("GetOrganizationCount: %v", err)
+ return fmt.Errorf("GetOrganizationCount: %w", err)
} else if count > 0 {
return models.ErrUserHasOrgs{UID: u.ID}
}
// Check ownership of packages.
if ownsPackages, err := packages_model.HasOwnerPackages(ctx, u.ID); err != nil {
- return fmt.Errorf("HasOwnerPackages: %v", err)
+ return fmt.Errorf("HasOwnerPackages: %w", err)
} else if ownsPackages {
return models.ErrUserOwnPackages{UID: u.ID}
}
if err := models.DeleteUser(ctx, u, purge); err != nil {
- return fmt.Errorf("DeleteUser: %v", err)
+ return fmt.Errorf("DeleteUser: %w", err)
}
if err := committer.Commit(); err != nil {
@@ -185,7 +185,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
// so just keep error logs of those operations.
path := user_model.UserPath(u.Name)
if err := util.RemoveAll(path); err != nil {
- err = fmt.Errorf("Failed to RemoveAll %s: %v", path, err)
+ err = fmt.Errorf("Failed to RemoveAll %s: %w", path, err)
_ = system_model.CreateNotice(ctx, system_model.NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err))
return err
}
@@ -193,7 +193,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
if u.Avatar != "" {
avatarPath := u.CustomAvatarRelativePath()
if err := storage.Avatars.Delete(avatarPath); err != nil {
- err = fmt.Errorf("Failed to remove %s: %v", avatarPath, err)
+ err = fmt.Errorf("Failed to remove %s: %w", avatarPath, err)
_ = system_model.CreateNotice(ctx, system_model.NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err))
return err
}
@@ -248,7 +248,7 @@ func UploadAvatar(u *user_model.User, data []byte) error {
// Other users will lose their avatars too.
u.Avatar = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
if err = user_model.UpdateUserCols(ctx, u, "use_custom_avatar", "avatar"); err != nil {
- return fmt.Errorf("updateUser: %v", err)
+ return fmt.Errorf("updateUser: %w", err)
}
if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error {
@@ -257,7 +257,7 @@ func UploadAvatar(u *user_model.User, data []byte) 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)
}
return committer.Commit()
@@ -269,14 +269,14 @@ func DeleteAvatar(u *user_model.User) error {
log.Trace("DeleteAvatar[%d]: %s", u.ID, aPath)
if len(u.Avatar) > 0 {
if err := storage.Avatars.Delete(aPath); err != nil {
- return fmt.Errorf("Failed to remove %s: %v", aPath, err)
+ return fmt.Errorf("Failed to remove %s: %w", aPath, err)
}
}
u.UseCustomAvatar = false
u.Avatar = ""
if _, err := db.GetEngine(db.DefaultContext).ID(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil {
- return fmt.Errorf("UpdateUser: %v", err)
+ return fmt.Errorf("UpdateUser: %w", err)
}
return nil
}