mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09: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:
		| @@ -196,7 +196,7 @@ func (issue *Issue) LoadRepo(ctx context.Context) (err error) { | ||||
| 	if issue.Repo == nil { | ||||
| 		issue.Repo, err = repo_model.GetRepositoryByIDCtx(ctx, issue.RepoID) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("getRepositoryByID [%d]: %v", issue.RepoID, err) | ||||
| 			return fmt.Errorf("getRepositoryByID [%d]: %w", issue.RepoID, err) | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| @@ -234,7 +234,7 @@ func (issue *Issue) LoadLabels(ctx context.Context) (err error) { | ||||
| 	if issue.Labels == nil { | ||||
| 		issue.Labels, err = GetLabelsByIssueID(ctx, issue.ID) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("getLabelsByIssueID [%d]: %v", issue.ID, err) | ||||
| 			return fmt.Errorf("getLabelsByIssueID [%d]: %w", issue.ID, err) | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| @@ -252,7 +252,7 @@ func (issue *Issue) loadPoster(ctx context.Context) (err error) { | ||||
| 			issue.PosterID = -1 | ||||
| 			issue.Poster = user_model.NewGhostUser() | ||||
| 			if !user_model.IsErrUserNotExist(err) { | ||||
| 				return fmt.Errorf("getUserByID.(poster) [%d]: %v", issue.PosterID, err) | ||||
| 				return fmt.Errorf("getUserByID.(poster) [%d]: %w", issue.PosterID, err) | ||||
| 			} | ||||
| 			err = nil | ||||
| 			return | ||||
| @@ -268,7 +268,7 @@ func (issue *Issue) loadPullRequest(ctx context.Context) (err error) { | ||||
| 			if IsErrPullRequestNotExist(err) { | ||||
| 				return err | ||||
| 			} | ||||
| 			return fmt.Errorf("getPullRequestByIssueID [%d]: %v", issue.ID, err) | ||||
| 			return fmt.Errorf("getPullRequestByIssueID [%d]: %w", issue.ID, err) | ||||
| 		} | ||||
| 		issue.PullRequest.Issue = issue | ||||
| 	} | ||||
| @@ -361,7 +361,7 @@ func (issue *Issue) loadMilestone(ctx context.Context) (err error) { | ||||
| 	if (issue.Milestone == nil || issue.Milestone.ID != issue.MilestoneID) && issue.MilestoneID > 0 { | ||||
| 		issue.Milestone, err = GetMilestoneByRepoID(ctx, issue.RepoID, issue.MilestoneID) | ||||
| 		if err != nil && !IsErrMilestoneNotExist(err) { | ||||
| 			return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %v", issue.RepoID, issue.MilestoneID, err) | ||||
| 			return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %w", issue.RepoID, issue.MilestoneID, err) | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| @@ -401,7 +401,7 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) { | ||||
| 	if issue.Attachments == nil { | ||||
| 		issue.Attachments, err = repo_model.GetAttachmentsByIssueID(ctx, issue.ID) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("getAttachmentsByIssueID [%d]: %v", issue.ID, err) | ||||
| 			return fmt.Errorf("getAttachmentsByIssueID [%d]: %w", issue.ID, err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -518,19 +518,19 @@ func (issue *Issue) getLabels(ctx context.Context) (err error) { | ||||
|  | ||||
| 	issue.Labels, err = GetLabelsByIssueID(ctx, issue.ID) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("getLabelsByIssueID: %v", err) | ||||
| 		return fmt.Errorf("getLabelsByIssueID: %w", err) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func clearIssueLabels(ctx context.Context, issue *Issue, doer *user_model.User) (err error) { | ||||
| 	if err = issue.getLabels(ctx); err != nil { | ||||
| 		return fmt.Errorf("getLabels: %v", err) | ||||
| 		return fmt.Errorf("getLabels: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	for i := range issue.Labels { | ||||
| 		if err = deleteIssueLabel(ctx, issue, issue.Labels[i], doer); err != nil { | ||||
| 			return fmt.Errorf("removeLabel: %v", err) | ||||
| 			return fmt.Errorf("removeLabel: %w", err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -565,7 +565,7 @@ func ClearIssueLabels(issue *Issue, doer *user_model.User) (err error) { | ||||
| 	} | ||||
|  | ||||
| 	if err = committer.Commit(); err != nil { | ||||
| 		return fmt.Errorf("Commit: %v", err) | ||||
| 		return fmt.Errorf("Commit: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| @@ -635,13 +635,13 @@ func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (e | ||||
|  | ||||
| 	if len(toAdd) > 0 { | ||||
| 		if err = newIssueLabels(ctx, issue, toAdd, doer); err != nil { | ||||
| 			return fmt.Errorf("addLabels: %v", err) | ||||
| 			return fmt.Errorf("addLabels: %w", err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, l := range toRemove { | ||||
| 		if err = deleteIssueLabel(ctx, issue, l, doer); err != nil { | ||||
| 			return fmt.Errorf("removeLabel: %v", err) | ||||
| 			return fmt.Errorf("removeLabel: %w", err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -766,11 +766,11 @@ func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err | ||||
| 	defer committer.Close() | ||||
|  | ||||
| 	if err = UpdateIssueCols(ctx, issue, "name"); err != nil { | ||||
| 		return fmt.Errorf("updateIssueCols: %v", err) | ||||
| 		return fmt.Errorf("updateIssueCols: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	if err = issue.LoadRepo(ctx); err != nil { | ||||
| 		return fmt.Errorf("loadRepo: %v", err) | ||||
| 		return fmt.Errorf("loadRepo: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	opts := &CreateCommentOptions{ | ||||
| @@ -782,7 +782,7 @@ func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err | ||||
| 		NewTitle: issue.Title, | ||||
| 	} | ||||
| 	if _, err = CreateCommentCtx(ctx, opts); err != nil { | ||||
| 		return fmt.Errorf("createComment: %v", err) | ||||
| 		return fmt.Errorf("createComment: %w", err) | ||||
| 	} | ||||
| 	if err = issue.AddCrossReferences(ctx, doer, true); err != nil { | ||||
| 		return err | ||||
| @@ -800,11 +800,11 @@ func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err err | ||||
| 	defer committer.Close() | ||||
|  | ||||
| 	if err = UpdateIssueCols(ctx, issue, "ref"); err != nil { | ||||
| 		return fmt.Errorf("updateIssueCols: %v", err) | ||||
| 		return fmt.Errorf("updateIssueCols: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	if err = issue.LoadRepo(ctx); err != nil { | ||||
| 		return fmt.Errorf("loadRepo: %v", err) | ||||
| 		return fmt.Errorf("loadRepo: %w", err) | ||||
| 	} | ||||
| 	oldRefFriendly := strings.TrimPrefix(oldRef, git.BranchPrefix) | ||||
| 	newRefFriendly := strings.TrimPrefix(issue.Ref, git.BranchPrefix) | ||||
| @@ -818,7 +818,7 @@ func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err err | ||||
| 		NewRef: newRefFriendly, | ||||
| 	} | ||||
| 	if _, err = CreateCommentCtx(ctx, opts); err != nil { | ||||
| 		return fmt.Errorf("createComment: %v", err) | ||||
| 		return fmt.Errorf("createComment: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	return committer.Commit() | ||||
| @@ -850,12 +850,12 @@ func UpdateIssueAttachments(issueID int64, uuids []string) (err error) { | ||||
| 	defer committer.Close() | ||||
| 	attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, uuids) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", uuids, err) | ||||
| 		return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", uuids, err) | ||||
| 	} | ||||
| 	for i := 0; i < len(attachments); i++ { | ||||
| 		attachments[i].IssueID = issueID | ||||
| 		if err := repo_model.UpdateAttachment(ctx, attachments[i]); err != nil { | ||||
| 			return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err) | ||||
| 			return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err) | ||||
| 		} | ||||
| 	} | ||||
| 	return committer.Commit() | ||||
| @@ -871,28 +871,28 @@ func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (er | ||||
|  | ||||
| 	hasContentHistory, err := HasIssueContentHistory(ctx, issue.ID, 0) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("HasIssueContentHistory: %v", err) | ||||
| 		return fmt.Errorf("HasIssueContentHistory: %w", err) | ||||
| 	} | ||||
| 	if !hasContentHistory { | ||||
| 		if err = SaveIssueContentHistory(ctx, issue.PosterID, issue.ID, 0, | ||||
| 			issue.CreatedUnix, issue.Content, true); err != nil { | ||||
| 			return fmt.Errorf("SaveIssueContentHistory: %v", err) | ||||
| 			return fmt.Errorf("SaveIssueContentHistory: %w", err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	issue.Content = content | ||||
|  | ||||
| 	if err = UpdateIssueCols(ctx, issue, "content"); err != nil { | ||||
| 		return fmt.Errorf("UpdateIssueCols: %v", err) | ||||
| 		return fmt.Errorf("UpdateIssueCols: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	if err = SaveIssueContentHistory(ctx, doer.ID, issue.ID, 0, | ||||
| 		timeutil.TimeStampNow(), issue.Content, false); err != nil { | ||||
| 		return fmt.Errorf("SaveIssueContentHistory: %v", err) | ||||
| 		return fmt.Errorf("SaveIssueContentHistory: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	if err = issue.AddCrossReferences(ctx, doer, true); err != nil { | ||||
| 		return fmt.Errorf("addCrossReferences: %v", err) | ||||
| 		return fmt.Errorf("addCrossReferences: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	return committer.Commit() | ||||
| @@ -969,7 +969,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue | ||||
| 	if opts.Issue.MilestoneID > 0 { | ||||
| 		milestone, err := GetMilestoneByRepoID(ctx, opts.Issue.RepoID, opts.Issue.MilestoneID) | ||||
| 		if err != nil && !IsErrMilestoneNotExist(err) { | ||||
| 			return fmt.Errorf("getMilestoneByID: %v", err) | ||||
| 			return fmt.Errorf("getMilestoneByID: %w", err) | ||||
| 		} | ||||
|  | ||||
| 		// Assume milestone is invalid and drop silently. | ||||
| @@ -1023,7 +1023,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue | ||||
| 		// So we have to get all needed labels first. | ||||
| 		labels := make([]*Label, 0, len(opts.LabelIDs)) | ||||
| 		if err = e.In("id", opts.LabelIDs).Find(&labels); err != nil { | ||||
| 			return fmt.Errorf("find all labels [label_ids: %v]: %v", opts.LabelIDs, err) | ||||
| 			return fmt.Errorf("find all labels [label_ids: %v]: %w", opts.LabelIDs, err) | ||||
| 		} | ||||
|  | ||||
| 		if err = opts.Issue.loadPoster(ctx); err != nil { | ||||
| @@ -1037,7 +1037,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue | ||||
| 			} | ||||
|  | ||||
| 			if err = newIssueLabel(ctx, opts.Issue, label, opts.Issue.Poster); err != nil { | ||||
| 				return fmt.Errorf("addLabel [id: %d]: %v", label.ID, err) | ||||
| 				return fmt.Errorf("addLabel [id: %d]: %w", label.ID, err) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| @@ -1049,13 +1049,13 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue | ||||
| 	if len(opts.Attachments) > 0 { | ||||
| 		attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, opts.Attachments) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", opts.Attachments, err) | ||||
| 			return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", opts.Attachments, err) | ||||
| 		} | ||||
|  | ||||
| 		for i := 0; i < len(attachments); i++ { | ||||
| 			attachments[i].IssueID = opts.Issue.ID | ||||
| 			if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil { | ||||
| 				return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err) | ||||
| 				return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| @@ -1090,11 +1090,11 @@ func NewIssue(repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids | ||||
| 		if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) || IsErrNewIssueInsert(err) { | ||||
| 			return err | ||||
| 		} | ||||
| 		return fmt.Errorf("newIssue: %v", err) | ||||
| 		return fmt.Errorf("newIssue: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	if err = committer.Commit(); err != nil { | ||||
| 		return fmt.Errorf("Commit: %v", err) | ||||
| 		return fmt.Errorf("Commit: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| @@ -1614,7 +1614,7 @@ func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*user_mo | ||||
| 		ids[i] = u.ID | ||||
| 	} | ||||
| 	if err := UpdateIssueUsersByMentions(ctx, issueID, ids); err != nil { | ||||
| 		return fmt.Errorf("UpdateIssueUsersByMentions: %v", err) | ||||
| 		return fmt.Errorf("UpdateIssueUsersByMentions: %w", err) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
| @@ -1992,7 +1992,7 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment | ||||
| 	defer committer.Close() | ||||
|  | ||||
| 	if err := issue.LoadRepo(ctx); err != nil { | ||||
| 		return nil, false, fmt.Errorf("loadRepo: %v", err) | ||||
| 		return nil, false, fmt.Errorf("loadRepo: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	// Reload the issue | ||||
| @@ -2020,7 +2020,7 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment | ||||
| 		} | ||||
| 		_, err := CreateCommentCtx(ctx, opts) | ||||
| 		if err != nil { | ||||
| 			return nil, false, fmt.Errorf("createComment: %v", err) | ||||
| 			return nil, false, fmt.Errorf("createComment: %w", err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -2056,7 +2056,7 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *us | ||||
|  | ||||
| 	// Make the comment | ||||
| 	if _, err = createDeadlineComment(ctx, doer, issue, deadlineUnix); err != nil { | ||||
| 		return fmt.Errorf("createRemovedDueDateComment: %v", err) | ||||
| 		return fmt.Errorf("createRemovedDueDateComment: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	return committer.Commit() | ||||
| @@ -2093,7 +2093,7 @@ func (issue *Issue) GetParticipantIDsByIssue(ctx context.Context) ([]int64, erro | ||||
| 		Join("INNER", "`user`", "`user`.id = `comment`.poster_id"). | ||||
| 		Distinct("poster_id"). | ||||
| 		Find(&userIDs); err != nil { | ||||
| 		return nil, fmt.Errorf("get poster IDs: %v", err) | ||||
| 		return nil, fmt.Errorf("get poster IDs: %w", err) | ||||
| 	} | ||||
| 	if !util.IsInt64InSlice(issue.PosterID, userIDs) { | ||||
| 		return append(userIDs, issue.PosterID), nil | ||||
| @@ -2151,10 +2151,10 @@ func FindAndUpdateIssueMentions(ctx context.Context, issue *Issue, doer *user_mo | ||||
| 	rawMentions := references.FindAllMentionsMarkdown(content) | ||||
| 	mentions, err = ResolveIssueMentionsByVisibility(ctx, issue, doer, rawMentions) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err) | ||||
| 		return nil, fmt.Errorf("UpdateIssueMentions [%d]: %w", issue.ID, err) | ||||
| 	} | ||||
| 	if err = UpdateIssueMentions(ctx, issue.ID, mentions); err != nil { | ||||
| 		return nil, fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err) | ||||
| 		return nil, fmt.Errorf("UpdateIssueMentions [%d]: %w", issue.ID, err) | ||||
| 	} | ||||
| 	return mentions, err | ||||
| } | ||||
| @@ -2206,7 +2206,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u | ||||
| 			Where("team_repo.repo_id=?", issue.Repo.ID). | ||||
| 			In("team.lower_name", mentionTeams). | ||||
| 			Find(&teams); err != nil { | ||||
| 			return nil, fmt.Errorf("find mentioned teams: %v", err) | ||||
| 			return nil, fmt.Errorf("find mentioned teams: %w", err) | ||||
| 		} | ||||
| 		if len(teams) != 0 { | ||||
| 			checked := make([]int64, 0, len(teams)) | ||||
| @@ -2222,7 +2222,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u | ||||
| 				} | ||||
| 				has, err := db.GetEngine(ctx).Get(&organization.TeamUnit{OrgID: issue.Repo.Owner.ID, TeamID: team.ID, Type: unittype}) | ||||
| 				if err != nil { | ||||
| 					return nil, fmt.Errorf("get team units (%d): %v", team.ID, err) | ||||
| 					return nil, fmt.Errorf("get team units (%d): %w", team.ID, err) | ||||
| 				} | ||||
| 				if has { | ||||
| 					checked = append(checked, team.ID) | ||||
| @@ -2237,7 +2237,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u | ||||
| 					And("`user`.is_active = ?", true). | ||||
| 					And("`user`.prohibit_login = ?", false). | ||||
| 					Find(&teamusers); err != nil { | ||||
| 					return nil, fmt.Errorf("get teams users: %v", err) | ||||
| 					return nil, fmt.Errorf("get teams users: %w", err) | ||||
| 				} | ||||
| 				if len(teamusers) > 0 { | ||||
| 					users = make([]*user_model.User, 0, len(teamusers)) | ||||
| @@ -2273,7 +2273,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u | ||||
| 		And("`user`.prohibit_login = ?", false). | ||||
| 		In("`user`.lower_name", mentionUsers). | ||||
| 		Find(&unchecked); err != nil { | ||||
| 		return nil, fmt.Errorf("find mentioned users: %v", err) | ||||
| 		return nil, fmt.Errorf("find mentioned users: %w", err) | ||||
| 	} | ||||
| 	for _, user := range unchecked { | ||||
| 		if already := resolved[user.LowerName]; already || user.IsOrganization() { | ||||
| @@ -2282,7 +2282,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u | ||||
| 		// Normal users must have read access to the referencing issue | ||||
| 		perm, err := access_model.GetUserRepoPermission(ctx, issue.Repo, user) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("GetUserRepoPermission [%d]: %v", user.ID, err) | ||||
| 			return nil, fmt.Errorf("GetUserRepoPermission [%d]: %w", user.ID, err) | ||||
| 		} | ||||
| 		if !perm.CanReadIssuesOrPulls(issue.IsPull) { | ||||
| 			continue | ||||
|   | ||||
		Reference in New Issue
	
	Block a user