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 | |
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')
-rw-r--r-- | services/repository/adopt.go | 22 | ||||
-rw-r--r-- | services/repository/archiver/archiver.go | 12 | ||||
-rw-r--r-- | services/repository/avatar.go | 10 | ||||
-rw-r--r-- | services/repository/branch.go | 4 | ||||
-rw-r--r-- | services/repository/check.go | 4 | ||||
-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 | ||||
-rw-r--r-- | services/repository/fork.go | 8 | ||||
-rw-r--r-- | services/repository/hooks.go | 4 | ||||
-rw-r--r-- | services/repository/push.go | 32 | ||||
-rw-r--r-- | services/repository/repository.go | 2 |
16 files changed, 74 insertions, 74 deletions
diff --git a/services/repository/adopt.go b/services/repository/adopt.go index 9e04c15977..3b986c66c6 100644 --- a/services/repository/adopt.go +++ b/services/repository/adopt.go @@ -71,16 +71,16 @@ func AdoptRepository(doer, u *user_model.User, opts repo_module.CreateRepoOption return err } if err := adoptRepository(ctx, repoPath, doer, repo, opts); err != nil { - return fmt.Errorf("createDelegateHooks: %v", err) + return fmt.Errorf("createDelegateHooks: %w", err) } if err := repo_module.CheckDaemonExportOK(ctx, repo); err != nil { - return fmt.Errorf("checkDaemonExportOK: %v", err) + return fmt.Errorf("checkDaemonExportOK: %w", err) } // Initialize Issue Labels if selected if len(opts.IssueLabels) > 0 { if err := repo_module.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil { - return fmt.Errorf("InitializeLabels: %v", err) + return fmt.Errorf("InitializeLabels: %w", err) } } @@ -88,7 +88,7 @@ func AdoptRepository(doer, u *user_model.User, opts repo_module.CreateRepoOption SetDescription(fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath)). RunStdString(&git.RunOpts{Dir: repoPath}); err != nil { log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err) - return fmt.Errorf("CreateRepository(git update-server-info): %v", err) + return fmt.Errorf("CreateRepository(git update-server-info): %w", err) } return nil }); err != nil { @@ -111,13 +111,13 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r } if err := repo_module.CreateDelegateHooks(repoPath); err != nil { - return fmt.Errorf("createDelegateHooks: %v", err) + return fmt.Errorf("createDelegateHooks: %w", err) } // Re-fetch the repository from database before updating it (else it would // override changes that were done earlier with sql) if repo, err = repo_model.GetRepositoryByIDCtx(ctx, repo.ID); err != nil { - return fmt.Errorf("getRepositoryByID: %v", err) + return fmt.Errorf("getRepositoryByID: %w", err) } repo.IsEmpty = false @@ -125,7 +125,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r // Don't bother looking this repo in the context it won't be there gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { - return fmt.Errorf("openRepository: %v", err) + return fmt.Errorf("openRepository: %w", err) } defer gitRepo.Close() @@ -133,14 +133,14 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r repo.DefaultBranch = opts.DefaultBranch if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { - return fmt.Errorf("setDefaultBranch: %v", err) + return fmt.Errorf("setDefaultBranch: %w", err) } } else { repo.DefaultBranch, err = gitRepo.GetDefaultBranch() if err != nil { repo.DefaultBranch = setting.Repository.DefaultBranch if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { - return fmt.Errorf("setDefaultBranch: %v", err) + return fmt.Errorf("setDefaultBranch: %w", err) } } } @@ -176,12 +176,12 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r } if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { - return fmt.Errorf("setDefaultBranch: %v", err) + return fmt.Errorf("setDefaultBranch: %w", err) } } if err = repo_module.UpdateRepository(ctx, repo, false); err != nil { - return fmt.Errorf("updateRepository: %v", err) + return fmt.Errorf("updateRepository: %w", err) } return nil diff --git a/services/repository/archiver/archiver.go b/services/repository/archiver/archiver.go index ae43503bae..79537ea051 100644 --- a/services/repository/archiver/archiver.go +++ b/services/repository/archiver/archiver.go @@ -139,7 +139,7 @@ func (aReq *ArchiveRequest) GetArchiveName() string { func (aReq *ArchiveRequest) Await(ctx context.Context) (*repo_model.RepoArchiver, error) { archiver, err := repo_model.GetRepoArchiver(ctx, aReq.RepoID, aReq.Type, aReq.CommitID) if err != nil { - return nil, fmt.Errorf("models.GetRepoArchiver: %v", err) + return nil, fmt.Errorf("models.GetRepoArchiver: %w", err) } if archiver != nil && archiver.Status == repo_model.ArchiverReady { @@ -148,7 +148,7 @@ func (aReq *ArchiveRequest) Await(ctx context.Context) (*repo_model.RepoArchiver } if err := StartArchive(aReq); err != nil { - return nil, fmt.Errorf("archiver.StartArchive: %v", err) + return nil, fmt.Errorf("archiver.StartArchive: %w", err) } poll := time.NewTicker(time.Second * 1) @@ -164,7 +164,7 @@ func (aReq *ArchiveRequest) Await(ctx context.Context) (*repo_model.RepoArchiver case <-poll.C: archiver, err = repo_model.GetRepoArchiver(ctx, aReq.RepoID, aReq.Type, aReq.CommitID) if err != nil { - return nil, fmt.Errorf("repo_model.GetRepoArchiver: %v", err) + return nil, fmt.Errorf("repo_model.GetRepoArchiver: %w", err) } if archiver != nil && archiver.Status == repo_model.ArchiverReady { return archiver, nil @@ -218,7 +218,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) { } if !errors.Is(err, os.ErrNotExist) { - return nil, fmt.Errorf("unable to stat archive: %v", err) + return nil, fmt.Errorf("unable to stat archive: %w", err) } rd, w := io.Pipe() @@ -229,7 +229,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) { done := make(chan error, 1) // Ensure that there is some capacity which will ensure that the goroutine below can always finish repo, err := repo_model.GetRepositoryByID(archiver.RepoID) if err != nil { - return nil, fmt.Errorf("archiver.LoadRepo failed: %v", err) + return nil, fmt.Errorf("archiver.LoadRepo failed: %w", err) } gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) @@ -268,7 +268,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) { // TODO: add submodule data to zip if _, err := storage.RepoArchives.Save(rPath, rd, -1); err != nil { - return nil, fmt.Errorf("unable to write archive: %v", err) + return nil, fmt.Errorf("unable to write archive: %w", err) } err = <-done diff --git a/services/repository/avatar.go b/services/repository/avatar.go index b9bd36ab66..b80a8fb775 100644 --- a/services/repository/avatar.go +++ b/services/repository/avatar.go @@ -45,7 +45,7 @@ func UploadAvatar(repo *repo_model.Repository, data []byte) error { // Then repo will be removed - only it avatar file will be removed repo.Avatar = newAvatar if err := repo_model.UpdateRepositoryCols(ctx, repo, "avatar"); err != nil { - return fmt.Errorf("UploadAvatar: Update repository avatar: %v", err) + return fmt.Errorf("UploadAvatar: Update repository avatar: %w", err) } if err := storage.SaveFrom(storage.RepoAvatars, repo.CustomAvatarRelativePath(), func(w io.Writer) error { @@ -54,12 +54,12 @@ func UploadAvatar(repo *repo_model.Repository, data []byte) error { } return err }); err != nil { - return fmt.Errorf("UploadAvatar %s failed: Failed to remove old repo avatar %s: %v", repo.RepoPath(), newAvatar, err) + return fmt.Errorf("UploadAvatar %s failed: Failed to remove old repo avatar %s: %w", repo.RepoPath(), newAvatar, err) } if len(oldAvatarPath) > 0 { if err := storage.RepoAvatars.Delete(oldAvatarPath); err != nil { - return fmt.Errorf("UploadAvatar: Failed to remove old repo avatar %s: %v", oldAvatarPath, err) + return fmt.Errorf("UploadAvatar: Failed to remove old repo avatar %s: %w", oldAvatarPath, err) } } @@ -84,11 +84,11 @@ func DeleteAvatar(repo *repo_model.Repository) error { repo.Avatar = "" if err := repo_model.UpdateRepositoryCols(ctx, repo, "avatar"); err != nil { - return fmt.Errorf("DeleteAvatar: Update repository avatar: %v", err) + return fmt.Errorf("DeleteAvatar: Update repository avatar: %w", err) } if err := storage.RepoAvatars.Delete(avatarPath); err != nil { - return fmt.Errorf("DeleteAvatar: Failed to remove %s: %v", avatarPath, err) + return fmt.Errorf("DeleteAvatar: Failed to remove %s: %w", avatarPath, err) } return committer.Commit() diff --git a/services/repository/branch.go b/services/repository/branch.go index 6c9a5d76ca..1328422582 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -42,7 +42,7 @@ func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_mode if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) { return err } - return fmt.Errorf("Push: %v", err) + return fmt.Errorf("Push: %w", err) } return nil @@ -99,7 +99,7 @@ func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) { return err } - return fmt.Errorf("Push: %v", err) + return fmt.Errorf("Push: %w", err) } return nil diff --git a/services/repository/check.go b/services/repository/check.go index 1b2da4cc08..5529a61b39 100644 --- a/services/repository/check.go +++ b/services/repository/check.go @@ -86,7 +86,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...git.CmdArg) if err = system_model.CreateRepositoryNotice(desc); err != nil { log.Error("CreateRepositoryNotice: %v", err) } - return fmt.Errorf("Repository garbage collection failed in repo: %s: Error: %v", repo.FullName(), err) + return fmt.Errorf("Repository garbage collection failed in repo: %s: Error: %w", repo.FullName(), err) } // Now update the size of the repository @@ -96,7 +96,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...git.CmdArg) if err = system_model.CreateRepositoryNotice(desc); err != nil { log.Error("CreateRepositoryNotice: %v", err) } - return fmt.Errorf("Updating size as part of garbage collection failed in repo: %s: Error: %v", repo.FullName(), err) + return fmt.Errorf("Updating size as part of garbage collection failed in repo: %s: Error: %w", repo.FullName(), err) } return nil 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)) diff --git a/services/repository/fork.go b/services/repository/fork.go index af0ade99a9..136d7ccab6 100644 --- a/services/repository/fork.go +++ b/services/repository/fork.go @@ -134,22 +134,22 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork SetDescription(fmt.Sprintf("ForkRepository(git clone): %s to %s", opts.BaseRepo.FullName(), repo.FullName())). RunStdBytes(&git.RunOpts{Timeout: 10 * time.Minute}); err != nil { log.Error("Fork Repository (git clone) Failed for %v (from %v):\nStdout: %s\nError: %v", repo, opts.BaseRepo, stdout, err) - return fmt.Errorf("git clone: %v", err) + return fmt.Errorf("git clone: %w", err) } if err := repo_module.CheckDaemonExportOK(txCtx, repo); err != nil { - return fmt.Errorf("checkDaemonExportOK: %v", err) + return fmt.Errorf("checkDaemonExportOK: %w", err) } if stdout, _, err := git.NewCommand(txCtx, "update-server-info"). SetDescription(fmt.Sprintf("ForkRepository(git update-server-info): %s", repo.FullName())). RunStdString(&git.RunOpts{Dir: repoPath}); err != nil { log.Error("Fork Repository (git update-server-info) failed for %v:\nStdout: %s\nError: %v", repo, stdout, err) - return fmt.Errorf("git update-server-info: %v", err) + return fmt.Errorf("git update-server-info: %w", err) } if err = repo_module.CreateDelegateHooks(repoPath); err != nil { - return fmt.Errorf("createDelegateHooks: %v", err) + return fmt.Errorf("createDelegateHooks: %w", err) } return nil }) diff --git a/services/repository/hooks.go b/services/repository/hooks.go index 45a031f38e..d326cd26b1 100644 --- a/services/repository/hooks.go +++ b/services/repository/hooks.go @@ -36,11 +36,11 @@ func SyncRepositoryHooks(ctx context.Context) error { } if err := repo_module.CreateDelegateHooks(repo.RepoPath()); err != nil { - return fmt.Errorf("SyncRepositoryHook: %v", err) + return fmt.Errorf("SyncRepositoryHook: %w", err) } if repo.HasWiki() { if err := repo_module.CreateDelegateHooks(repo.WikiPath()); err != nil { - return fmt.Errorf("SyncRepositoryHook: %v", err) + return fmt.Errorf("SyncRepositoryHook: %w", err) } } return nil diff --git a/services/repository/push.go b/services/repository/push.go index d645928c43..3a7205d18b 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -84,14 +84,14 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { repo, err := repo_model.GetRepositoryByOwnerAndName(optsList[0].RepoUserName, optsList[0].RepoName) if err != nil { - return fmt.Errorf("GetRepositoryByOwnerAndName failed: %v", err) + return fmt.Errorf("GetRepositoryByOwnerAndName failed: %w", err) } repoPath := repo.RepoPath() gitRepo, err := git.OpenRepository(ctx, repoPath) if err != nil { - return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err) + return fmt.Errorf("OpenRepository[%s]: %w", repoPath, err) } defer gitRepo.Close() @@ -129,7 +129,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } else { // is new tag newCommit, err := gitRepo.GetCommit(opts.NewCommitID) if err != nil { - return fmt.Errorf("gitRepo.GetCommit: %v", err) + return fmt.Errorf("gitRepo.GetCommit: %w", err) } commits := repo_module.NewPushCommits() @@ -162,7 +162,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { newCommit, err := gitRepo.GetCommit(opts.NewCommitID) if err != nil { - return fmt.Errorf("gitRepo.GetCommit: %v", err) + return fmt.Errorf("gitRepo.GetCommit: %w", err) } refName := opts.RefName() @@ -182,19 +182,19 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } // Update the is empty and default_branch columns if err := repo_model.UpdateRepositoryCols(db.DefaultContext, repo, "default_branch", "is_empty"); err != nil { - return fmt.Errorf("UpdateRepositoryCols: %v", err) + return fmt.Errorf("UpdateRepositoryCols: %w", err) } } l, err = newCommit.CommitsBeforeLimit(10) if err != nil { - return fmt.Errorf("newCommit.CommitsBeforeLimit: %v", err) + return fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err) } notification.NotifyCreateRef(pusher, repo, "branch", opts.RefFullName, opts.NewCommitID) } else { l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID) if err != nil { - return fmt.Errorf("newCommit.CommitsBeforeUntil: %v", err) + return fmt.Errorf("newCommit.CommitsBeforeUntil: %w", err) } isForce, err := repo_module.IsForcePush(ctx, opts) @@ -277,12 +277,12 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } } if err := PushUpdateAddDeleteTags(repo, gitRepo, addTags, delTags); err != nil { - return fmt.Errorf("PushUpdateAddDeleteTags: %v", err) + return fmt.Errorf("PushUpdateAddDeleteTags: %w", err) } // Change repository last updated time. if err := repo_model.UpdateRepositoryUpdatedTime(repo.ID, time.Now()); err != nil { - return fmt.Errorf("UpdateRepositoryUpdatedTime: %v", err) + return fmt.Errorf("UpdateRepositoryUpdatedTime: %w", err) } return nil @@ -311,7 +311,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo releases, err := repo_model.GetReleasesByRepoIDAndNames(ctx, repo.ID, lowerTags) if err != nil { - return fmt.Errorf("GetReleasesByRepoIDAndNames: %v", err) + return fmt.Errorf("GetReleasesByRepoIDAndNames: %w", err) } relMap := make(map[string]*repo_model.Release) for _, rel := range releases { @@ -325,11 +325,11 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo for i, lowerTag := range lowerTags { tag, err := gitRepo.GetTag(tags[i]) if err != nil { - return fmt.Errorf("GetTag: %v", err) + return fmt.Errorf("GetTag: %w", err) } commit, err := tag.Commit(gitRepo) if err != nil { - return fmt.Errorf("Commit: %v", err) + return fmt.Errorf("Commit: %w", err) } sig := tag.Tagger @@ -348,7 +348,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo if !ok { author, err = user_model.GetUserByEmailContext(ctx, sig.Email) if err != nil && !user_model.IsErrUserNotExist(err) { - return fmt.Errorf("GetUserByEmail: %v", err) + return fmt.Errorf("GetUserByEmail: %w", err) } if author != nil { emailToUser[sig.Email] = author @@ -359,7 +359,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo commitsCount, err := commit.CommitsCount() if err != nil { - return fmt.Errorf("CommitsCount: %v", err) + return fmt.Errorf("CommitsCount: %w", err) } rel, has := relMap[lowerTag] @@ -393,14 +393,14 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo rel.PublisherID = author.ID } if err = repo_model.UpdateRelease(ctx, rel); err != nil { - return fmt.Errorf("Update: %v", err) + return fmt.Errorf("Update: %w", err) } } } if len(newReleases) > 0 { if err = db.Insert(ctx, newReleases); err != nil { - return fmt.Errorf("Insert: %v", err) + return fmt.Errorf("Insert: %w", err) } } diff --git a/services/repository/repository.go b/services/repository/repository.go index 47687d9a73..763ef74927 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -97,7 +97,7 @@ func UpdateRepository(repo *repo_model.Repository, visibilityChanged bool) (err defer committer.Close() if err = repo_module.UpdateRepository(ctx, repo, visibilityChanged); err != nil { - return fmt.Errorf("updateRepository: %v", err) + return fmt.Errorf("updateRepository: %w", err) } return committer.Commit() |