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 /services/repository/files | |
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 'services/repository/files')
-rw-r--r-- | services/repository/files/cherry_pick.go | 4 | ||||
-rw-r--r-- | services/repository/files/commit.go | 6 | ||||
-rw-r--r-- | services/repository/files/delete.go | 4 | ||||
-rw-r--r-- | services/repository/files/patch.go | 4 | ||||
-rw-r--r-- | services/repository/files/temp_repo.go | 22 | ||||
-rw-r--r-- | services/repository/files/update.go | 6 | ||||
-rw-r--r-- | services/repository/files/upload.go | 4 |
7 files changed, 25 insertions, 25 deletions
diff --git a/services/repository/files/cherry_pick.go b/services/repository/files/cherry_pick.go index 0107d99e66..a30d4f6025 100644 --- a/services/repository/files/cherry_pick.go +++ b/services/repository/files/cherry_pick.go @@ -51,7 +51,7 @@ func CherryPick(ctx context.Context, repo *repo_model.Repository, doer *user_mod } else { lastCommitID, err := t.gitRepo.ConvertToSHA1(opts.LastCommitID) if err != nil { - return nil, fmt.Errorf("CherryPick: Invalid last commit ID: %v", err) + return nil, fmt.Errorf("CherryPick: Invalid last commit ID: %w", err) } opts.LastCommitID = lastCommitID.String() if commit.ID.String() != opts.LastCommitID { @@ -81,7 +81,7 @@ func CherryPick(ctx context.Context, repo *repo_model.Repository, doer *user_mod conflict, _, err := pull.AttemptThreeWayMerge(ctx, t.basePath, t.gitRepo, base, opts.LastCommitID, right, description) if err != nil { - return nil, fmt.Errorf("failed to three-way merge %s onto %s: %v", right, opts.OldBranch, err) + return nil, fmt.Errorf("failed to three-way merge %s onto %s: %w", right, opts.OldBranch, err) } if conflict { diff --git a/services/repository/files/commit.go b/services/repository/files/commit.go index ecd981b5ff..bc5a4c8ed3 100644 --- a/services/repository/files/commit.go +++ b/services/repository/files/commit.go @@ -26,13 +26,13 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato // confirm that commit is exist gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath()) if err != nil { - return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err) + return fmt.Errorf("OpenRepository[%s]: %w", repoPath, err) } defer closer.Close() if _, err := gitRepo.GetCommit(sha); err != nil { gitRepo.Close() - return fmt.Errorf("GetCommit[%s]: %v", sha, err) + return fmt.Errorf("GetCommit[%s]: %w", sha, err) } gitRepo.Close() @@ -42,7 +42,7 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato SHA: sha, CommitStatus: status, }); err != nil { - return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %v", repo.ID, creator.ID, sha, err) + return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", repo.ID, creator.ID, sha, err) } if status.State.IsSuccess() { diff --git a/services/repository/files/delete.go b/services/repository/files/delete.go index 781a762d0f..f098052ad8 100644 --- a/services/repository/files/delete.go +++ b/services/repository/files/delete.go @@ -104,7 +104,7 @@ func DeleteRepoFile(ctx context.Context, repo *repo_model.Repository, doer *user } else { lastCommitID, err := t.gitRepo.ConvertToSHA1(opts.LastCommitID) if err != nil { - return nil, fmt.Errorf("DeleteRepoFile: Invalid last commit ID: %v", err) + return nil, fmt.Errorf("DeleteRepoFile: Invalid last commit ID: %w", err) } opts.LastCommitID = lastCommitID.String() } @@ -112,7 +112,7 @@ func DeleteRepoFile(ctx context.Context, repo *repo_model.Repository, doer *user // Get the files in the index filesInIndex, err := t.LsFiles(opts.TreePath) if err != nil { - return nil, fmt.Errorf("DeleteRepoFile: %v", err) + return nil, fmt.Errorf("DeleteRepoFile: %w", err) } // Find the file we want to delete in the index diff --git a/services/repository/files/patch.go b/services/repository/files/patch.go index 437890c488..2be01f25be 100644 --- a/services/repository/files/patch.go +++ b/services/repository/files/patch.go @@ -125,7 +125,7 @@ func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user } else { lastCommitID, err := t.gitRepo.ConvertToSHA1(opts.LastCommitID) if err != nil { - return nil, fmt.Errorf("ApplyPatch: Invalid last commit ID: %v", err) + return nil, fmt.Errorf("ApplyPatch: Invalid last commit ID: %w", err) } opts.LastCommitID = lastCommitID.String() if commit.ID.String() != opts.LastCommitID { @@ -152,7 +152,7 @@ func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user Stderr: stderr, Stdin: strings.NewReader(opts.Content), }); err != nil { - return nil, fmt.Errorf("Error: Stdout: %s\nStderr: %s\nErr: %v", stdout.String(), stderr.String(), err) + return nil, fmt.Errorf("Error: Stdout: %s\nStderr: %s\nErr: %w", stdout.String(), stderr.String(), err) } // Now write the tree diff --git a/services/repository/files/temp_repo.go b/services/repository/files/temp_repo.go index 9513f2341e..b96d9e7b3d 100644 --- a/services/repository/files/temp_repo.go +++ b/services/repository/files/temp_repo.go @@ -67,7 +67,7 @@ func (t *TemporaryUploadRepository) Clone(branch string) error { Name: t.repo.Name, } } else { - return fmt.Errorf("Clone: %v %s", err, stderr) + return fmt.Errorf("Clone: %w %s", err, stderr) } } gitRepo, err := git.OpenRepository(t.ctx, t.basePath) @@ -94,7 +94,7 @@ func (t *TemporaryUploadRepository) Init() error { // SetDefaultIndex sets the git index to our HEAD func (t *TemporaryUploadRepository) SetDefaultIndex() error { if _, _, err := git.NewCommand(t.ctx, "read-tree", "HEAD").RunStdString(&git.RunOpts{Dir: t.basePath}); err != nil { - return fmt.Errorf("SetDefaultIndex: %v", err) + return fmt.Errorf("SetDefaultIndex: %w", err) } return nil } @@ -111,7 +111,7 @@ func (t *TemporaryUploadRepository) LsFiles(filenames ...string) ([]string, erro Stderr: stdErr, }); err != nil { log.Error("Unable to run git ls-files for temporary repo: %s (%s) Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), t.basePath, err, stdOut.String(), stdErr.String()) - err = fmt.Errorf("Unable to run git ls-files for temporary repo of: %s Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String()) + err = fmt.Errorf("Unable to run git ls-files for temporary repo of: %s Error: %w\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String()) return nil, err } @@ -144,7 +144,7 @@ func (t *TemporaryUploadRepository) RemoveFilesFromIndex(filenames ...string) er Stderr: stdErr, }); err != nil { log.Error("Unable to update-index for temporary repo: %s (%s) Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), t.basePath, err, stdOut.String(), stdErr.String()) - return fmt.Errorf("Unable to update-index for temporary repo: %s Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String()) + return fmt.Errorf("Unable to update-index for temporary repo: %s Error: %w\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String()) } return nil } @@ -162,7 +162,7 @@ func (t *TemporaryUploadRepository) HashObject(content io.Reader) (string, error Stderr: stdErr, }); err != nil { log.Error("Unable to hash-object to temporary repo: %s (%s) Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), t.basePath, err, stdOut.String(), stdErr.String()) - return "", fmt.Errorf("Unable to hash-object to temporary repo: %s Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String()) + return "", fmt.Errorf("Unable to hash-object to temporary repo: %s Error: %w\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String()) } return strings.TrimSpace(stdOut.String()), nil @@ -179,7 +179,7 @@ func (t *TemporaryUploadRepository) AddObjectToIndex(mode, objectHash, objectPat } } log.Error("Unable to add object to index: %s %s %s in temporary repo %s(%s) Error: %v", mode, objectHash, objectPath, t.repo.FullName(), t.basePath, err) - return fmt.Errorf("Unable to add object to index at %s in temporary repo %s Error: %v", objectPath, t.repo.FullName(), err) + return fmt.Errorf("Unable to add object to index at %s in temporary repo %s Error: %w", objectPath, t.repo.FullName(), err) } return nil } @@ -189,7 +189,7 @@ func (t *TemporaryUploadRepository) WriteTree() (string, error) { stdout, _, err := git.NewCommand(t.ctx, "write-tree").RunStdString(&git.RunOpts{Dir: t.basePath}) if err != nil { log.Error("Unable to write tree in temporary repo: %s(%s): Error: %v", t.repo.FullName(), t.basePath, err) - return "", fmt.Errorf("Unable to write-tree in temporary repo for: %s Error: %v", t.repo.FullName(), err) + return "", fmt.Errorf("Unable to write-tree in temporary repo for: %s Error: %w", t.repo.FullName(), err) } return strings.TrimSpace(stdout), nil } @@ -207,7 +207,7 @@ func (t *TemporaryUploadRepository) GetLastCommitByRef(ref string) (string, erro stdout, _, err := git.NewCommand(t.ctx, "rev-parse").AddDynamicArguments(ref).RunStdString(&git.RunOpts{Dir: t.basePath}) if err != nil { log.Error("Unable to get last ref for %s in temporary repo: %s(%s): Error: %v", ref, t.repo.FullName(), t.basePath, err) - return "", fmt.Errorf("Unable to rev-parse %s in temporary repo for: %s Error: %v", ref, t.repo.FullName(), err) + return "", fmt.Errorf("Unable to rev-parse %s in temporary repo for: %s Error: %w", ref, t.repo.FullName(), err) } return strings.TrimSpace(stdout), nil } @@ -292,7 +292,7 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(parent string, author, co }); err != nil { log.Error("Unable to commit-tree in temporary repo: %s (%s) Error: %v\nStdout: %s\nStderr: %s", t.repo.FullName(), t.basePath, err, stdout, stderr) - return "", fmt.Errorf("Unable to commit-tree in temporary repo: %s Error: %v\nStdout: %s\nStderr: %s", + return "", fmt.Errorf("Unable to commit-tree in temporary repo: %s Error: %w\nStdout: %s\nStderr: %s", t.repo.FullName(), err, stdout, stderr) } return strings.TrimSpace(stdout.String()), nil @@ -328,7 +328,7 @@ func (t *TemporaryUploadRepository) DiffIndex() (*gitdiff.Diff, error) { stdoutReader, stdoutWriter, err := os.Pipe() if err != nil { log.Error("Unable to open stdout pipe: %v", err) - return nil, fmt.Errorf("Unable to open stdout pipe: %v", err) + return nil, fmt.Errorf("Unable to open stdout pipe: %w", err) } defer func() { _ = stdoutReader.Close() @@ -361,7 +361,7 @@ func (t *TemporaryUploadRepository) DiffIndex() (*gitdiff.Diff, error) { } log.Error("Unable to run diff-index pipeline in temporary repo %s (%s). Error: %v\nStderr: %s", t.repo.FullName(), t.basePath, err, stderr) - return nil, fmt.Errorf("Unable to run diff-index pipeline in temporary repo %s. Error: %v\nStderr: %s", + return nil, fmt.Errorf("Unable to run diff-index pipeline in temporary repo %s. Error: %w\nStderr: %s", t.repo.FullName(), err, stderr) } diff --git a/services/repository/files/update.go b/services/repository/files/update.go index 87c622a9be..1721b00b01 100644 --- a/services/repository/files/update.go +++ b/services/repository/files/update.go @@ -226,7 +226,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do } else { lastCommitID, err := t.gitRepo.ConvertToSHA1(opts.LastCommitID) if err != nil { - return nil, fmt.Errorf("ConvertToSHA1: Invalid last commit ID: %v", err) + return nil, fmt.Errorf("ConvertToSHA1: Invalid last commit ID: %w", err) } opts.LastCommitID = lastCommitID.String() @@ -321,7 +321,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do // Get the two paths (might be the same if not moving) from the index if they exist filesInIndex, err := t.LsFiles(opts.TreePath, opts.FromTreePath) if err != nil { - return nil, fmt.Errorf("UpdateRepoFile: %v", err) + return nil, fmt.Errorf("UpdateRepoFile: %w", err) } // If is a new file (not updating) then the given path shouldn't exist if opts.IsNewFile { @@ -436,7 +436,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do if !exist { if err := contentStore.Put(lfsMetaObject.Pointer, strings.NewReader(opts.Content)); err != nil { if _, err2 := git_model.RemoveLFSMetaObjectByOid(repo.ID, lfsMetaObject.Oid); err2 != nil { - return nil, fmt.Errorf("Error whilst removing failed inserted LFS object %s: %v (Prev Error: %v)", lfsMetaObject.Oid, err2, err) + return nil, fmt.Errorf("Error whilst removing failed inserted LFS object %s: %v (Prev Error: %w)", lfsMetaObject.Oid, err2, err) } return nil, err } diff --git a/services/repository/files/upload.go b/services/repository/files/upload.go index b2dadb6497..3728780991 100644 --- a/services/repository/files/upload.go +++ b/services/repository/files/upload.go @@ -42,7 +42,7 @@ func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, orig } if !info.lfsMetaObject.Existing { if _, err := git_model.RemoveLFSMetaObjectByOid(t.repo.ID, info.lfsMetaObject.Oid); err != nil { - original = fmt.Errorf("%v, %v", original, err) + original = fmt.Errorf("%w, %v", original, err) // We wrap the original error - as this is the underlying error that required the fallback } } } @@ -57,7 +57,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use uploads, err := repo_model.GetUploadsByUUIDs(opts.Files) if err != nil { - return fmt.Errorf("GetUploadsByUUIDs [uuids: %v]: %v", opts.Files, err) + return fmt.Errorf("GetUploadsByUUIDs [uuids: %v]: %w", opts.Files, err) } names := make([]string, len(uploads)) |