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 /models/git | |
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 'models/git')
-rw-r--r-- | models/git/branches.go | 12 | ||||
-rw-r--r-- | models/git/commit_status.go | 10 | ||||
-rw-r--r-- | models/git/lfs.go | 2 |
3 files changed, 12 insertions, 12 deletions
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 } |