forked from forgejo/forgejo
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:
parent
7c11a73833
commit
0ebb45cfe7
207 changed files with 857 additions and 857 deletions
|
@ -40,7 +40,7 @@ func init() {
|
|||
func (a *Attachment) IncreaseDownloadCount() error {
|
||||
// Update download count.
|
||||
if _, err := db.GetEngine(db.DefaultContext).Exec("UPDATE `attachment` SET download_count=download_count+1 WHERE id=?", a.ID); err != nil {
|
||||
return fmt.Errorf("increase attachment count: %v", err)
|
||||
return fmt.Errorf("increase attachment count: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -36,7 +36,7 @@ func generateRandomAvatar(ctx context.Context, repo *Repository) error {
|
|||
seed := idToString
|
||||
img, err := avatar.RandomImage([]byte(seed))
|
||||
if err != nil {
|
||||
return fmt.Errorf("RandomImage: %v", err)
|
||||
return fmt.Errorf("RandomImage: %w", err)
|
||||
}
|
||||
|
||||
repo.Avatar = idToString
|
||||
|
@ -47,7 +47,7 @@ func generateRandomAvatar(ctx context.Context, repo *Repository) error {
|
|||
}
|
||||
return err
|
||||
}); err != nil {
|
||||
return fmt.Errorf("Failed to create dir %s: %v", repo.CustomAvatarRelativePath(), err)
|
||||
return fmt.Errorf("Failed to create dir %s: %w", repo.CustomAvatarRelativePath(), err)
|
||||
}
|
||||
|
||||
log.Info("New random avatar created for repository: %d", repo.ID)
|
||||
|
|
|
@ -40,7 +40,7 @@ type Collaborator struct {
|
|||
func GetCollaborators(ctx context.Context, repoID int64, listOptions db.ListOptions) ([]*Collaborator, error) {
|
||||
collaborations, err := getCollaborations(ctx, repoID, listOptions)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getCollaborations: %v", err)
|
||||
return nil, fmt.Errorf("getCollaborations: %w", err)
|
||||
}
|
||||
|
||||
collaborators := make([]*Collaborator, 0, len(collaborations))
|
||||
|
@ -114,7 +114,7 @@ func ChangeCollaborationAccessModeCtx(ctx context.Context, repo *Repository, uid
|
|||
}
|
||||
has, err := e.Get(collaboration)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get collaboration: %v", err)
|
||||
return fmt.Errorf("get collaboration: %w", err)
|
||||
} else if !has {
|
||||
return nil
|
||||
}
|
||||
|
@ -128,9 +128,9 @@ func ChangeCollaborationAccessModeCtx(ctx context.Context, repo *Repository, uid
|
|||
ID(collaboration.ID).
|
||||
Cols("mode").
|
||||
Update(collaboration); err != nil {
|
||||
return fmt.Errorf("update collaboration: %v", err)
|
||||
return fmt.Errorf("update collaboration: %w", err)
|
||||
} else if _, err = e.Exec("UPDATE access SET mode = ? WHERE user_id = ? AND repo_id = ?", mode, uid, repo.ID); err != nil {
|
||||
return fmt.Errorf("update access table: %v", err)
|
||||
return fmt.Errorf("update access table: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -156,7 +156,7 @@ func AddReleaseAttachments(ctx context.Context, releaseID int64, attachmentUUIDs
|
|||
// Check attachments
|
||||
attachments, err := GetAttachmentsByUUIDs(ctx, attachmentUUIDs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", attachmentUUIDs, err)
|
||||
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %w", attachmentUUIDs, err)
|
||||
}
|
||||
|
||||
for i := range attachments {
|
||||
|
@ -166,7 +166,7 @@ func AddReleaseAttachments(ctx context.Context, releaseID int64, attachmentUUIDs
|
|||
attachments[i].ReleaseID = releaseID
|
||||
// No assign value could be 0, so ignore AllCols().
|
||||
if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Update(attachments[i]); err != nil {
|
||||
return fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
|
||||
return fmt.Errorf("update attachment [%d]: %w", attachments[i].ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -413,7 +413,7 @@ func PushUpdateDeleteTagsContext(ctx context.Context, repo *Repository, tags []s
|
|||
Where("repo_id = ? AND is_tag = ?", repo.ID, true).
|
||||
In("lower_tag_name", lowerTags).
|
||||
Delete(new(Release)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
return fmt.Errorf("Delete: %w", err)
|
||||
}
|
||||
|
||||
if _, err := db.GetEngine(ctx).
|
||||
|
@ -423,7 +423,7 @@ func PushUpdateDeleteTagsContext(ctx context.Context, repo *Repository, tags []s
|
|||
Update(&Release{
|
||||
IsDraft: true,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
return fmt.Errorf("Update: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -436,18 +436,18 @@ func PushUpdateDeleteTag(repo *Repository, tagName string) error {
|
|||
if IsErrReleaseNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("GetRelease: %v", err)
|
||||
return fmt.Errorf("GetRelease: %w", err)
|
||||
}
|
||||
if rel.IsTag {
|
||||
if _, err = db.GetEngine(db.DefaultContext).ID(rel.ID).Delete(new(Release)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
return fmt.Errorf("Delete: %w", err)
|
||||
}
|
||||
} else {
|
||||
rel.IsDraft = true
|
||||
rel.NumCommits = 0
|
||||
rel.Sha1 = ""
|
||||
if _, err = db.GetEngine(db.DefaultContext).ID(rel.ID).AllCols().Update(rel); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
return fmt.Errorf("Update: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -458,13 +458,13 @@ func PushUpdateDeleteTag(repo *Repository, tagName string) error {
|
|||
func SaveOrUpdateTag(repo *Repository, newRel *Release) error {
|
||||
rel, err := GetRelease(repo.ID, newRel.TagName)
|
||||
if err != nil && !IsErrReleaseNotExist(err) {
|
||||
return fmt.Errorf("GetRelease: %v", err)
|
||||
return fmt.Errorf("GetRelease: %w", err)
|
||||
}
|
||||
|
||||
if rel == nil {
|
||||
rel = newRel
|
||||
if _, err = db.GetEngine(db.DefaultContext).Insert(rel); err != nil {
|
||||
return fmt.Errorf("InsertOne: %v", err)
|
||||
return fmt.Errorf("InsertOne: %w", err)
|
||||
}
|
||||
} else {
|
||||
rel.Sha1 = newRel.Sha1
|
||||
|
@ -475,7 +475,7 @@ func SaveOrUpdateTag(repo *Repository, newRel *Release) error {
|
|||
rel.PublisherID = newRel.PublisherID
|
||||
}
|
||||
if _, err = db.GetEngine(db.DefaultContext).ID(rel.ID).AllCols().Update(rel); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
return fmt.Errorf("Update: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -760,7 +760,7 @@ func CountRepositories(ctx context.Context, opts CountRepositoryOptions) (int64,
|
|||
|
||||
count, err := sess.Count(new(Repository))
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("countRepositories: %v", err)
|
||||
return 0, fmt.Errorf("countRepositories: %w", err)
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
|
|
@ -95,13 +95,13 @@ func GetIndexerStatus(ctx context.Context, repo *Repository, indexerType RepoInd
|
|||
func UpdateIndexerStatus(ctx context.Context, repo *Repository, indexerType RepoIndexerType, sha string) error {
|
||||
status, err := GetIndexerStatus(ctx, repo, indexerType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to getIndexerStatus for repo: %s Error: %v", repo.FullName(), err)
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to getIndexerStatus for repo: %s Error: %w", repo.FullName(), err)
|
||||
}
|
||||
|
||||
if len(status.CommitSha) == 0 {
|
||||
status.CommitSha = sha
|
||||
if err := db.Insert(ctx, status); err != nil {
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to insert repoIndexerStatus for repo: %s Sha: %s Error: %v", repo.FullName(), sha, err)
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to insert repoIndexerStatus for repo: %s Sha: %s Error: %w", repo.FullName(), sha, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ func UpdateIndexerStatus(ctx context.Context, repo *Repository, indexerType Repo
|
|||
_, err = db.GetEngine(ctx).ID(status.ID).Cols("commit_sha").
|
||||
Update(status)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to update repoIndexerStatus for repo: %s Sha: %s Error: %v", repo.FullName(), sha, err)
|
||||
return fmt.Errorf("UpdateIndexerStatus: Unable to update repoIndexerStatus for repo: %s Sha: %s Error: %w", repo.FullName(), sha, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func (repos RepositoryList) loadAttributes(ctx context.Context) error {
|
|||
Where("id > 0").
|
||||
In("id", set.Values()).
|
||||
Find(&users); err != nil {
|
||||
return fmt.Errorf("find users: %v", err)
|
||||
return fmt.Errorf("find users: %w", err)
|
||||
}
|
||||
for i := range repos {
|
||||
repos[i].Owner = users[repos[i].OwnerID]
|
||||
|
@ -93,7 +93,7 @@ func (repos RepositoryList) loadAttributes(ctx context.Context) error {
|
|||
Where("`is_primary` = ? AND `language` != ?", true, "other").
|
||||
In("`repo_id`", repoIDs).
|
||||
Find(&stats); err != nil {
|
||||
return fmt.Errorf("find primary languages: %v", err)
|
||||
return fmt.Errorf("find primary languages: %w", err)
|
||||
}
|
||||
stats.LoadAttributes()
|
||||
for i := range repos {
|
||||
|
@ -537,7 +537,7 @@ func SearchRepositoryByCondition(opts *SearchRepoOptions, cond builder.Cond, loa
|
|||
}
|
||||
repos := make(RepositoryList, 0, defaultSize)
|
||||
if err := sess.Find(&repos); err != nil {
|
||||
return nil, 0, fmt.Errorf("Repo: %v", err)
|
||||
return nil, 0, fmt.Errorf("Repo: %w", err)
|
||||
}
|
||||
|
||||
if opts.PageSize <= 0 {
|
||||
|
@ -546,7 +546,7 @@ func SearchRepositoryByCondition(opts *SearchRepoOptions, cond builder.Cond, loa
|
|||
|
||||
if loadAttributes {
|
||||
if err := repos.loadAttributes(ctx); err != nil {
|
||||
return nil, 0, fmt.Errorf("LoadAttributes: %v", err)
|
||||
return nil, 0, fmt.Errorf("LoadAttributes: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -582,7 +582,7 @@ func searchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, c
|
|||
Where(cond).
|
||||
Count(new(Repository))
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("Count: %v", err)
|
||||
return nil, 0, fmt.Errorf("Count: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -725,7 +725,7 @@ func GetUserRepositories(opts *SearchRepoOptions) (RepositoryList, int64, error)
|
|||
|
||||
count, err := sess.Where(cond).Count(new(Repository))
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("Count: %v", err)
|
||||
return nil, 0, fmt.Errorf("Count: %w", err)
|
||||
}
|
||||
|
||||
sess = sess.Where(cond).OrderBy(opts.OrderBy.String())
|
||||
|
|
|
@ -119,7 +119,7 @@ func CheckCreateRepository(doer, u *user_model.User, name string, overwriteOrAdo
|
|||
|
||||
has, err := IsRepositoryExist(db.DefaultContext, u, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("IsRepositoryExist: %v", err)
|
||||
return fmt.Errorf("IsRepositoryExist: %w", err)
|
||||
} else if has {
|
||||
return ErrRepoAlreadyExist{u.Name, name}
|
||||
}
|
||||
|
@ -150,14 +150,14 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s
|
|||
|
||||
has, err := IsRepositoryExist(db.DefaultContext, repo.Owner, newRepoName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("IsRepositoryExist: %v", err)
|
||||
return fmt.Errorf("IsRepositoryExist: %w", err)
|
||||
} else if has {
|
||||
return ErrRepoAlreadyExist{repo.Owner.Name, newRepoName}
|
||||
}
|
||||
|
||||
newRepoPath := RepoPath(repo.Owner.Name, newRepoName)
|
||||
if err = util.Rename(repo.RepoPath(), newRepoPath); err != nil {
|
||||
return fmt.Errorf("rename repository directory: %v", err)
|
||||
return fmt.Errorf("rename repository directory: %w", err)
|
||||
}
|
||||
|
||||
wikiPath := repo.WikiPath()
|
||||
|
@ -168,7 +168,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s
|
|||
}
|
||||
if isExist {
|
||||
if err = util.Rename(wikiPath, WikiPath(repo.Owner.Name, newRepoName)); err != nil {
|
||||
return fmt.Errorf("rename repository wiki: %v", err)
|
||||
return fmt.Errorf("rename repository wiki: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,19 +70,19 @@ func NewUpload(name string, buf []byte, file multipart.File) (_ *Upload, err err
|
|||
|
||||
localPath := upload.LocalPath()
|
||||
if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil {
|
||||
return nil, fmt.Errorf("MkdirAll: %v", err)
|
||||
return nil, fmt.Errorf("MkdirAll: %w", err)
|
||||
}
|
||||
|
||||
fw, err := os.Create(localPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Create: %v", err)
|
||||
return nil, fmt.Errorf("Create: %w", err)
|
||||
}
|
||||
defer fw.Close()
|
||||
|
||||
if _, err = fw.Write(buf); err != nil {
|
||||
return nil, fmt.Errorf("Write: %v", err)
|
||||
return nil, fmt.Errorf("Write: %w", err)
|
||||
} else if _, err = io.Copy(fw, file); err != nil {
|
||||
return nil, fmt.Errorf("Copy: %v", err)
|
||||
return nil, fmt.Errorf("Copy: %w", err)
|
||||
}
|
||||
|
||||
if _, err := db.GetEngine(db.DefaultContext).Insert(upload); err != nil {
|
||||
|
@ -134,7 +134,7 @@ func DeleteUploads(uploads ...*Upload) (err error) {
|
|||
if _, err = db.GetEngine(ctx).
|
||||
In("id", ids).
|
||||
Delete(new(Upload)); err != nil {
|
||||
return fmt.Errorf("delete uploads: %v", err)
|
||||
return fmt.Errorf("delete uploads: %w", err)
|
||||
}
|
||||
|
||||
if err = committer.Commit(); err != nil {
|
||||
|
@ -152,7 +152,7 @@ func DeleteUploads(uploads ...*Upload) (err error) {
|
|||
}
|
||||
|
||||
if err := util.Remove(localPath); err != nil {
|
||||
return fmt.Errorf("remove upload: %v", err)
|
||||
return fmt.Errorf("remove upload: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,11 +166,11 @@ func DeleteUploadByUUID(uuid string) error {
|
|||
if IsErrUploadNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("GetUploadByUUID: %v", err)
|
||||
return fmt.Errorf("GetUploadByUUID: %w", err)
|
||||
}
|
||||
|
||||
if err := DeleteUploads(upload); err != nil {
|
||||
return fmt.Errorf("DeleteUpload: %v", err)
|
||||
return fmt.Errorf("DeleteUpload: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue