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 /routers | |
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 'routers')
-rw-r--r-- | routers/api/v1/activitypub/reqsignature.go | 2 | ||||
-rw-r--r-- | routers/api/v1/misc/signing.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/key.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/status.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/tag.go | 2 | ||||
-rw-r--r-- | routers/web/auth/auth.go | 2 | ||||
-rw-r--r-- | routers/web/auth/oauth.go | 4 | ||||
-rw-r--r-- | routers/web/repo/lfs.go | 8 | ||||
-rw-r--r-- | routers/web/repo/release.go | 4 | ||||
-rw-r--r-- | routers/web/repo/repo.go | 2 | ||||
-rw-r--r-- | routers/web/repo/setting.go | 6 | ||||
-rw-r--r-- | routers/web/user/home.go | 4 | ||||
-rw-r--r-- | routers/web/user/setting/profile.go | 8 |
13 files changed, 25 insertions, 25 deletions
diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 5c0776602b..649cb488b3 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -26,7 +26,7 @@ func getPublicKeyFromResponse(b []byte, keyID *url.URL) (p crypto.PublicKey, err person := ap.PersonNew(ap.IRI(keyID.String())) err = person.UnmarshalJSON(b) if err != nil { - err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %v", err) + err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %w", err) return } pubKey := person.PublicKey diff --git a/routers/api/v1/misc/signing.go b/routers/api/v1/misc/signing.go index b99e560ccf..1070cc78cb 100644 --- a/routers/api/v1/misc/signing.go +++ b/routers/api/v1/misc/signing.go @@ -59,6 +59,6 @@ func SigningKey(ctx *context.APIContext) { } _, err = ctx.Write([]byte(content)) if err != nil { - ctx.Error(http.StatusInternalServerError, "gpg export", fmt.Errorf("Error writing key content %v", err)) + ctx.Error(http.StatusInternalServerError, "gpg export", fmt.Errorf("Error writing key content %w", err)) } } diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go index 0c780eb97d..14f6aa6148 100644 --- a/routers/api/v1/repo/key.go +++ b/routers/api/v1/repo/key.go @@ -174,7 +174,7 @@ func HandleCheckKeyStringError(ctx *context.APIContext, err error) { } else if asymkey_model.IsErrKeyUnableVerify(err) { ctx.Error(http.StatusUnprocessableEntity, "", "Unable to verify key content") } else { - ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid key content: %v", err)) + ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid key content: %w", err)) } } diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go index 10e78f2a9b..97ef69a6ea 100644 --- a/routers/api/v1/repo/status.go +++ b/routers/api/v1/repo/status.go @@ -194,7 +194,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) { State: ctx.FormTrim("state"), }) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetCommitStatuses", fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %v", repo.FullName(), sha, ctx.FormInt("page"), err)) + ctx.Error(http.StatusInternalServerError, "GetCommitStatuses", fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %w", repo.FullName(), sha, ctx.FormInt("page"), err)) return } @@ -255,7 +255,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) { statuses, count, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx)) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetLatestCommitStatus", fmt.Errorf("GetLatestCommitStatus[%s, %s]: %v", repo.FullName(), sha, err)) + ctx.Error(http.StatusInternalServerError, "GetLatestCommitStatus", fmt.Errorf("GetLatestCommitStatus[%s, %s]: %w", repo.FullName(), sha, err)) return } diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go index f0f8503996..ab31866162 100644 --- a/routers/api/v1/repo/tag.go +++ b/routers/api/v1/repo/tag.go @@ -190,7 +190,7 @@ func CreateTag(ctx *context.APIContext) { commit, err := ctx.Repo.GitRepo.GetCommit(form.Target) if err != nil { - ctx.Error(http.StatusNotFound, "target not found", fmt.Errorf("target not found: %v", err)) + ctx.Error(http.StatusNotFound, "target not found", fmt.Errorf("target not found: %w", err)) return } diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index b48bdb9951..25d70d7c47 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -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 } diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index 9c929d990e..4fba8d8e8c 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -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) { diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go index 41639c4603..67cb6837a5 100644 --- a/routers/web/repo/lfs.go +++ b/routers/web/repo/lfs.go @@ -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] diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index 1e5710fa98..0cb85f3798 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -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 diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 974f03f951..3e746d3f05 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -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 } diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index e7abec0d3e..2b5691ce88 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -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 } diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 837caedc84..95ec1aa2fa 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -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 diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index c9a7afe982..ba3f5b5080 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -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 |