From 0ebb45cfe7606adf021ad359d6fbfcefc54360a5 Mon Sep 17 00:00:00 2001 From: delvh Date: Mon, 24 Oct 2022 21:29:17 +0200 Subject: 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 Co-authored-by: wxiaoguang --- models/git/branches.go | 12 ++++++------ models/git/commit_status.go | 10 +++++----- models/git/lfs.go | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'models/git') diff --git a/models/git/branches.go b/models/git/branches.go index 7f05a56676..b17d762dbe 100644 --- a/models/git/branches.go +++ b/models/git/branches.go @@ -270,7 +270,7 @@ type WhitelistOptions struct { // to avoid unnecessary whitelist delete and regenerate. func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) { if err = repo.GetOwner(ctx); err != nil { - return fmt.Errorf("GetOwner: %v", err) + return fmt.Errorf("GetOwner: %w", err) } whitelist, err := updateUserWhitelist(ctx, repo, protectBranch.WhitelistUserIDs, opts.UserIDs) @@ -313,13 +313,13 @@ func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, prote // Make sure protectBranch.ID is not 0 for whitelists if protectBranch.ID == 0 { if _, err = db.GetEngine(ctx).Insert(protectBranch); err != nil { - return fmt.Errorf("Insert: %v", err) + return fmt.Errorf("Insert: %w", err) } return nil } if _, err = db.GetEngine(ctx).ID(protectBranch.ID).AllCols().Update(protectBranch); err != nil { - return fmt.Errorf("Update: %v", err) + return fmt.Errorf("Update: %w", err) } return nil @@ -378,11 +378,11 @@ func updateUserWhitelist(ctx context.Context, repo *repo_model.Repository, curre for _, userID := range newWhitelist { user, err := user_model.GetUserByIDCtx(ctx, userID) if err != nil { - return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err) + return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %w", userID, repo.ID, err) } perm, err := access_model.GetUserRepoPermission(ctx, repo, user) if err != nil { - return nil, fmt.Errorf("GetUserRepoPermission [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err) + return nil, fmt.Errorf("GetUserRepoPermission [user_id: %d, repo_id: %d]: %w", userID, repo.ID, err) } if !perm.CanWrite(unit.TypeCode) { @@ -405,7 +405,7 @@ func updateTeamWhitelist(ctx context.Context, repo *repo_model.Repository, curre teams, err := organization.GetTeamsWithAccessToRepo(ctx, repo.OwnerID, repo.ID, perm.AccessModeRead) if err != nil { - return nil, fmt.Errorf("GetTeamsWithAccessToRepo [org_id: %d, repo_id: %d]: %v", repo.OwnerID, repo.ID, err) + return nil, fmt.Errorf("GetTeamsWithAccessToRepo [org_id: %d, repo_id: %d]: %w", repo.OwnerID, repo.ID, err) } whitelist = make([]int64, 0, len(teams)) diff --git a/models/git/commit_status.go b/models/git/commit_status.go index 9e24221862..620baa036c 100644 --- a/models/git/commit_status.go +++ b/models/git/commit_status.go @@ -128,13 +128,13 @@ func (status *CommitStatus) loadAttributes(ctx context.Context) (err error) { if status.Repo == nil { status.Repo, err = repo_model.GetRepositoryByIDCtx(ctx, status.RepoID) if err != nil { - return fmt.Errorf("getRepositoryByID [%d]: %v", status.RepoID, err) + return fmt.Errorf("getRepositoryByID [%d]: %w", status.RepoID, err) } } if status.Creator == nil && status.CreatorID > 0 { status.Creator, err = user_model.GetUserByIDCtx(ctx, status.CreatorID) if err != nil { - return fmt.Errorf("getUserByID [%d]: %v", status.CreatorID, err) + return fmt.Errorf("getUserByID [%d]: %w", status.CreatorID, err) } } return nil @@ -294,12 +294,12 @@ func NewCommitStatus(opts NewCommitStatusOptions) error { // Get the next Status Index idx, err := GetNextCommitStatusIndex(opts.Repo.ID, opts.SHA) if err != nil { - return fmt.Errorf("generate commit status index failed: %v", err) + return fmt.Errorf("generate commit status index failed: %w", err) } ctx, committer, err := db.TxContext() if err != nil { - return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %v", opts.Repo.ID, opts.Creator.ID, opts.SHA, err) + return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", opts.Repo.ID, opts.Creator.ID, opts.SHA, err) } defer committer.Close() @@ -316,7 +316,7 @@ func NewCommitStatus(opts NewCommitStatusOptions) error { // Insert new CommitStatus if _, err = db.GetEngine(ctx).Insert(opts.CommitStatus); err != nil { - return fmt.Errorf("Insert CommitStatus[%s, %s]: %v", repoPath, opts.SHA, err) + return fmt.Errorf("Insert CommitStatus[%s, %s]: %w", repoPath, opts.SHA, err) } return committer.Commit() diff --git a/models/git/lfs.go b/models/git/lfs.go index 1dab31d5f9..58042edfdb 100644 --- a/models/git/lfs.go +++ b/models/git/lfs.go @@ -316,7 +316,7 @@ func CopyLFS(ctx context.Context, newRepo, oldRepo *repo_model.Repository) error func GetRepoLFSSize(ctx context.Context, repoID int64) (int64, error) { lfsSize, err := db.GetEngine(ctx).Where("repository_id = ?", repoID).SumInt(new(LFSMetaObject), "size") if err != nil { - return 0, fmt.Errorf("updateSize: GetLFSMetaObjects: %v", err) + return 0, fmt.Errorf("updateSize: GetLFSMetaObjects: %w", err) } return lfsSize, nil } -- cgit v1.2.3