mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +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:
@@ -70,7 +70,7 @@ func AutoSignIn(ctx *context.Context) (bool, error) {
|
||||
u, err := user_model.GetUserByName(ctx, uname)
|
||||
if err != nil {
|
||||
if !user_model.IsErrUserNotExist(err) {
|
||||
return false, fmt.Errorf("GetUserByName: %v", err)
|
||||
return false, fmt.Errorf("GetUserByName: %w", err)
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
@@ -303,7 +303,7 @@ func InfoOAuth(ctx *context.Context) {
|
||||
func getOAuthGroupsForUser(user *user_model.User) ([]string, error) {
|
||||
orgs, err := org_model.GetUserOrgsList(user)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetUserOrgList: %v", err)
|
||||
return nil, fmt.Errorf("GetUserOrgList: %w", err)
|
||||
}
|
||||
|
||||
var groups []string
|
||||
@@ -311,7 +311,7 @@ func getOAuthGroupsForUser(user *user_model.User) ([]string, error) {
|
||||
groups = append(groups, org.Name)
|
||||
teams, err := org.LoadTeams()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("LoadTeams: %v", err)
|
||||
return nil, fmt.Errorf("LoadTeams: %w", err)
|
||||
}
|
||||
for _, team := range teams {
|
||||
if team.IsMember(user.ID) {
|
||||
|
@@ -122,14 +122,14 @@ func LFSLocks(ctx *context.Context) {
|
||||
Shared: true,
|
||||
}); err != nil {
|
||||
log.Error("Failed to clone repository: %s (%v)", ctx.Repo.Repository.FullName(), err)
|
||||
ctx.ServerError("LFSLocks", fmt.Errorf("failed to clone repository: %s (%v)", ctx.Repo.Repository.FullName(), err))
|
||||
ctx.ServerError("LFSLocks", fmt.Errorf("failed to clone repository: %s (%w)", ctx.Repo.Repository.FullName(), err))
|
||||
return
|
||||
}
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, tmpBasePath)
|
||||
if err != nil {
|
||||
log.Error("Unable to open temporary repository: %s (%v)", tmpBasePath, err)
|
||||
ctx.ServerError("LFSLocks", fmt.Errorf("failed to open new temporary repository in: %s %v", tmpBasePath, err))
|
||||
ctx.ServerError("LFSLocks", fmt.Errorf("failed to open new temporary repository in: %s %w", tmpBasePath, err))
|
||||
return
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
@@ -142,7 +142,7 @@ func LFSLocks(ctx *context.Context) {
|
||||
|
||||
if err := gitRepo.ReadTreeToIndex(ctx.Repo.Repository.DefaultBranch); err != nil {
|
||||
log.Error("Unable to read the default branch to the index: %s (%v)", ctx.Repo.Repository.DefaultBranch, err)
|
||||
ctx.ServerError("LFSLocks", fmt.Errorf("unable to read the default branch to the index: %s (%v)", ctx.Repo.Repository.DefaultBranch, err))
|
||||
ctx.ServerError("LFSLocks", fmt.Errorf("unable to read the default branch to the index: %s (%w)", ctx.Repo.Repository.DefaultBranch, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -542,7 +542,7 @@ func LFSAutoAssociate(ctx *context.Context) {
|
||||
metas[i] = &git_model.LFSMetaObject{}
|
||||
metas[i].Size, err = strconv.ParseInt(oid[idx+1:], 10, 64)
|
||||
if err != nil {
|
||||
ctx.ServerError("LFSAutoAssociate", fmt.Errorf("illegal oid input: %s %v", oid, err))
|
||||
ctx.ServerError("LFSAutoAssociate", fmt.Errorf("illegal oid input: %s %w", oid, err))
|
||||
return
|
||||
}
|
||||
metas[i].Oid = oid[:idx]
|
||||
|
@@ -46,11 +46,11 @@ func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *repo_model
|
||||
if repoCtx.GitRepo.IsBranchExist(release.Target) {
|
||||
commit, err := repoCtx.GitRepo.GetBranchCommit(release.Target)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetBranchCommit: %v", err)
|
||||
return fmt.Errorf("GetBranchCommit: %w", err)
|
||||
}
|
||||
countCache[release.Target], err = commit.CommitsCount()
|
||||
if err != nil {
|
||||
return fmt.Errorf("CommitsCount: %v", err)
|
||||
return fmt.Errorf("CommitsCount: %w", err)
|
||||
}
|
||||
} else {
|
||||
// Use NumCommits of the newest release on that target
|
||||
|
@@ -90,7 +90,7 @@ func checkContextUser(ctx *context.Context, uid int64) *user_model.User {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserByID", fmt.Errorf("[%d]: %v", uid, err))
|
||||
ctx.ServerError("GetUserByID", fmt.Errorf("[%d]: %w", uid, err))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -1197,7 +1197,7 @@ func UpdateAvatarSetting(ctx *context.Context, form forms.AvatarForm) error {
|
||||
|
||||
r, err := form.Avatar.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Avatar.Open: %v", err)
|
||||
return fmt.Errorf("Avatar.Open: %w", err)
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
@@ -1207,14 +1207,14 @@ func UpdateAvatarSetting(ctx *context.Context, form forms.AvatarForm) error {
|
||||
|
||||
data, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return fmt.Errorf("io.ReadAll: %v", err)
|
||||
return fmt.Errorf("io.ReadAll: %w", err)
|
||||
}
|
||||
st := typesniffer.DetectContentType(data)
|
||||
if !(st.IsImage() && !st.IsSvgImage()) {
|
||||
return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image"))
|
||||
}
|
||||
if err = repo_service.UploadAvatar(ctxRepo, data); err != nil {
|
||||
return fmt.Errorf("UploadAvatar: %v", err)
|
||||
return fmt.Errorf("UploadAvatar: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -697,11 +697,11 @@ func issueIDsFromSearch(ctx *context.Context, ctxUser *user_model.User, keyword
|
||||
|
||||
searchRepoIDs, err := issues_model.GetRepoIDsForIssuesOptions(opts, ctxUser)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetRepoIDsForIssuesOptions: %v", err)
|
||||
return nil, fmt.Errorf("GetRepoIDsForIssuesOptions: %w", err)
|
||||
}
|
||||
issueIDsFromSearch, err := issue_indexer.SearchIssuesByKeyword(ctx, searchRepoIDs, keyword)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("SearchIssuesByKeyword: %v", err)
|
||||
return nil, fmt.Errorf("SearchIssuesByKeyword: %w", err)
|
||||
}
|
||||
|
||||
return issueIDsFromSearch, nil
|
||||
|
@@ -162,7 +162,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *
|
||||
if form.Avatar != nil && form.Avatar.Filename != "" {
|
||||
fr, err := form.Avatar.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Avatar.Open: %v", err)
|
||||
return fmt.Errorf("Avatar.Open: %w", err)
|
||||
}
|
||||
defer fr.Close()
|
||||
|
||||
@@ -172,7 +172,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *
|
||||
|
||||
data, err := io.ReadAll(fr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("io.ReadAll: %v", err)
|
||||
return fmt.Errorf("io.ReadAll: %w", err)
|
||||
}
|
||||
|
||||
st := typesniffer.DetectContentType(data)
|
||||
@@ -180,7 +180,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *
|
||||
return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image"))
|
||||
}
|
||||
if err = user_service.UploadAvatar(ctxUser, data); err != nil {
|
||||
return fmt.Errorf("UploadAvatar: %v", err)
|
||||
return fmt.Errorf("UploadAvatar: %w", err)
|
||||
}
|
||||
} else if ctxUser.UseCustomAvatar && ctxUser.Avatar == "" {
|
||||
// No avatar is uploaded but setting has been changed to enable,
|
||||
@@ -191,7 +191,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *
|
||||
}
|
||||
|
||||
if err := user_model.UpdateUserCols(ctx, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil {
|
||||
return fmt.Errorf("UpdateUser: %v", err)
|
||||
return fmt.Errorf("UpdateUser: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user