diff --git a/cmd/admin.go b/cmd/admin.go index 2cf63d384ab..525bc2cfcdb 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -588,7 +588,7 @@ func runCreateUser(c *cli.Context) error { } if err := user_model.CreateUser(u, overwriteDefault); err != nil { - return fmt.Errorf("CreateUser: %v", err) + return fmt.Errorf("CreateUser: %w", err) } if c.Bool("access-token") { @@ -735,7 +735,7 @@ func runRepoSyncReleases(_ *cli.Context) error { Private: true, }) if err != nil { - return fmt.Errorf("SearchRepositoryByName: %v", err) + return fmt.Errorf("SearchRepositoryByName: %w", err) } if len(repos) == 0 { break diff --git a/cmd/cmd.go b/cmd/cmd.go index 36d54bb19f0..f20a9363257 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -68,7 +68,7 @@ Ensure you are running in the correct environment or set the correct configurati If this is the intended configuration file complete the [database] section.`, setting.CustomConf) } if err := db.InitEngine(ctx); err != nil { - return fmt.Errorf("unable to initialize the database using the configuration in %q. Error: %v", setting.CustomConf, err) + return fmt.Errorf("unable to initialize the database using the configuration in %q. Error: %w", setting.CustomConf, err) } return nil } diff --git a/cmd/dump_repo.go b/cmd/dump_repo.go index 72456c61d33..5f41ab69a98 100644 --- a/cmd/dump_repo.go +++ b/cmd/dump_repo.go @@ -166,7 +166,7 @@ func runDumpRepository(ctx *cli.Context) error { // make sure the directory doesn't exist or is empty, prevent from deleting user files repoDir := ctx.String("repo_dir") if exists, err := util.IsExist(repoDir); err != nil { - return fmt.Errorf("unable to stat repo_dir %q: %v", repoDir, err) + return fmt.Errorf("unable to stat repo_dir %q: %w", repoDir, err) } else if exists { if isDir, _ := util.IsDir(repoDir); !isDir { return fmt.Errorf("repo_dir %q already exists but it's not a directory", repoDir) diff --git a/cmd/embedded.go b/cmd/embedded.go index ffdc3d6a636..b71ee6dfe71 100644 --- a/cmd/embedded.go +++ b/cmd/embedded.go @@ -186,11 +186,11 @@ func runViewDo(c *cli.Context) error { data, err := assets[0].Section.Asset(assets[0].Name) if err != nil { - return fmt.Errorf("%s: %v", assets[0].Path, err) + return fmt.Errorf("%s: %w", assets[0].Path, err) } if _, err = os.Stdout.Write(data); err != nil { - return fmt.Errorf("%s: %v", assets[0].Path, err) + return fmt.Errorf("%s: %w", assets[0].Path, err) } return nil @@ -251,11 +251,11 @@ func extractAsset(d string, a asset, overwrite, rename bool) error { data, err := a.Section.Asset(a.Name) if err != nil { - return fmt.Errorf("%s: %v", a.Path, err) + return fmt.Errorf("%s: %w", a.Path, err) } if err := os.MkdirAll(dir, os.ModePerm); err != nil { - return fmt.Errorf("%s: %v", dir, err) + return fmt.Errorf("%s: %w", dir, err) } perms := os.ModePerm & 0o666 @@ -263,7 +263,7 @@ func extractAsset(d string, a asset, overwrite, rename bool) error { fi, err := os.Lstat(dest) if err != nil { if !errors.Is(err, os.ErrNotExist) { - return fmt.Errorf("%s: %v", dest, err) + return fmt.Errorf("%s: %w", dest, err) } } else if !overwrite && !rename { fmt.Printf("%s already exists; skipped.\n", dest) @@ -272,7 +272,7 @@ func extractAsset(d string, a asset, overwrite, rename bool) error { return fmt.Errorf("%s already exists, but it's not a regular file", dest) } else if rename { if err := util.Rename(dest, dest+".bak"); err != nil { - return fmt.Errorf("Error creating backup for %s: %v", dest, err) + return fmt.Errorf("Error creating backup for %s: %w", dest, err) } // Attempt to respect file permissions mask (even if user:group will be set anew) perms = fi.Mode() @@ -280,12 +280,12 @@ func extractAsset(d string, a asset, overwrite, rename bool) error { file, err := os.OpenFile(dest, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, perms) if err != nil { - return fmt.Errorf("%s: %v", dest, err) + return fmt.Errorf("%s: %w", dest, err) } defer file.Close() if _, err = file.Write(data); err != nil { - return fmt.Errorf("%s: %v", dest, err) + return fmt.Errorf("%s: %w", dest, err) } fmt.Println(dest) @@ -325,7 +325,7 @@ func getPatterns(args []string) ([]glob.Glob, error) { pat := make([]glob.Glob, len(args)) for i := range args { if g, err := glob.Compile(args[i], '/'); err != nil { - return nil, fmt.Errorf("'%s': Invalid glob pattern: %v", args[i], err) + return nil, fmt.Errorf("'%s': Invalid glob pattern: %w", args[i], err) } else { pat[i] = g } diff --git a/cmd/hook.go b/cmd/hook.go index ab6d48b5458..3970d27cf24 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -312,7 +312,7 @@ func runHookPostReceive(c *cli.Context) error { // First of all run update-server-info no matter what if _, _, err := git.NewCommand(ctx, "update-server-info").RunStdString(nil); err != nil { - return fmt.Errorf("Failed to call 'git update-server-info': %v", err) + return fmt.Errorf("Failed to call 'git update-server-info': %w", err) } // Now if we're an internal don't do anything else diff --git a/models/activities/action.go b/models/activities/action.go index 3c8acb5ba8c..147511edec6 100644 --- a/models/activities/action.go +++ b/models/activities/action.go @@ -359,11 +359,11 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, error) { actions := make([]*Action, 0, opts.PageSize) if err := sess.Desc("`action`.created_unix").Find(&actions); err != nil { - return nil, fmt.Errorf("Find: %v", err) + return nil, fmt.Errorf("Find: %w", err) } if err := ActionList(actions).loadAttributes(ctx); err != nil { - return nil, fmt.Errorf("LoadAttributes: %v", err) + return nil, fmt.Errorf("LoadAttributes: %w", err) } return actions, nil @@ -415,7 +415,7 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) { env := organization.OrgFromUser(opts.RequestedUser).AccessibleTeamReposEnv(opts.RequestedTeam) teamRepoIDs, err := env.RepoIDs(1, opts.RequestedUser.NumRepos) if err != nil { - return nil, fmt.Errorf("GetTeamRepositories: %v", err) + return nil, fmt.Errorf("GetTeamRepositories: %w", err) } cond = cond.And(builder.In("repo_id", teamRepoIDs)) } @@ -477,14 +477,14 @@ func notifyWatchers(ctx context.Context, actions ...*Action) error { // Add feeds for user self and all watchers. watchers, err = repo_model.GetWatchers(ctx, act.RepoID) if err != nil { - return fmt.Errorf("get watchers: %v", err) + return fmt.Errorf("get watchers: %w", err) } } // Add feed for actioner. act.UserID = act.ActUserID if _, err = e.Insert(act); err != nil { - return fmt.Errorf("insert new actioner: %v", err) + return fmt.Errorf("insert new actioner: %w", err) } if repoChanged { @@ -493,7 +493,7 @@ func notifyWatchers(ctx context.Context, actions ...*Action) error { // check repo owner exist. if err := act.Repo.GetOwner(ctx); err != nil { - return fmt.Errorf("can't get repo owner: %v", err) + return fmt.Errorf("can't get repo owner: %w", err) } } else if act.Repo == nil { act.Repo = repo @@ -504,7 +504,7 @@ func notifyWatchers(ctx context.Context, actions ...*Action) error { act.ID = 0 act.UserID = act.Repo.Owner.ID if err = db.Insert(ctx, act); err != nil { - return fmt.Errorf("insert new actioner: %v", err) + return fmt.Errorf("insert new actioner: %w", err) } } @@ -557,7 +557,7 @@ func notifyWatchers(ctx context.Context, actions ...*Action) error { } if err = db.Insert(ctx, act); err != nil { - return fmt.Errorf("insert new action: %v", err) + return fmt.Errorf("insert new action: %w", err) } } } diff --git a/models/activities/action_list.go b/models/activities/action_list.go index f349b94ac8b..86aa8689e2f 100644 --- a/models/activities/action_list.go +++ b/models/activities/action_list.go @@ -36,7 +36,7 @@ func (actions ActionList) loadUsers(ctx context.Context) (map[int64]*user_model. In("id", userIDs). Find(&userMaps) if err != nil { - return nil, fmt.Errorf("find user: %v", err) + return nil, fmt.Errorf("find user: %w", err) } for _, action := range actions { @@ -62,7 +62,7 @@ func (actions ActionList) loadRepositories(ctx context.Context) error { repoMaps := make(map[int64]*repo_model.Repository, len(repoIDs)) err := db.GetEngine(ctx).In("id", repoIDs).Find(&repoMaps) if err != nil { - return fmt.Errorf("find repository: %v", err) + return fmt.Errorf("find repository: %w", err) } for _, action := range actions { diff --git a/models/activities/notification.go b/models/activities/notification.go index 0a610881674..5748b807a06 100644 --- a/models/activities/notification.go +++ b/models/activities/notification.go @@ -403,7 +403,7 @@ func (n *Notification) loadRepo(ctx context.Context) (err error) { if n.Repository == nil { n.Repository, err = repo_model.GetRepositoryByIDCtx(ctx, n.RepoID) if err != nil { - return fmt.Errorf("getRepositoryByID [%d]: %v", n.RepoID, err) + return fmt.Errorf("getRepositoryByID [%d]: %w", n.RepoID, err) } } return nil @@ -413,7 +413,7 @@ func (n *Notification) loadIssue(ctx context.Context) (err error) { if n.Issue == nil && n.IssueID != 0 { n.Issue, err = issues_model.GetIssueByID(ctx, n.IssueID) if err != nil { - return fmt.Errorf("getIssueByID [%d]: %v", n.IssueID, err) + return fmt.Errorf("getIssueByID [%d]: %w", n.IssueID, err) } return n.Issue.LoadAttributes(ctx) } @@ -440,7 +440,7 @@ func (n *Notification) loadUser(ctx context.Context) (err error) { if n.User == nil { n.User, err = user_model.GetUserByIDCtx(ctx, n.UserID) if err != nil { - return fmt.Errorf("getUserByID [%d]: %v", n.UserID, err) + return fmt.Errorf("getUserByID [%d]: %w", n.UserID, err) } } return nil diff --git a/models/activities/repo_activity.go b/models/activities/repo_activity.go index 3052d65e837..4c8aa7e81d1 100644 --- a/models/activities/repo_activity.go +++ b/models/activities/repo_activity.go @@ -49,32 +49,32 @@ func GetActivityStats(ctx context.Context, repo *repo_model.Repository, timeFrom stats := &ActivityStats{Code: &git.CodeActivityStats{}} if releases { if err := stats.FillReleases(repo.ID, timeFrom); err != nil { - return nil, fmt.Errorf("FillReleases: %v", err) + return nil, fmt.Errorf("FillReleases: %w", err) } } if prs { if err := stats.FillPullRequests(repo.ID, timeFrom); err != nil { - return nil, fmt.Errorf("FillPullRequests: %v", err) + return nil, fmt.Errorf("FillPullRequests: %w", err) } } if issues { if err := stats.FillIssues(repo.ID, timeFrom); err != nil { - return nil, fmt.Errorf("FillIssues: %v", err) + return nil, fmt.Errorf("FillIssues: %w", err) } } if err := stats.FillUnresolvedIssues(repo.ID, timeFrom, issues, prs); err != nil { - return nil, fmt.Errorf("FillUnresolvedIssues: %v", err) + return nil, fmt.Errorf("FillUnresolvedIssues: %w", err) } if code { gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath()) if err != nil { - return nil, fmt.Errorf("OpenRepository: %v", err) + return nil, fmt.Errorf("OpenRepository: %w", err) } defer closer.Close() code, err := gitRepo.GetCodeActivityStats(timeFrom, repo.DefaultBranch) if err != nil { - return nil, fmt.Errorf("FillFromGit: %v", err) + return nil, fmt.Errorf("FillFromGit: %w", err) } stats.Code = code } @@ -85,13 +85,13 @@ func GetActivityStats(ctx context.Context, repo *repo_model.Repository, timeFrom func GetActivityStatsTopAuthors(ctx context.Context, repo *repo_model.Repository, timeFrom time.Time, count int) ([]*ActivityAuthorData, error) { gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath()) if err != nil { - return nil, fmt.Errorf("OpenRepository: %v", err) + return nil, fmt.Errorf("OpenRepository: %w", err) } defer closer.Close() code, err := gitRepo.GetCodeActivityStats(timeFrom, "") if err != nil { - return nil, fmt.Errorf("FillFromGit: %v", err) + return nil, fmt.Errorf("FillFromGit: %w", err) } if code.Authors == nil { return nil, nil diff --git a/models/asymkey/gpg_key.go b/models/asymkey/gpg_key.go index 78dc453e0de..83774533aa7 100644 --- a/models/asymkey/gpg_key.go +++ b/models/asymkey/gpg_key.go @@ -226,7 +226,7 @@ func DeleteGPGKey(doer *user_model.User, id int64) (err error) { if IsErrGPGKeyNotExist(err) { return nil } - return fmt.Errorf("GetPublicKeyByID: %v", err) + return fmt.Errorf("GetPublicKeyByID: %w", err) } // Check if user has access to delete this key. diff --git a/models/asymkey/ssh_key.go b/models/asymkey/ssh_key.go index 9f95bb5baf8..7ed4ad6b3f4 100644 --- a/models/asymkey/ssh_key.go +++ b/models/asymkey/ssh_key.go @@ -130,7 +130,7 @@ func AddPublicKey(ownerID int64, name, content string, authSourceID int64) (*Pub LoginSourceID: authSourceID, } if err = addKey(ctx, key); err != nil { - return nil, fmt.Errorf("addKey: %v", err) + return nil, fmt.Errorf("addKey: %w", err) } return key, committer.Commit() diff --git a/models/asymkey/ssh_key_deploy.go b/models/asymkey/ssh_key_deploy.go index fd8388e61d5..d5c981da47b 100644 --- a/models/asymkey/ssh_key_deploy.go +++ b/models/asymkey/ssh_key_deploy.go @@ -151,7 +151,7 @@ func AddDeployKey(repoID int64, name, content string, readOnly bool) (*DeployKey pkey.Content = content pkey.Name = name if err = addKey(ctx, pkey); err != nil { - return nil, fmt.Errorf("addKey: %v", err) + return nil, fmt.Errorf("addKey: %w", err) } } diff --git a/models/asymkey/ssh_key_fingerprint.go b/models/asymkey/ssh_key_fingerprint.go index 747a7e6473c..788d58dbabd 100644 --- a/models/asymkey/ssh_key_fingerprint.go +++ b/models/asymkey/ssh_key_fingerprint.go @@ -95,7 +95,7 @@ func CalcFingerprint(publicKeyContent string) (string, error) { log.Info("%s", publicKeyContent) return "", err } - return "", fmt.Errorf("%s: %v", fnName, err) + return "", fmt.Errorf("%s: %w", fnName, err) } return fp, nil } diff --git a/models/asymkey/ssh_key_parse.go b/models/asymkey/ssh_key_parse.go index 3f52a4e9e09..2462310ed97 100644 --- a/models/asymkey/ssh_key_parse.go +++ b/models/asymkey/ssh_key_parse.go @@ -44,7 +44,7 @@ const ssh2keyStart = "---- BEGIN SSH2 PUBLIC KEY ----" func extractTypeFromBase64Key(key string) (string, error) { b, err := base64.StdEncoding.DecodeString(key) if err != nil || len(b) < 4 { - return "", fmt.Errorf("invalid key format: %v", err) + return "", fmt.Errorf("invalid key format: %w", err) } keyLength := int(binary.BigEndian.Uint32(b)) @@ -85,7 +85,7 @@ func parseKeyString(content string) (string, error) { t, err := extractTypeFromBase64Key(keyContent) if err != nil { - return "", fmt.Errorf("extractTypeFromBase64Key: %v", err) + return "", fmt.Errorf("extractTypeFromBase64Key: %w", err) } keyType = t } else { @@ -104,14 +104,14 @@ func parseKeyString(content string) (string, error) { var pk rsa.PublicKey _, err2 := asn1.Unmarshal(block.Bytes, &pk) if err2 != nil { - return "", fmt.Errorf("failed to parse DER encoded public key as either PKIX or PEM RSA Key: %v %v", err, err2) + return "", fmt.Errorf("failed to parse DER encoded public key as either PKIX or PEM RSA Key: %v %w", err, err2) } pub = &pk } sshKey, err := ssh.NewPublicKey(pub) if err != nil { - return "", fmt.Errorf("unable to convert to ssh public key: %v", err) + return "", fmt.Errorf("unable to convert to ssh public key: %w", err) } content = string(ssh.MarshalAuthorizedKey(sshKey)) } @@ -138,7 +138,7 @@ func parseKeyString(content string) (string, error) { // If keyType is not given, extract it from content. If given, validate it. t, err := extractTypeFromBase64Key(keyContent) if err != nil { - return "", fmt.Errorf("extractTypeFromBase64Key: %v", err) + return "", fmt.Errorf("extractTypeFromBase64Key: %w", err) } if len(keyType) == 0 { keyType = t @@ -149,7 +149,7 @@ func parseKeyString(content string) (string, error) { // Finally we need to check whether we can actually read the proposed key: _, _, _, _, err := ssh.ParseAuthorizedKey([]byte(keyType + " " + keyContent + " " + keyComment)) if err != nil { - return "", fmt.Errorf("invalid ssh public key: %v", err) + return "", fmt.Errorf("invalid ssh public key: %w", err) } return keyType + " " + keyContent + " " + keyComment, nil } @@ -191,7 +191,7 @@ func CheckPublicKeyString(content string) (_ string, err error) { keyType, length, err = SSHKeyGenParsePublicKey(content) } if err != nil { - return "", fmt.Errorf("%s: %v", fnName, err) + return "", fmt.Errorf("%s: %w", fnName, err) } log.Trace("Key info [native: %v]: %s-%d", setting.SSH.StartBuiltinServer, keyType, length) @@ -220,7 +220,7 @@ func SSHNativeParsePublicKey(keyLine string) (string, int, error) { if strings.Contains(err.Error(), "ssh: unknown key algorithm") { return "", 0, ErrKeyUnableVerify{err.Error()} } - return "", 0, fmt.Errorf("ParsePublicKey: %v", err) + return "", 0, fmt.Errorf("ParsePublicKey: %w", err) } // The ssh library can parse the key, so next we find out what key exactly we have. @@ -267,12 +267,12 @@ func SSHNativeParsePublicKey(keyLine string) (string, int, error) { func writeTmpKeyFile(content string) (string, error) { tmpFile, err := os.CreateTemp(setting.SSH.KeyTestPath, "gitea_keytest") if err != nil { - return "", fmt.Errorf("TempFile: %v", err) + return "", fmt.Errorf("TempFile: %w", err) } defer tmpFile.Close() if _, err = tmpFile.WriteString(content); err != nil { - return "", fmt.Errorf("WriteString: %v", err) + return "", fmt.Errorf("WriteString: %w", err) } return tmpFile.Name(), nil } @@ -281,7 +281,7 @@ func writeTmpKeyFile(content string) (string, error) { func SSHKeyGenParsePublicKey(key string) (string, int, error) { tmpName, err := writeTmpKeyFile(key) if err != nil { - return "", 0, fmt.Errorf("writeTmpKeyFile: %v", err) + return "", 0, fmt.Errorf("writeTmpKeyFile: %w", err) } defer func() { if err := util.Remove(tmpName); err != nil { diff --git a/models/asymkey/ssh_key_principals.go b/models/asymkey/ssh_key_principals.go index 7a5c234f6fd..e0d407af356 100644 --- a/models/asymkey/ssh_key_principals.go +++ b/models/asymkey/ssh_key_principals.go @@ -51,7 +51,7 @@ func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*Public LoginSourceID: authSourceID, } if err = db.Insert(ctx, key); err != nil { - return nil, fmt.Errorf("addKey: %v", err) + return nil, fmt.Errorf("addKey: %w", err) } if err = committer.Commit(); err != nil { diff --git a/models/auth/oauth2.go b/models/auth/oauth2.go index e42084c086b..ccd9336f651 100644 --- a/models/auth/oauth2.go +++ b/models/auth/oauth2.go @@ -570,7 +570,7 @@ func DeleteOAuth2RelictsByUserID(ctx context.Context, userID int64) error { &OAuth2Application{UID: userID}, &OAuth2Grant{UserID: userID}, ); err != nil { - return fmt.Errorf("DeleteBeans: %v", err) + return fmt.Errorf("DeleteBeans: %w", err) } return nil diff --git a/models/auth/token.go b/models/auth/token.go index 3afef832da8..17c07531f85 100644 --- a/models/auth/token.go +++ b/models/auth/token.go @@ -86,7 +86,7 @@ func init() { var err error successfulAccessTokenCache, err = lru.New(setting.SuccessfulTokensCacheSize) if err != nil { - return fmt.Errorf("unable to allocate AccessToken cache: %v", err) + return fmt.Errorf("unable to allocate AccessToken cache: %w", err) } } else { successfulAccessTokenCache = nil diff --git a/models/db/engine.go b/models/db/engine.go index f0c9ec46e9b..41949eb6f60 100755 --- a/models/db/engine.go +++ b/models/db/engine.go @@ -130,7 +130,7 @@ func SyncAllTables() error { func InitEngine(ctx context.Context) error { xormEngine, err := newXORMEngine() if err != nil { - return fmt.Errorf("failed to connect to database: %v", err) + return fmt.Errorf("failed to connect to database: %w", err) } xormEngine.SetMapper(names.GonicMapper{}) @@ -189,16 +189,16 @@ func InitEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.Engine) // However, we should think carefully about should we support re-install on an installed instance, // as there may be other problems due to secret reinitialization. if err = migrateFunc(x); err != nil { - return fmt.Errorf("migrate: %v", err) + return fmt.Errorf("migrate: %w", err) } if err = SyncAllTables(); err != nil { - return fmt.Errorf("sync database struct error: %v", err) + return fmt.Errorf("sync database struct error: %w", err) } for _, initFunc := range initFuncs { if err := initFunc(); err != nil { - return fmt.Errorf("initFunc failed: %v", err) + return fmt.Errorf("initFunc failed: %w", err) } } diff --git a/models/git/branches.go b/models/git/branches.go index 7f05a566769..b17d762dbe5 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 9e24221862e..620baa036cb 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 1dab31d5f98..58042edfdbe 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 } diff --git a/models/issues/assignees.go b/models/issues/assignees.go index 7f589f5d7e8..d960d5ebafe 100644 --- a/models/issues/assignees.go +++ b/models/issues/assignees.go @@ -85,12 +85,12 @@ func ToggleIssueAssignee(issue *Issue, doer *user_model.User, assigneeID int64) func toggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.User, assigneeID int64, isCreate bool) (removed bool, comment *Comment, err error) { removed, err = toggleUserAssignee(ctx, issue, assigneeID) if err != nil { - return false, nil, fmt.Errorf("UpdateIssueUserByAssignee: %v", err) + return false, nil, fmt.Errorf("UpdateIssueUserByAssignee: %w", err) } // Repo infos if err = issue.LoadRepo(ctx); err != nil { - return false, nil, fmt.Errorf("loadRepo: %v", err) + return false, nil, fmt.Errorf("loadRepo: %w", err) } opts := &CreateCommentOptions{ @@ -104,7 +104,7 @@ func toggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.Use // Comment comment, err = CreateCommentCtx(ctx, opts) if err != nil { - return false, nil, fmt.Errorf("createComment: %v", err) + return false, nil, fmt.Errorf("createComment: %w", err) } // if pull request is in the middle of creation - don't call webhook diff --git a/models/issues/comment.go b/models/issues/comment.go index 9ab6cab7d08..bdc574252cc 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -573,13 +573,13 @@ func (c *Comment) UpdateAttachments(uuids []string) error { attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, uuids) if err != nil { - return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", uuids, err) + return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", uuids, err) } for i := 0; i < len(attachments); i++ { attachments[i].IssueID = c.IssueID attachments[i].CommentID = c.ID if err := repo_model.UpdateAttachment(ctx, attachments[i]); err != nil { - return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err) + return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err) } } return committer.Commit() @@ -874,7 +874,7 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment // Check attachments attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, opts.Attachments) if err != nil { - return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", opts.Attachments, err) + return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", opts.Attachments, err) } for i := range attachments { @@ -882,7 +882,7 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment attachments[i].CommentID = comment.ID // 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) } } case CommentTypeReopen, CommentTypeClose: @@ -1034,7 +1034,7 @@ func CreateRefComment(doer *user_model.User, repo *repo_model.Repository, issue CommitSHA: commitSHA, }) if err != nil { - return fmt.Errorf("check reference comment: %v", err) + return fmt.Errorf("check reference comment: %w", err) } else if has { return nil } @@ -1152,7 +1152,7 @@ func UpdateComment(c *Comment, doer *user_model.User) error { return err } if err := committer.Commit(); err != nil { - return fmt.Errorf("Commit: %v", err) + return fmt.Errorf("Commit: %w", err) } return nil diff --git a/models/issues/issue.go b/models/issues/issue.go index f77166db111..b1b140732bd 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -196,7 +196,7 @@ func (issue *Issue) LoadRepo(ctx context.Context) (err error) { if issue.Repo == nil { issue.Repo, err = repo_model.GetRepositoryByIDCtx(ctx, issue.RepoID) if err != nil { - return fmt.Errorf("getRepositoryByID [%d]: %v", issue.RepoID, err) + return fmt.Errorf("getRepositoryByID [%d]: %w", issue.RepoID, err) } } return nil @@ -234,7 +234,7 @@ func (issue *Issue) LoadLabels(ctx context.Context) (err error) { if issue.Labels == nil { issue.Labels, err = GetLabelsByIssueID(ctx, issue.ID) if err != nil { - return fmt.Errorf("getLabelsByIssueID [%d]: %v", issue.ID, err) + return fmt.Errorf("getLabelsByIssueID [%d]: %w", issue.ID, err) } } return nil @@ -252,7 +252,7 @@ func (issue *Issue) loadPoster(ctx context.Context) (err error) { issue.PosterID = -1 issue.Poster = user_model.NewGhostUser() if !user_model.IsErrUserNotExist(err) { - return fmt.Errorf("getUserByID.(poster) [%d]: %v", issue.PosterID, err) + return fmt.Errorf("getUserByID.(poster) [%d]: %w", issue.PosterID, err) } err = nil return @@ -268,7 +268,7 @@ func (issue *Issue) loadPullRequest(ctx context.Context) (err error) { if IsErrPullRequestNotExist(err) { return err } - return fmt.Errorf("getPullRequestByIssueID [%d]: %v", issue.ID, err) + return fmt.Errorf("getPullRequestByIssueID [%d]: %w", issue.ID, err) } issue.PullRequest.Issue = issue } @@ -361,7 +361,7 @@ func (issue *Issue) loadMilestone(ctx context.Context) (err error) { if (issue.Milestone == nil || issue.Milestone.ID != issue.MilestoneID) && issue.MilestoneID > 0 { issue.Milestone, err = GetMilestoneByRepoID(ctx, issue.RepoID, issue.MilestoneID) if err != nil && !IsErrMilestoneNotExist(err) { - return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %v", issue.RepoID, issue.MilestoneID, err) + return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %w", issue.RepoID, issue.MilestoneID, err) } } return nil @@ -401,7 +401,7 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) { if issue.Attachments == nil { issue.Attachments, err = repo_model.GetAttachmentsByIssueID(ctx, issue.ID) if err != nil { - return fmt.Errorf("getAttachmentsByIssueID [%d]: %v", issue.ID, err) + return fmt.Errorf("getAttachmentsByIssueID [%d]: %w", issue.ID, err) } } @@ -518,19 +518,19 @@ func (issue *Issue) getLabels(ctx context.Context) (err error) { issue.Labels, err = GetLabelsByIssueID(ctx, issue.ID) if err != nil { - return fmt.Errorf("getLabelsByIssueID: %v", err) + return fmt.Errorf("getLabelsByIssueID: %w", err) } return nil } func clearIssueLabels(ctx context.Context, issue *Issue, doer *user_model.User) (err error) { if err = issue.getLabels(ctx); err != nil { - return fmt.Errorf("getLabels: %v", err) + return fmt.Errorf("getLabels: %w", err) } for i := range issue.Labels { if err = deleteIssueLabel(ctx, issue, issue.Labels[i], doer); err != nil { - return fmt.Errorf("removeLabel: %v", err) + return fmt.Errorf("removeLabel: %w", err) } } @@ -565,7 +565,7 @@ func ClearIssueLabels(issue *Issue, doer *user_model.User) (err error) { } if err = committer.Commit(); err != nil { - return fmt.Errorf("Commit: %v", err) + return fmt.Errorf("Commit: %w", err) } return nil @@ -635,13 +635,13 @@ func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (e if len(toAdd) > 0 { if err = newIssueLabels(ctx, issue, toAdd, doer); err != nil { - return fmt.Errorf("addLabels: %v", err) + return fmt.Errorf("addLabels: %w", err) } } for _, l := range toRemove { if err = deleteIssueLabel(ctx, issue, l, doer); err != nil { - return fmt.Errorf("removeLabel: %v", err) + return fmt.Errorf("removeLabel: %w", err) } } @@ -766,11 +766,11 @@ func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err defer committer.Close() if err = UpdateIssueCols(ctx, issue, "name"); err != nil { - return fmt.Errorf("updateIssueCols: %v", err) + return fmt.Errorf("updateIssueCols: %w", err) } if err = issue.LoadRepo(ctx); err != nil { - return fmt.Errorf("loadRepo: %v", err) + return fmt.Errorf("loadRepo: %w", err) } opts := &CreateCommentOptions{ @@ -782,7 +782,7 @@ func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err NewTitle: issue.Title, } if _, err = CreateCommentCtx(ctx, opts); err != nil { - return fmt.Errorf("createComment: %v", err) + return fmt.Errorf("createComment: %w", err) } if err = issue.AddCrossReferences(ctx, doer, true); err != nil { return err @@ -800,11 +800,11 @@ func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err err defer committer.Close() if err = UpdateIssueCols(ctx, issue, "ref"); err != nil { - return fmt.Errorf("updateIssueCols: %v", err) + return fmt.Errorf("updateIssueCols: %w", err) } if err = issue.LoadRepo(ctx); err != nil { - return fmt.Errorf("loadRepo: %v", err) + return fmt.Errorf("loadRepo: %w", err) } oldRefFriendly := strings.TrimPrefix(oldRef, git.BranchPrefix) newRefFriendly := strings.TrimPrefix(issue.Ref, git.BranchPrefix) @@ -818,7 +818,7 @@ func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err err NewRef: newRefFriendly, } if _, err = CreateCommentCtx(ctx, opts); err != nil { - return fmt.Errorf("createComment: %v", err) + return fmt.Errorf("createComment: %w", err) } return committer.Commit() @@ -850,12 +850,12 @@ func UpdateIssueAttachments(issueID int64, uuids []string) (err error) { defer committer.Close() attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, uuids) if err != nil { - return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", uuids, err) + return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", uuids, err) } for i := 0; i < len(attachments); i++ { attachments[i].IssueID = issueID if err := repo_model.UpdateAttachment(ctx, attachments[i]); err != nil { - return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err) + return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err) } } return committer.Commit() @@ -871,28 +871,28 @@ func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (er hasContentHistory, err := HasIssueContentHistory(ctx, issue.ID, 0) if err != nil { - return fmt.Errorf("HasIssueContentHistory: %v", err) + return fmt.Errorf("HasIssueContentHistory: %w", err) } if !hasContentHistory { if err = SaveIssueContentHistory(ctx, issue.PosterID, issue.ID, 0, issue.CreatedUnix, issue.Content, true); err != nil { - return fmt.Errorf("SaveIssueContentHistory: %v", err) + return fmt.Errorf("SaveIssueContentHistory: %w", err) } } issue.Content = content if err = UpdateIssueCols(ctx, issue, "content"); err != nil { - return fmt.Errorf("UpdateIssueCols: %v", err) + return fmt.Errorf("UpdateIssueCols: %w", err) } if err = SaveIssueContentHistory(ctx, doer.ID, issue.ID, 0, timeutil.TimeStampNow(), issue.Content, false); err != nil { - return fmt.Errorf("SaveIssueContentHistory: %v", err) + return fmt.Errorf("SaveIssueContentHistory: %w", err) } if err = issue.AddCrossReferences(ctx, doer, true); err != nil { - return fmt.Errorf("addCrossReferences: %v", err) + return fmt.Errorf("addCrossReferences: %w", err) } return committer.Commit() @@ -969,7 +969,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue if opts.Issue.MilestoneID > 0 { milestone, err := GetMilestoneByRepoID(ctx, opts.Issue.RepoID, opts.Issue.MilestoneID) if err != nil && !IsErrMilestoneNotExist(err) { - return fmt.Errorf("getMilestoneByID: %v", err) + return fmt.Errorf("getMilestoneByID: %w", err) } // Assume milestone is invalid and drop silently. @@ -1023,7 +1023,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue // So we have to get all needed labels first. labels := make([]*Label, 0, len(opts.LabelIDs)) if err = e.In("id", opts.LabelIDs).Find(&labels); err != nil { - return fmt.Errorf("find all labels [label_ids: %v]: %v", opts.LabelIDs, err) + return fmt.Errorf("find all labels [label_ids: %v]: %w", opts.LabelIDs, err) } if err = opts.Issue.loadPoster(ctx); err != nil { @@ -1037,7 +1037,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue } if err = newIssueLabel(ctx, opts.Issue, label, opts.Issue.Poster); err != nil { - return fmt.Errorf("addLabel [id: %d]: %v", label.ID, err) + return fmt.Errorf("addLabel [id: %d]: %w", label.ID, err) } } } @@ -1049,13 +1049,13 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue if len(opts.Attachments) > 0 { attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, opts.Attachments) if err != nil { - return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", opts.Attachments, err) + return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", opts.Attachments, err) } for i := 0; i < len(attachments); i++ { attachments[i].IssueID = opts.Issue.ID if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil { - return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err) + return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err) } } } @@ -1090,11 +1090,11 @@ func NewIssue(repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) || IsErrNewIssueInsert(err) { return err } - return fmt.Errorf("newIssue: %v", err) + return fmt.Errorf("newIssue: %w", err) } if err = committer.Commit(); err != nil { - return fmt.Errorf("Commit: %v", err) + return fmt.Errorf("Commit: %w", err) } return nil @@ -1614,7 +1614,7 @@ func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*user_mo ids[i] = u.ID } if err := UpdateIssueUsersByMentions(ctx, issueID, ids); err != nil { - return fmt.Errorf("UpdateIssueUsersByMentions: %v", err) + return fmt.Errorf("UpdateIssueUsersByMentions: %w", err) } return nil } @@ -1992,7 +1992,7 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment defer committer.Close() if err := issue.LoadRepo(ctx); err != nil { - return nil, false, fmt.Errorf("loadRepo: %v", err) + return nil, false, fmt.Errorf("loadRepo: %w", err) } // Reload the issue @@ -2020,7 +2020,7 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment } _, err := CreateCommentCtx(ctx, opts) if err != nil { - return nil, false, fmt.Errorf("createComment: %v", err) + return nil, false, fmt.Errorf("createComment: %w", err) } } @@ -2056,7 +2056,7 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *us // Make the comment if _, err = createDeadlineComment(ctx, doer, issue, deadlineUnix); err != nil { - return fmt.Errorf("createRemovedDueDateComment: %v", err) + return fmt.Errorf("createRemovedDueDateComment: %w", err) } return committer.Commit() @@ -2093,7 +2093,7 @@ func (issue *Issue) GetParticipantIDsByIssue(ctx context.Context) ([]int64, erro Join("INNER", "`user`", "`user`.id = `comment`.poster_id"). Distinct("poster_id"). Find(&userIDs); err != nil { - return nil, fmt.Errorf("get poster IDs: %v", err) + return nil, fmt.Errorf("get poster IDs: %w", err) } if !util.IsInt64InSlice(issue.PosterID, userIDs) { return append(userIDs, issue.PosterID), nil @@ -2151,10 +2151,10 @@ func FindAndUpdateIssueMentions(ctx context.Context, issue *Issue, doer *user_mo rawMentions := references.FindAllMentionsMarkdown(content) mentions, err = ResolveIssueMentionsByVisibility(ctx, issue, doer, rawMentions) if err != nil { - return nil, fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err) + return nil, fmt.Errorf("UpdateIssueMentions [%d]: %w", issue.ID, err) } if err = UpdateIssueMentions(ctx, issue.ID, mentions); err != nil { - return nil, fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err) + return nil, fmt.Errorf("UpdateIssueMentions [%d]: %w", issue.ID, err) } return mentions, err } @@ -2206,7 +2206,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u Where("team_repo.repo_id=?", issue.Repo.ID). In("team.lower_name", mentionTeams). Find(&teams); err != nil { - return nil, fmt.Errorf("find mentioned teams: %v", err) + return nil, fmt.Errorf("find mentioned teams: %w", err) } if len(teams) != 0 { checked := make([]int64, 0, len(teams)) @@ -2222,7 +2222,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u } has, err := db.GetEngine(ctx).Get(&organization.TeamUnit{OrgID: issue.Repo.Owner.ID, TeamID: team.ID, Type: unittype}) if err != nil { - return nil, fmt.Errorf("get team units (%d): %v", team.ID, err) + return nil, fmt.Errorf("get team units (%d): %w", team.ID, err) } if has { checked = append(checked, team.ID) @@ -2237,7 +2237,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u And("`user`.is_active = ?", true). And("`user`.prohibit_login = ?", false). Find(&teamusers); err != nil { - return nil, fmt.Errorf("get teams users: %v", err) + return nil, fmt.Errorf("get teams users: %w", err) } if len(teamusers) > 0 { users = make([]*user_model.User, 0, len(teamusers)) @@ -2273,7 +2273,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u And("`user`.prohibit_login = ?", false). In("`user`.lower_name", mentionUsers). Find(&unchecked); err != nil { - return nil, fmt.Errorf("find mentioned users: %v", err) + return nil, fmt.Errorf("find mentioned users: %w", err) } for _, user := range unchecked { if already := resolved[user.LowerName]; already || user.IsOrganization() { @@ -2282,7 +2282,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u // Normal users must have read access to the referencing issue perm, err := access_model.GetUserRepoPermission(ctx, issue.Repo, user) if err != nil { - return nil, fmt.Errorf("GetUserRepoPermission [%d]: %v", user.ID, err) + return nil, fmt.Errorf("GetUserRepoPermission [%d]: %w", user.ID, err) } if !perm.CanReadIssuesOrPulls(issue.IsPull) { continue diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index deadb6a5649..bbe2292dd1d 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -51,7 +51,7 @@ func (issues IssueList) loadRepositories(ctx context.Context) ([]*repo_model.Rep In("id", repoIDs[:limit]). Find(&repoMaps) if err != nil { - return nil, fmt.Errorf("find repository: %v", err) + return nil, fmt.Errorf("find repository: %w", err) } left -= limit repoIDs = repoIDs[limit:] @@ -161,7 +161,7 @@ func (issues IssueList) loadLabels(ctx context.Context) error { err = rows.Scan(&labelIssue) if err != nil { if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadLabels: Close: %v", err1) + return fmt.Errorf("IssueList.loadLabels: Close: %w", err1) } return err } @@ -170,7 +170,7 @@ func (issues IssueList) loadLabels(ctx context.Context) error { // When there are no rows left and we try to close it. // Since that is not relevant for us, we can safely ignore it. if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadLabels: Close: %v", err1) + return fmt.Errorf("IssueList.loadLabels: Close: %w", err1) } left -= limit issueIDs = issueIDs[limit:] @@ -287,7 +287,7 @@ func (issues IssueList) loadAssignees(ctx context.Context) error { err = rows.Scan(&assigneeIssue) if err != nil { if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadAssignees: Close: %v", err1) + return fmt.Errorf("IssueList.loadAssignees: Close: %w", err1) } return err } @@ -295,7 +295,7 @@ func (issues IssueList) loadAssignees(ctx context.Context) error { assignees[assigneeIssue.IssueAssignee.IssueID] = append(assignees[assigneeIssue.IssueAssignee.IssueID], assigneeIssue.Assignee) } if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadAssignees: Close: %v", err1) + return fmt.Errorf("IssueList.loadAssignees: Close: %w", err1) } left -= limit issueIDs = issueIDs[limit:] @@ -342,14 +342,14 @@ func (issues IssueList) loadPullRequests(ctx context.Context) error { err = rows.Scan(&pr) if err != nil { if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadPullRequests: Close: %v", err1) + return fmt.Errorf("IssueList.loadPullRequests: Close: %w", err1) } return err } pullRequestMaps[pr.IssueID] = &pr } if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadPullRequests: Close: %v", err1) + return fmt.Errorf("IssueList.loadPullRequests: Close: %w", err1) } left -= limit issuesIDs = issuesIDs[limit:] @@ -387,14 +387,14 @@ func (issues IssueList) loadAttachments(ctx context.Context) (err error) { err = rows.Scan(&attachment) if err != nil { if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadAttachments: Close: %v", err1) + return fmt.Errorf("IssueList.loadAttachments: Close: %w", err1) } return err } attachments[attachment.IssueID] = append(attachments[attachment.IssueID], &attachment) } if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadAttachments: Close: %v", err1) + return fmt.Errorf("IssueList.loadAttachments: Close: %w", err1) } left -= limit issuesIDs = issuesIDs[limit:] @@ -433,14 +433,14 @@ func (issues IssueList) loadComments(ctx context.Context, cond builder.Cond) (er err = rows.Scan(&comment) if err != nil { if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadComments: Close: %v", err1) + return fmt.Errorf("IssueList.loadComments: Close: %w", err1) } return err } comments[comment.IssueID] = append(comments[comment.IssueID], &comment) } if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadComments: Close: %v", err1) + return fmt.Errorf("IssueList.loadComments: Close: %w", err1) } left -= limit issuesIDs = issuesIDs[limit:] @@ -492,14 +492,14 @@ func (issues IssueList) loadTotalTrackedTimes(ctx context.Context) (err error) { err = rows.Scan(&totalTime) if err != nil { if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadTotalTrackedTimes: Close: %v", err1) + return fmt.Errorf("IssueList.loadTotalTrackedTimes: Close: %w", err1) } return err } trackedTimes[totalTime.IssueID] = totalTime.Time } if err1 := rows.Close(); err1 != nil { - return fmt.Errorf("IssueList.loadTotalTrackedTimes: Close: %v", err1) + return fmt.Errorf("IssueList.loadTotalTrackedTimes: Close: %w", err1) } left -= limit ids = ids[limit:] @@ -514,35 +514,35 @@ func (issues IssueList) loadTotalTrackedTimes(ctx context.Context) (err error) { // loadAttributes loads all attributes, expect for attachments and comments func (issues IssueList) loadAttributes(ctx context.Context) error { if _, err := issues.loadRepositories(ctx); err != nil { - return fmt.Errorf("issue.loadAttributes: loadRepositories: %v", err) + return fmt.Errorf("issue.loadAttributes: loadRepositories: %w", err) } if err := issues.loadPosters(ctx); err != nil { - return fmt.Errorf("issue.loadAttributes: loadPosters: %v", err) + return fmt.Errorf("issue.loadAttributes: loadPosters: %w", err) } if err := issues.loadLabels(ctx); err != nil { - return fmt.Errorf("issue.loadAttributes: loadLabels: %v", err) + return fmt.Errorf("issue.loadAttributes: loadLabels: %w", err) } if err := issues.loadMilestones(ctx); err != nil { - return fmt.Errorf("issue.loadAttributes: loadMilestones: %v", err) + return fmt.Errorf("issue.loadAttributes: loadMilestones: %w", err) } if err := issues.loadProjects(ctx); err != nil { - return fmt.Errorf("issue.loadAttributes: loadProjects: %v", err) + return fmt.Errorf("issue.loadAttributes: loadProjects: %w", err) } if err := issues.loadAssignees(ctx); err != nil { - return fmt.Errorf("issue.loadAttributes: loadAssignees: %v", err) + return fmt.Errorf("issue.loadAttributes: loadAssignees: %w", err) } if err := issues.loadPullRequests(ctx); err != nil { - return fmt.Errorf("issue.loadAttributes: loadPullRequests: %v", err) + return fmt.Errorf("issue.loadAttributes: loadPullRequests: %w", err) } if err := issues.loadTotalTrackedTimes(ctx); err != nil { - return fmt.Errorf("issue.loadAttributes: loadTotalTrackedTimes: %v", err) + return fmt.Errorf("issue.loadAttributes: loadTotalTrackedTimes: %w", err) } return nil diff --git a/models/issues/issue_user.go b/models/issues/issue_user.go index f5d22589af3..c1a68c96e81 100644 --- a/models/issues/issue_user.go +++ b/models/issues/issue_user.go @@ -29,7 +29,7 @@ func init() { func NewIssueUsers(ctx context.Context, repo *repo_model.Repository, issue *Issue) error { assignees, err := repo_model.GetRepoAssignees(ctx, repo) if err != nil { - return fmt.Errorf("getAssignees: %v", err) + return fmt.Errorf("getAssignees: %w", err) } // Poster can be anyone, append later if not one of assignees. diff --git a/models/issues/issue_xref.go b/models/issues/issue_xref.go index 6de91058e80..e389f63d72a 100644 --- a/models/issues/issue_xref.go +++ b/models/issues/issue_xref.go @@ -334,7 +334,7 @@ func (pr *PullRequest) ResolveCrossReferences(ctx context.Context) ([]*Comment, In("ref_action", []references.XRefAction{references.XRefActionCloses, references.XRefActionReopens}). OrderBy("id"). Find(&unfiltered); err != nil { - return nil, fmt.Errorf("get reference: %v", err) + return nil, fmt.Errorf("get reference: %w", err) } refs := make([]*Comment, 0, len(unfiltered)) diff --git a/models/issues/label.go b/models/issues/label.go index be97454e26f..bbdc99e2651 100644 --- a/models/issues/label.go +++ b/models/issues/label.go @@ -667,7 +667,7 @@ func newIssueLabels(ctx context.Context, issue *Issue, labels []*Label, doer *us } if err = newIssueLabel(ctx, issue, label, doer); err != nil { - return fmt.Errorf("newIssueLabel: %v", err) + return fmt.Errorf("newIssueLabel: %w", err) } } diff --git a/models/issues/pull.go b/models/issues/pull.go index 18b67eb3058..f03cabc3c82 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -228,7 +228,7 @@ func (pr *PullRequest) loadAttributes(ctx context.Context) (err error) { pr.MergerID = -1 pr.Merger = user_model.NewGhostUser() } else if err != nil { - return fmt.Errorf("getUserByID [%d]: %v", pr.MergerID, err) + return fmt.Errorf("getUserByID [%d]: %w", pr.MergerID, err) } } @@ -255,7 +255,7 @@ func (pr *PullRequest) LoadHeadRepoCtx(ctx context.Context) (err error) { pr.HeadRepo, err = repo_model.GetRepositoryByIDCtx(ctx, pr.HeadRepoID) if err != nil && !repo_model.IsErrRepoNotExist(err) { // Head repo maybe deleted, but it should still work - return fmt.Errorf("getRepositoryByID(head): %v", err) + return fmt.Errorf("getRepositoryByID(head): %w", err) } pr.isHeadRepoLoaded = true } @@ -290,7 +290,7 @@ func (pr *PullRequest) LoadBaseRepoCtx(ctx context.Context) (err error) { pr.BaseRepo, err = repo_model.GetRepositoryByIDCtx(ctx, pr.BaseRepoID) if err != nil { - return fmt.Errorf("repo_model.GetRepositoryByID(base): %v", err) + return fmt.Errorf("repo_model.GetRepositoryByID(base): %w", err) } return nil } @@ -482,7 +482,7 @@ func (pr *PullRequest) SetMerged(ctx context.Context) (bool, error) { } if _, err := changeIssueStatus(ctx, pr.Issue, pr.Merger, true, true); err != nil { - return false, fmt.Errorf("Issue.changeStatus: %v", err) + return false, fmt.Errorf("Issue.changeStatus: %w", err) } // reset the conflicted files as there cannot be any if we're merged @@ -490,7 +490,7 @@ func (pr *PullRequest) SetMerged(ctx context.Context) (bool, error) { // We need to save all of the data used to compute this merge as it may have already been changed by TestPatch. FIXME: need to set some state to prevent TestPatch from running whilst we are merging. if _, err := sess.Where("id = ?", pr.ID).Cols("has_merged, status, merge_base, merged_commit_id, merger_id, merged_unix, conflicted_files").Update(pr); err != nil { - return false, fmt.Errorf("Failed to update pr[%d]: %v", pr.ID, err) + return false, fmt.Errorf("Failed to update pr[%d]: %w", pr.ID, err) } return true, nil @@ -507,7 +507,7 @@ func NewPullRequest(outerCtx context.Context, repo *repo_model.Repository, issue idx, err := db.GetNextResourceIndex(ctx, "issue_index", repo.ID) if err != nil { - return fmt.Errorf("generate pull request index failed: %v", err) + return fmt.Errorf("generate pull request index failed: %w", err) } issue.Index = idx @@ -522,18 +522,18 @@ func NewPullRequest(outerCtx context.Context, repo *repo_model.Repository, issue if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) || IsErrNewIssueInsert(err) { return err } - return fmt.Errorf("newIssue: %v", err) + return fmt.Errorf("newIssue: %w", err) } pr.Index = issue.Index pr.BaseRepo = repo pr.IssueID = issue.ID if err = db.Insert(ctx, pr); err != nil { - return fmt.Errorf("insert pull repo: %v", err) + return fmt.Errorf("insert pull repo: %w", err) } if err = committer.Commit(); err != nil { - return fmt.Errorf("Commit: %v", err) + return fmt.Errorf("Commit: %w", err) } return nil diff --git a/models/issues/pull_list.go b/models/issues/pull_list.go index 8eeffa2c0d1..c69f18492b4 100644 --- a/models/issues/pull_list.go +++ b/models/issues/pull_list.go @@ -168,7 +168,7 @@ func (prs PullRequestList) loadAttributes(ctx context.Context) error { Where("id > 0"). In("id", issueIDs). Find(&issues); err != nil { - return fmt.Errorf("find issues: %v", err) + return fmt.Errorf("find issues: %w", err) } set := make(map[int64]*Issue) @@ -205,7 +205,7 @@ func (prs PullRequestList) InvalidateCodeComments(ctx context.Context, doer *use Where("type = ? and invalidated = ?", CommentTypeCode, false). In("issue_id", issueIDs). Find(&codeComments); err != nil { - return fmt.Errorf("find code comments: %v", err) + return fmt.Errorf("find code comments: %w", err) } for _, comment := range codeComments { if err := comment.CheckInvalidation(repo, doer, branch); err != nil { diff --git a/models/issues/reaction.go b/models/issues/reaction.go index 02cffad3ba4..c7503c23a24 100644 --- a/models/issues/reaction.go +++ b/models/issues/reaction.go @@ -355,7 +355,7 @@ func (list ReactionList) LoadUsers(ctx context.Context, repo *repo_model.Reposit In("id", userIDs). Find(&userMaps) if err != nil { - return nil, fmt.Errorf("find user: %v", err) + return nil, fmt.Errorf("find user: %w", err) } for _, reaction := range list { diff --git a/models/issues/review.go b/models/issues/review.go index 26fcea9eef8..3d2fceda2d9 100644 --- a/models/issues/review.go +++ b/models/issues/review.go @@ -790,10 +790,10 @@ func AddTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_ official, err := IsOfficialReviewerTeam(ctx, issue, reviewer) if err != nil { - return nil, fmt.Errorf("isOfficialReviewerTeam(): %v", err) + return nil, fmt.Errorf("isOfficialReviewerTeam(): %w", err) } else if !official { if official, err = IsOfficialReviewer(ctx, issue, doer); err != nil { - return nil, fmt.Errorf("isOfficialReviewer(): %v", err) + return nil, fmt.Errorf("isOfficialReviewer(): %w", err) } } @@ -823,7 +823,7 @@ func AddTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_ ReviewID: review.ID, }) if err != nil { - return nil, fmt.Errorf("CreateCommentCtx(): %v", err) + return nil, fmt.Errorf("CreateCommentCtx(): %w", err) } return comment, committer.Commit() @@ -852,7 +852,7 @@ func RemoveTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *us official, err := IsOfficialReviewerTeam(ctx, issue, reviewer) if err != nil { - return nil, fmt.Errorf("isOfficialReviewerTeam(): %v", err) + return nil, fmt.Errorf("isOfficialReviewerTeam(): %w", err) } if official { @@ -882,7 +882,7 @@ func RemoveTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *us AssigneeTeamID: reviewer.ID, // Use AssigneeTeamID as reviewer team ID }) if err != nil { - return nil, fmt.Errorf("CreateCommentCtx(): %v", err) + return nil, fmt.Errorf("CreateCommentCtx(): %w", err) } return comment, committer.Commit() diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index a6201c10907..f1f943a2c29 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -428,13 +428,13 @@ var migrations = []Migration{ // GetCurrentDBVersion returns the current db version func GetCurrentDBVersion(x *xorm.Engine) (int64, error) { if err := x.Sync(new(Version)); err != nil { - return -1, fmt.Errorf("sync: %v", err) + return -1, fmt.Errorf("sync: %w", err) } currentVersion := &Version{ID: 1} has, err := x.Get(currentVersion) if err != nil { - return -1, fmt.Errorf("get: %v", err) + return -1, fmt.Errorf("get: %w", err) } if !has { return -1, nil @@ -476,13 +476,13 @@ func Migrate(x *xorm.Engine) error { // Set a new clean the default mapper to GonicMapper as that is the default for Gitea. x.SetMapper(names.GonicMapper{}) if err := x.Sync(new(Version)); err != nil { - return fmt.Errorf("sync: %v", err) + return fmt.Errorf("sync: %w", err) } currentVersion := &Version{ID: 1} has, err := x.Get(currentVersion) if err != nil { - return fmt.Errorf("get: %v", err) + return fmt.Errorf("get: %w", err) } else if !has { // If the version record does not exist we think // it is a fresh installation and we can skip all migrations. @@ -490,7 +490,7 @@ func Migrate(x *xorm.Engine) error { currentVersion.Version = int64(minDBVersion + len(migrations)) if _, err = x.InsertOne(currentVersion); err != nil { - return fmt.Errorf("insert: %v", err) + return fmt.Errorf("insert: %w", err) } } @@ -519,7 +519,7 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t // Reset the mapper between each migration - migrations are not supposed to depend on each other x.SetMapper(names.GonicMapper{}) if err = m.Migrate(x); err != nil { - return fmt.Errorf("migration[%d]: %s failed: %v", v+int64(i), m.Description(), err) + return fmt.Errorf("migration[%d]: %s failed: %w", v+int64(i), m.Description(), err) } currentVersion.Version = v + int64(i) + 1 if _, err = x.ID(1).Update(currentVersion); err != nil { @@ -918,7 +918,7 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin cols += "DROP COLUMN `" + col + "` CASCADE" } if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, cols)); err != nil { - return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err) + return fmt.Errorf("Drop table `%s` columns %v: %w", tableName, columnNames, err) } case setting.Database.UseMySQL: // Drop indexes on columns first @@ -946,7 +946,7 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin cols += "DROP COLUMN `" + col + "`" } if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, cols)); err != nil { - return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err) + return fmt.Errorf("Drop table `%s` columns %v: %w", tableName, columnNames, err) } case setting.Database.UseMSSQL: cols := "" @@ -960,27 +960,27 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin tableName, strings.ReplaceAll(cols, "`", "'")) constraints := make([]string, 0) if err := sess.SQL(sql).Find(&constraints); err != nil { - return fmt.Errorf("Find constraints: %v", err) + return fmt.Errorf("Find constraints: %w", err) } for _, constraint := range constraints { if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` DROP CONSTRAINT `%s`", tableName, constraint)); err != nil { - return fmt.Errorf("Drop table `%s` default constraint `%s`: %v", tableName, constraint, err) + return fmt.Errorf("Drop table `%s` default constraint `%s`: %w", tableName, constraint, err) } } sql = fmt.Sprintf("SELECT DISTINCT Name FROM sys.indexes INNER JOIN sys.index_columns ON indexes.index_id = index_columns.index_id AND indexes.object_id = index_columns.object_id WHERE indexes.object_id = OBJECT_ID('%[1]s') AND index_columns.column_id IN (SELECT column_id FROM sys.columns WHERE LOWER(name) IN (%[2]s) AND object_id = OBJECT_ID('%[1]s'))", tableName, strings.ReplaceAll(cols, "`", "'")) constraints = make([]string, 0) if err := sess.SQL(sql).Find(&constraints); err != nil { - return fmt.Errorf("Find constraints: %v", err) + return fmt.Errorf("Find constraints: %w", err) } for _, constraint := range constraints { if _, err := sess.Exec(fmt.Sprintf("DROP INDEX `%[2]s` ON `%[1]s`", tableName, constraint)); err != nil { - return fmt.Errorf("Drop index `%[2]s` on `%[1]s`: %v", tableName, constraint, err) + return fmt.Errorf("Drop index `%s` on `%s`: %w", constraint, tableName, err) } } if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` DROP COLUMN %s", tableName, cols)); err != nil { - return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err) + return fmt.Errorf("Drop table `%s` columns %v: %w", tableName, columnNames, err) } default: log.Fatal("Unrecognized DB") diff --git a/models/migrations/v113.go b/models/migrations/v113.go index 199c02ac98c..4af246863d0 100644 --- a/models/migrations/v113.go +++ b/models/migrations/v113.go @@ -17,7 +17,7 @@ func featureChangeTargetBranch(x *xorm.Engine) error { } if err := x.Sync2(new(Comment)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v115.go b/models/migrations/v115.go index b242ccf2389..3e61cb6e0ea 100644 --- a/models/migrations/v115.go +++ b/models/migrations/v115.go @@ -45,11 +45,11 @@ func renameExistingUserAvatarName(x *xorm.Engine) error { migrated := 0 for { if err := sess.Begin(); err != nil { - return fmt.Errorf("session.Begin: %v", err) + return fmt.Errorf("session.Begin: %w", err) } users := make([]*User, 0, 50) if err := sess.Table("user").Asc("id").Limit(50, start).Find(&users); err != nil { - return fmt.Errorf("select users from id [%d]: %v", start, err) + return fmt.Errorf("select users from id [%d]: %w", start, err) } if len(users) == 0 { _ = sess.Rollback() @@ -76,7 +76,7 @@ func renameExistingUserAvatarName(x *xorm.Engine) error { newAvatar, err := copyOldAvatarToNewLocation(user.ID, oldAvatar) if err != nil { _ = sess.Rollback() - return fmt.Errorf("[user: %s] %v", user.LowerName, err) + return fmt.Errorf("[user: %s] %w", user.LowerName, err) } else if newAvatar == oldAvatar { continue } @@ -84,7 +84,7 @@ func renameExistingUserAvatarName(x *xorm.Engine) error { user.Avatar = newAvatar if _, err := sess.ID(user.ID).Cols("avatar").Update(user); err != nil { _ = sess.Rollback() - return fmt.Errorf("[user: %s] user table update: %v", user.LowerName, err) + return fmt.Errorf("[user: %s] user table update: %w", user.LowerName, err) } deleteList.Add(filepath.Join(setting.Avatar.Path, oldAvatar)) @@ -104,7 +104,7 @@ func renameExistingUserAvatarName(x *xorm.Engine) error { } if err := sess.Commit(); err != nil { _ = sess.Rollback() - return fmt.Errorf("commit session: %v", err) + return fmt.Errorf("commit session: %w", err) } } @@ -138,13 +138,13 @@ func renameExistingUserAvatarName(x *xorm.Engine) error { func copyOldAvatarToNewLocation(userID int64, oldAvatar string) (string, error) { fr, err := os.Open(filepath.Join(setting.Avatar.Path, oldAvatar)) if err != nil { - return "", fmt.Errorf("os.Open: %v", err) + return "", fmt.Errorf("os.Open: %w", err) } defer fr.Close() data, err := io.ReadAll(fr) if err != nil { - return "", fmt.Errorf("io.ReadAll: %v", err) + return "", fmt.Errorf("io.ReadAll: %w", err) } newAvatar := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", userID, md5.Sum(data))))) @@ -153,7 +153,7 @@ func copyOldAvatarToNewLocation(userID int64, oldAvatar string) (string, error) } if err := os.WriteFile(filepath.Join(setting.Avatar.Path, newAvatar), data, 0o666); err != nil { - return "", fmt.Errorf("os.WriteFile: %v", err) + return "", fmt.Errorf("os.WriteFile: %w", err) } return newAvatar, nil diff --git a/models/migrations/v125.go b/models/migrations/v125.go index ac567f66b94..64483e13977 100644 --- a/models/migrations/v125.go +++ b/models/migrations/v125.go @@ -17,7 +17,7 @@ func addReviewMigrateInfo(x *xorm.Engine) error { } if err := x.Sync2(new(Review)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v127.go b/models/migrations/v127.go index d8f0de4a6e1..7be1e326d45 100644 --- a/models/migrations/v127.go +++ b/models/migrations/v127.go @@ -36,10 +36,10 @@ func addLanguageStats(x *xorm.Engine) error { } if err := x.Sync2(new(LanguageStat)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } if err := x.Sync2(new(RepoIndexerStatus)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v128.go b/models/migrations/v128.go index aba0ed68976..7e84ff5b717 100644 --- a/models/migrations/v128.go +++ b/models/migrations/v128.go @@ -59,7 +59,7 @@ func fixMergeBase(x *xorm.Engine) error { for { prs := make([]PullRequest, 0, 50) if err := x.Limit(limit, start).Asc("id").Find(&prs); err != nil { - return fmt.Errorf("Find: %v", err) + return fmt.Errorf("Find: %w", err) } if len(prs) == 0 { break @@ -70,7 +70,7 @@ func fixMergeBase(x *xorm.Engine) error { baseRepo := &Repository{ID: pr.BaseRepoID} has, err := x.Table("repository").Get(baseRepo) if err != nil { - return fmt.Errorf("Unable to get base repo %d %v", pr.BaseRepoID, err) + return fmt.Errorf("Unable to get base repo %d %w", pr.BaseRepoID, err) } if !has { log.Error("Missing base repo with id %d for PR ID %d", pr.BaseRepoID, pr.ID) diff --git a/models/migrations/v131.go b/models/migrations/v131.go index a38c7be634f..48fd3e29c94 100644 --- a/models/migrations/v131.go +++ b/models/migrations/v131.go @@ -16,7 +16,7 @@ func addSystemWebhookColumn(x *xorm.Engine) error { } if err := x.Sync2(new(Webhook)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v132.go b/models/migrations/v132.go index 3f7b1c97096..e67a67e907e 100644 --- a/models/migrations/v132.go +++ b/models/migrations/v132.go @@ -16,7 +16,7 @@ func addBranchProtectionProtectedFilesColumn(x *xorm.Engine) error { } if err := x.Sync2(new(ProtectedBranch)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v134.go b/models/migrations/v134.go index 06d0f8276ac..75c6768720b 100644 --- a/models/migrations/v134.go +++ b/models/migrations/v134.go @@ -58,7 +58,7 @@ func refixMergeBase(x *xorm.Engine) error { for { prs := make([]PullRequest, 0, 50) if err := x.Limit(limit, start).Asc("id").Where("has_merged = ?", true).Find(&prs); err != nil { - return fmt.Errorf("Find: %v", err) + return fmt.Errorf("Find: %w", err) } if len(prs) == 0 { break @@ -69,7 +69,7 @@ func refixMergeBase(x *xorm.Engine) error { baseRepo := &Repository{ID: pr.BaseRepoID} has, err := x.Table("repository").Get(baseRepo) if err != nil { - return fmt.Errorf("Unable to get base repo %d %v", pr.BaseRepoID, err) + return fmt.Errorf("Unable to get base repo %d %w", pr.BaseRepoID, err) } if !has { log.Error("Missing base repo with id %d for PR ID %d", pr.BaseRepoID, pr.ID) diff --git a/models/migrations/v135.go b/models/migrations/v135.go index 8d859d42c05..eaa852d44fc 100644 --- a/models/migrations/v135.go +++ b/models/migrations/v135.go @@ -16,7 +16,7 @@ func addOrgIDLabelColumn(x *xorm.Engine) error { } if err := x.Sync2(new(Label)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v136.go b/models/migrations/v136.go index 94372e41425..b2192f38530 100644 --- a/models/migrations/v136.go +++ b/models/migrations/v136.go @@ -44,7 +44,7 @@ func addCommitDivergenceToPulls(x *xorm.Engine) error { } if err := x.Sync2(new(PullRequest)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } last := 0 @@ -80,7 +80,7 @@ func addCommitDivergenceToPulls(x *xorm.Engine) error { baseRepo := &Repository{ID: pr.BaseRepoID} has, err := x.Table("repository").Get(baseRepo) if err != nil { - return fmt.Errorf("Unable to get base repo %d %v", pr.BaseRepoID, err) + return fmt.Errorf("Unable to get base repo %d %w", pr.BaseRepoID, err) } if !has { log.Error("Missing base repo with id %d for PR ID %d", pr.BaseRepoID, pr.ID) @@ -101,7 +101,7 @@ func addCommitDivergenceToPulls(x *xorm.Engine) error { pr.CommitsBehind = divergence.Behind if _, err = sess.ID(pr.ID).Cols("commits_ahead", "commits_behind").Update(pr); err != nil { - return fmt.Errorf("Update Cols: %v", err) + return fmt.Errorf("Update Cols: %w", err) } migrated++ } diff --git a/models/migrations/v138.go b/models/migrations/v138.go index 2db9b821add..03235200abc 100644 --- a/models/migrations/v138.go +++ b/models/migrations/v138.go @@ -16,7 +16,7 @@ func addResolveDoerIDCommentColumn(x *xorm.Engine) error { } if err := x.Sync2(new(Comment)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v140.go b/models/migrations/v140.go index 871d14b84ee..b54740f1a94 100644 --- a/models/migrations/v140.go +++ b/models/migrations/v140.go @@ -34,7 +34,7 @@ func fixLanguageStatsToSaveSize(x *xorm.Engine) error { } if err := x.Sync2(new(LanguageStat)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } x.Delete(&RepoIndexerStatus{IndexerType: RepoIndexerTypeStats}) diff --git a/models/migrations/v141.go b/models/migrations/v141.go index ab05698b8cb..21247cc78f9 100644 --- a/models/migrations/v141.go +++ b/models/migrations/v141.go @@ -16,7 +16,7 @@ func addKeepActivityPrivateUserColumn(x *xorm.Engine) error { } if err := x.Sync2(new(User)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v145.go b/models/migrations/v145.go index ee79c20e97a..afc60497e31 100644 --- a/models/migrations/v145.go +++ b/models/migrations/v145.go @@ -53,16 +53,16 @@ func increaseLanguageField(x *xorm.Engine) error { if err := sess.SQL(`SELECT i.name AS Name FROM sys.indexes i INNER JOIN sys.index_columns ic ON i.index_id = ic.index_id AND i.object_id = ic.object_id - INNER JOIN sys.tables AS t + INNER JOIN sys.tables AS t ON t.object_id = i.object_id INNER JOIN sys.columns c ON t.object_id = c.object_id AND ic.column_id = c.column_id WHERE t.name = 'language_stat' AND c.name = 'language'`).Find(&constraints); err != nil { - return fmt.Errorf("Find constraints: %v", err) + return fmt.Errorf("Find constraints: %w", err) } for _, constraint := range constraints { if _, err := sess.Exec(fmt.Sprintf("DROP INDEX [%s] ON `language_stat`", constraint)); err != nil { - return fmt.Errorf("Drop table `language_stat` constraint `%s`: %v", constraint, err) + return fmt.Errorf("Drop table `language_stat` constraint `%s`: %w", constraint, err) } } if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE language_stat ALTER COLUMN language %s", sqlType)); err != nil { diff --git a/models/migrations/v149.go b/models/migrations/v149.go index 60c0fae8bcd..4d2cf5b9767 100644 --- a/models/migrations/v149.go +++ b/models/migrations/v149.go @@ -19,7 +19,7 @@ func addCreatedAndUpdatedToMilestones(x *xorm.Engine) error { } if err := x.Sync2(new(Milestone)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v155.go b/models/migrations/v155.go index 58d78b6cfbd..f95b4dfa3f5 100644 --- a/models/migrations/v155.go +++ b/models/migrations/v155.go @@ -16,7 +16,7 @@ func addChangedProtectedFilesPullRequestColumn(x *xorm.Engine) error { } if err := x.Sync2(new(PullRequest)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v156.go b/models/migrations/v156.go index 26f97fe984d..2c146892d2c 100644 --- a/models/migrations/v156.go +++ b/models/migrations/v156.go @@ -123,7 +123,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error { continue } log.Error("Error whilst getting commit for Tag: %s in [%d]%s/%s. Error: %v", release.TagName, repo.ID, repo.OwnerName, repo.Name, err) - return fmt.Errorf("GetTagCommit: %v", err) + return fmt.Errorf("GetTagCommit: %w", err) } if commit.Author.Email == "" { @@ -135,7 +135,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error { continue } log.Error("Error whilst getting commit for Tag: %s in [%d]%s/%s. Error: %v", release.TagName, repo.ID, repo.OwnerName, repo.Name, err) - return fmt.Errorf("GetCommit: %v", err) + return fmt.Errorf("GetCommit: %w", err) } } diff --git a/models/migrations/v164.go b/models/migrations/v164.go index 01ba796563d..02343fac249 100644 --- a/models/migrations/v164.go +++ b/models/migrations/v164.go @@ -32,7 +32,7 @@ func (grant *OAuth2Grant) TableName() string { func addScopeAndNonceColumnsToOAuth2Grant(x *xorm.Engine) error { if err := x.Sync2(new(OAuth2Grant)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v167.go b/models/migrations/v167.go index fd91f226abb..26d7cfd4f87 100644 --- a/models/migrations/v167.go +++ b/models/migrations/v167.go @@ -18,7 +18,7 @@ func addUserRedirect(x *xorm.Engine) (err error) { } if err := x.Sync2(new(UserRedirect)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v170.go b/models/migrations/v170.go index 853a23d290d..2d654fb2b17 100644 --- a/models/migrations/v170.go +++ b/models/migrations/v170.go @@ -16,7 +16,7 @@ func addDismissedReviewColumn(x *xorm.Engine) error { } if err := x.Sync2(new(Review)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v171.go b/models/migrations/v171.go index 2547ff0f77b..8b27493ceac 100644 --- a/models/migrations/v171.go +++ b/models/migrations/v171.go @@ -16,7 +16,7 @@ func addSortingColToProjectBoard(x *xorm.Engine) error { } if err := x.Sync2(new(ProjectBoard)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v173.go b/models/migrations/v173.go index dd4589066d9..c1f167e6f6a 100644 --- a/models/migrations/v173.go +++ b/models/migrations/v173.go @@ -16,7 +16,7 @@ func addTimeIDCommentColumn(x *xorm.Engine) error { } if err := x.Sync2(new(Comment)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v174.go b/models/migrations/v174.go index 5915d3626bc..b6c555525ef 100644 --- a/models/migrations/v174.go +++ b/models/migrations/v174.go @@ -28,7 +28,7 @@ func addRepoTransfer(x *xorm.Engine) error { } if err := sess.Sync2(new(RepoTransfer)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return sess.Commit() diff --git a/models/migrations/v177.go b/models/migrations/v177.go index c65fd3de008..f28826f1709 100644 --- a/models/migrations/v177.go +++ b/models/migrations/v177.go @@ -25,7 +25,7 @@ func deleteOrphanedIssueLabels(x *xorm.Engine) error { } if err := sess.Sync2(new(IssueLabel)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } if _, err := sess.Exec(`DELETE FROM issue_label WHERE issue_label.id IN ( diff --git a/models/migrations/v183.go b/models/migrations/v183.go index cc752bf827c..0dc3af28a76 100644 --- a/models/migrations/v183.go +++ b/models/migrations/v183.go @@ -32,7 +32,7 @@ func createPushMirrorTable(x *xorm.Engine) error { } if err := sess.Sync2(new(PushMirror)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return sess.Commit() diff --git a/models/migrations/v184.go b/models/migrations/v184.go index 97bc72d5d94..593a8100a8a 100644 --- a/models/migrations/v184.go +++ b/models/migrations/v184.go @@ -43,7 +43,7 @@ func renameTaskErrorsToMessage(x *xorm.Engine) error { } if err := sess.Sync2(new(Task)); err != nil { - return fmt.Errorf("error on Sync2: %v", err) + return fmt.Errorf("error on Sync2: %w", err) } if messageExist { diff --git a/models/migrations/v190.go b/models/migrations/v190.go index 8d1fba83734..00046ff2a18 100644 --- a/models/migrations/v190.go +++ b/models/migrations/v190.go @@ -18,7 +18,7 @@ func addAgitFlowPullRequest(x *xorm.Engine) error { } if err := x.Sync2(new(PullRequest)); err != nil { - return fmt.Errorf("sync2: %v", err) + return fmt.Errorf("sync2: %w", err) } return nil } diff --git a/models/migrations/v194.go b/models/migrations/v194.go index 7ea160e2b26..6bd2f19ef53 100644 --- a/models/migrations/v194.go +++ b/models/migrations/v194.go @@ -16,7 +16,7 @@ func addBranchProtectionUnprotectedFilesColumn(x *xorm.Engine) error { } if err := x.Sync2(new(ProtectedBranch)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v195.go b/models/migrations/v195.go index 06694eb57df..8594dddf1fc 100644 --- a/models/migrations/v195.go +++ b/models/migrations/v195.go @@ -20,7 +20,7 @@ func addTableCommitStatusIndex(x *xorm.Engine) error { } if err := x.Sync2(new(CommitStatusIndex)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } sess := x.NewSession() diff --git a/models/migrations/v196.go b/models/migrations/v196.go index c0332c7bb4e..0423d0268b7 100644 --- a/models/migrations/v196.go +++ b/models/migrations/v196.go @@ -16,7 +16,7 @@ func addColorColToProjectBoard(x *xorm.Engine) error { } if err := x.Sync2(new(ProjectBoard)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v198.go b/models/migrations/v198.go index e3c31460a9f..4b1515109e1 100644 --- a/models/migrations/v198.go +++ b/models/migrations/v198.go @@ -27,7 +27,7 @@ func addTableIssueContentHistory(x *xorm.Engine) error { sess := x.NewSession() defer sess.Close() if err := sess.Sync2(new(IssueContentHistory)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return sess.Commit() } diff --git a/models/migrations/v200.go b/models/migrations/v200.go index 56ac06cb136..f0f107bf77d 100644 --- a/models/migrations/v200.go +++ b/models/migrations/v200.go @@ -17,7 +17,7 @@ func addTableAppState(x *xorm.Engine) error { Content string `xorm:"LONGTEXT"` } if err := x.Sync2(new(AppState)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v202.go b/models/migrations/v202.go index 664728969ae..1bfc28d6370 100644 --- a/models/migrations/v202.go +++ b/models/migrations/v202.go @@ -18,7 +18,7 @@ func createUserSettingsTable(x *xorm.Engine) error { SettingValue string `xorm:"text"` } if err := x.Sync2(new(UserSetting)); err != nil { - return fmt.Errorf("sync2: %v", err) + return fmt.Errorf("sync2: %w", err) } return nil } diff --git a/models/migrations/v206.go b/models/migrations/v206.go index c6a5dc811c5..525a4757221 100644 --- a/models/migrations/v206.go +++ b/models/migrations/v206.go @@ -20,7 +20,7 @@ func addAuthorizeColForTeamUnit(x *xorm.Engine) error { } if err := x.Sync2(new(TeamUnit)); err != nil { - return fmt.Errorf("sync2: %v", err) + return fmt.Errorf("sync2: %w", err) } // migrate old permission diff --git a/models/migrations/v210.go b/models/migrations/v210.go index f32fae77bac..891c96fb303 100644 --- a/models/migrations/v210.go +++ b/models/migrations/v210.go @@ -144,7 +144,7 @@ func remigrateU2FCredentials(x *xorm.Engine) error { if !has { has, err := sess.Where("`lower_name`=?", remigrated.LowerName).And("`user_id`=?", remigrated.UserID).Exist(new(webauthnCredential)) if err != nil { - return fmt.Errorf("unable to check webauthn_credential[lower_name: %s, user_id:%v]. Error: %w", remigrated.LowerName, remigrated.UserID, err) + return fmt.Errorf("unable to check webauthn_credential[lower_name: %s, user_id: %d]. Error: %w", remigrated.LowerName, remigrated.UserID, err) } if !has { _, err = sess.Insert(remigrated) diff --git a/models/migrations/v211.go b/models/migrations/v211.go index 26ccfd20376..ec7cb46d472 100644 --- a/models/migrations/v211.go +++ b/models/migrations/v211.go @@ -20,7 +20,7 @@ func createForeignReferenceTable(x *xorm.Engine) error { } if err := x.Sync2(new(ForeignReference)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v223.go b/models/migrations/v223.go index d7ee4812b82..9f4c6acfe33 100644 --- a/models/migrations/v223.go +++ b/models/migrations/v223.go @@ -54,7 +54,7 @@ func renameCredentialIDBytes(x *xorm.Engine) error { } if err := sess.Sync2(new(webauthnCredential)); err != nil { - return fmt.Errorf("error on Sync2: %v", err) + return fmt.Errorf("error on Sync2: %w", err) } if credentialIDExist { diff --git a/models/migrations/v227.go b/models/migrations/v227.go index 8a3a9c877e7..36c0a5eef13 100644 --- a/models/migrations/v227.go +++ b/models/migrations/v227.go @@ -45,7 +45,7 @@ func insertSettingsIfNotExist(x *xorm.Engine, sysSettings []*SystemSetting) erro func createSystemSettingsTable(x *xorm.Engine) error { if err := x.Sync2(new(SystemSetting)); err != nil { - return fmt.Errorf("sync2: %v", err) + return fmt.Errorf("sync2: %w", err) } // migrate xx to database diff --git a/models/migrations/v70.go b/models/migrations/v70.go index 7d34c89d112..b2563544b2d 100644 --- a/models/migrations/v70.go +++ b/models/migrations/v70.go @@ -38,7 +38,7 @@ func addIssueDependencies(x *xorm.Engine) (err error) { ) if err = x.Sync(new(IssueDependency)); err != nil { - return fmt.Errorf("Error creating issue_dependency_table column definition: %v", err) + return fmt.Errorf("Error creating issue_dependency_table column definition: %w", err) } // Update Comment definition @@ -76,7 +76,7 @@ func addIssueDependencies(x *xorm.Engine) (err error) { } if err = x.Sync(new(Comment)); err != nil { - return fmt.Errorf("Error updating issue_comment table column definition: %v", err) + return fmt.Errorf("Error updating issue_comment table column definition: %w", err) } // RepoUnit describes all units of a repository @@ -93,7 +93,7 @@ func addIssueDependencies(x *xorm.Engine) (err error) { units := make([]*RepoUnit, 0, 100) err = x.Where("`type` = ?", v16UnitTypeIssues).Find(&units) if err != nil { - return fmt.Errorf("Query repo units: %v", err) + return fmt.Errorf("Query repo units: %w", err) } for _, unit := range units { if unit.Config == nil { diff --git a/models/migrations/v71.go b/models/migrations/v71.go index 163ec3ee5f9..70314386d71 100644 --- a/models/migrations/v71.go +++ b/models/migrations/v71.go @@ -30,7 +30,7 @@ func addScratchHash(x *xorm.Engine) error { } if err := x.Sync2(new(TwoFactor)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } sess := x.NewSession() @@ -61,7 +61,7 @@ func addScratchHash(x *xorm.Engine) error { tfa.ScratchHash = hashToken(tfa.ScratchToken, salt) if _, err := sess.ID(tfa.ID).Cols("scratch_salt, scratch_hash").Update(tfa); err != nil { - return fmt.Errorf("couldn't add in scratch_hash and scratch_salt: %v", err) + return fmt.Errorf("couldn't add in scratch_hash and scratch_salt: %w", err) } } diff --git a/models/migrations/v72.go b/models/migrations/v72.go index 612f58aab5e..2be4233863f 100644 --- a/models/migrations/v72.go +++ b/models/migrations/v72.go @@ -25,7 +25,7 @@ func addReview(x *xorm.Engine) error { } if err := x.Sync2(new(Review)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return nil } diff --git a/models/migrations/v76.go b/models/migrations/v76.go index a82ae40ba76..2686422723f 100644 --- a/models/migrations/v76.go +++ b/models/migrations/v76.go @@ -43,7 +43,7 @@ func addPullRequestRebaseWithMerge(x *xorm.Engine) error { // Updating existing issue units units := make([]*RepoUnit, 0, 100) if err := sess.Where("`type` = ?", v16UnitTypePRs).Find(&units); err != nil { - return fmt.Errorf("Query repo units: %v", err) + return fmt.Errorf("Query repo units: %w", err) } for _, unit := range units { if unit.Config == nil { diff --git a/models/migrations/v81.go b/models/migrations/v81.go index 4e9e7658ee4..5141f975764 100644 --- a/models/migrations/v81.go +++ b/models/migrations/v81.go @@ -24,7 +24,7 @@ func changeU2FCounterType(x *xorm.Engine) error { } if err != nil { - return fmt.Errorf("Error changing u2f_registration counter column type: %v", err) + return fmt.Errorf("Error changing u2f_registration counter column type: %w", err) } return nil diff --git a/models/migrations/v85.go b/models/migrations/v85.go index 9611d6e72ac..317660eb6f0 100644 --- a/models/migrations/v85.go +++ b/models/migrations/v85.go @@ -41,7 +41,7 @@ func hashAppToken(x *xorm.Engine) error { } if err := sess.Sync2(new(AccessToken)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } if err := sess.Commit(); err != nil { @@ -79,7 +79,7 @@ func hashAppToken(x *xorm.Engine) error { token.Sha1 = "" // ensure to blank out column in case drop column doesn't work if _, err := sess.ID(token.ID).Cols("token_hash, token_salt, token_last_eight, sha1").Update(token); err != nil { - return fmt.Errorf("couldn't add in sha1, token_hash, token_salt and token_last_eight: %v", err) + return fmt.Errorf("couldn't add in sha1, token_hash, token_salt and token_last_eight: %w", err) } } @@ -113,7 +113,7 @@ func resyncHashAppTokenWithUniqueHash(x *xorm.Engine) error { return err } if err := sess.Sync2(new(AccessToken)); err != nil { - return fmt.Errorf("Sync2: %v", err) + return fmt.Errorf("Sync2: %w", err) } return sess.Commit() } diff --git a/models/org.go b/models/org.go index 53be80c3dfa..150c41f55da 100644 --- a/models/org.go +++ b/models/org.go @@ -25,14 +25,14 @@ func removeOrgUser(ctx context.Context, orgID, userID int64) error { And("org_id=?", orgID). Get(ou) if err != nil { - return fmt.Errorf("get org-user: %v", err) + return fmt.Errorf("get org-user: %w", err) } else if !has { return nil } org, err := organization.GetOrgByID(ctx, orgID) if err != nil { - return fmt.Errorf("GetUserByID [%d]: %v", orgID, err) + return fmt.Errorf("GetUserByID [%d]: %w", orgID, err) } // Check if the user to delete is the last member in owner team. @@ -62,11 +62,11 @@ func removeOrgUser(ctx context.Context, orgID, userID int64) error { // Delete all repository accesses and unwatch them. env, err := organization.AccessibleReposEnv(ctx, org, userID) if err != nil { - return fmt.Errorf("AccessibleReposEnv: %v", err) + return fmt.Errorf("AccessibleReposEnv: %w", err) } repoIDs, err := env.RepoIDs(1, org.NumRepos) if err != nil { - return fmt.Errorf("GetUserRepositories [%d]: %v", userID, err) + return fmt.Errorf("GetUserRepositories [%d]: %w", userID, err) } for _, repoID := range repoIDs { if err = repo_model.WatchRepo(ctx, userID, repoID, false); err != nil { diff --git a/models/org_team.go b/models/org_team.go index 6066e7f5c9b..290b1c8b6ad 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -31,23 +31,23 @@ func AddRepository(ctx context.Context, t *organization.Team, repo *repo_model.R } if err = organization.IncrTeamRepoNum(ctx, t.ID); err != nil { - return fmt.Errorf("update team: %v", err) + return fmt.Errorf("update team: %w", err) } t.NumRepos++ if err = access_model.RecalculateTeamAccesses(ctx, repo, 0); err != nil { - return fmt.Errorf("recalculateAccesses: %v", err) + return fmt.Errorf("recalculateAccesses: %w", err) } // Make all team members watch this repo if enabled in global settings if setting.Service.AutoWatchNewRepos { if err = t.GetMembersCtx(ctx); err != nil { - return fmt.Errorf("getMembers: %v", err) + return fmt.Errorf("getMembers: %w", err) } for _, u := range t.Members { if err = repo_model.WatchRepo(ctx, u.ID, repo.ID, true); err != nil { - return fmt.Errorf("watchRepo: %v", err) + return fmt.Errorf("watchRepo: %w", err) } } } @@ -60,13 +60,13 @@ func AddRepository(ctx context.Context, t *organization.Team, repo *repo_model.R func addAllRepositories(ctx context.Context, t *organization.Team) error { orgRepos, err := organization.GetOrgRepositories(ctx, t.OrgID) if err != nil { - return fmt.Errorf("get org repos: %v", err) + return fmt.Errorf("get org repos: %w", err) } for _, repo := range orgRepos { if !organization.HasTeamRepo(ctx, t.OrgID, t.ID, repo.ID) { if err := AddRepository(ctx, t, repo); err != nil { - return fmt.Errorf("AddRepository: %v", err) + return fmt.Errorf("AddRepository: %w", err) } } } @@ -180,7 +180,7 @@ func removeRepository(ctx context.Context, t *organization.Team, repo *repo_mode teamUsers, err := organization.GetTeamUsersByTeamID(ctx, t.ID) if err != nil { - return fmt.Errorf("getTeamUsersByTeamID: %v", err) + return fmt.Errorf("getTeamUsersByTeamID: %w", err) } for _, teamUser := range teamUsers { has, err := access_model.HasAccess(ctx, teamUser.UID, repo) @@ -287,7 +287,7 @@ func NewTeam(t *organization.Team) (err error) { if t.IncludesAllRepositories { err = addAllRepositories(ctx, t) if err != nil { - return fmt.Errorf("addAllRepositories: %v", err) + return fmt.Errorf("addAllRepositories: %w", err) } } @@ -329,7 +329,7 @@ func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err if _, err = sess.ID(t.ID).Cols("name", "lower_name", "description", "can_create_org_repo", "authorize", "includes_all_repositories").Update(t); err != nil { - return fmt.Errorf("update: %v", err) + return fmt.Errorf("update: %w", err) } // update units for team @@ -351,12 +351,12 @@ func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err // Update access for team members if needed. if authChanged { if err = t.GetRepositoriesCtx(ctx); err != nil { - return fmt.Errorf("getRepositories: %v", err) + return fmt.Errorf("getRepositories: %w", err) } for _, repo := range t.Repos { if err = access_model.RecalculateTeamAccesses(ctx, repo, 0); err != nil { - return fmt.Errorf("recalculateTeamAccesses: %v", err) + return fmt.Errorf("recalculateTeamAccesses: %w", err) } } } @@ -365,7 +365,7 @@ func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err if includeAllChanged && t.IncludesAllRepositories { err = addAllRepositories(ctx, t) if err != nil { - return fmt.Errorf("addAllRepositories: %v", err) + return fmt.Errorf("addAllRepositories: %w", err) } } @@ -397,7 +397,7 @@ func DeleteTeam(t *organization.Team) error { builder.Select("id").From("repository").Where(builder.Eq{"owner_id": t.OrgID})). Find(&protections) if err != nil { - return fmt.Errorf("findProtectedBranches: %v", err) + return fmt.Errorf("findProtectedBranches: %w", err) } for _, p := range protections { var matched1, matched2, matched3 bool @@ -419,7 +419,7 @@ func DeleteTeam(t *organization.Team) error { "merge_whitelist_team_i_ds", "approvals_whitelist_team_i_ds", ).Update(p); err != nil { - return fmt.Errorf("updateProtectedBranches: %v", err) + return fmt.Errorf("updateProtectedBranches: %w", err) } } } @@ -496,14 +496,14 @@ func AddTeamMember(team *organization.Team, userID int64) error { And("mode < ?", team.AccessMode). SetExpr("mode", team.AccessMode). Update(new(access_model.Access)); err != nil { - return fmt.Errorf("update user accesses: %v", err) + return fmt.Errorf("update user accesses: %w", err) } // for not exist access var repoIDs []int64 accessSubQuery := builder.Select("repo_id").From("access").Where(builder.Eq{"user_id": userID}) if err := sess.SQL(subQuery.And(builder.NotIn("repo_id", accessSubQuery))).Find(&repoIDs); err != nil { - return fmt.Errorf("select id accesses: %v", err) + return fmt.Errorf("select id accesses: %w", err) } accesses := make([]*access_model.Access, 0, 100) @@ -511,7 +511,7 @@ func AddTeamMember(team *organization.Team, userID int64) error { accesses = append(accesses, &access_model.Access{RepoID: repoID, UserID: userID, Mode: team.AccessMode}) if (i%100 == 0 || i == len(repoIDs)-1) && len(accesses) > 0 { if err = db.Insert(ctx, accesses); err != nil { - return fmt.Errorf("insert new user accesses: %v", err) + return fmt.Errorf("insert new user accesses: %w", err) } accesses = accesses[:0] } diff --git a/models/organization/org.go b/models/organization/org.go index 58b58e67324..993ca3f10d8 100644 --- a/models/organization/org.go +++ b/models/organization/org.go @@ -288,10 +288,10 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) { } if err = db.Insert(ctx, org); err != nil { - return fmt.Errorf("insert organization: %v", err) + return fmt.Errorf("insert organization: %w", err) } if err = user_model.GenerateRandomAvatar(ctx, org.AsUser()); err != nil { - return fmt.Errorf("generate random avatar: %v", err) + return fmt.Errorf("generate random avatar: %w", err) } // Add initial creator to organization and owner team. @@ -299,7 +299,7 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) { UID: owner.ID, OrgID: org.ID, }); err != nil { - return fmt.Errorf("insert org-user relation: %v", err) + return fmt.Errorf("insert org-user relation: %w", err) } // Create default owner team. @@ -313,7 +313,7 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) { CanCreateOrgRepo: true, } if err = db.Insert(ctx, t); err != nil { - return fmt.Errorf("insert owner team: %v", err) + return fmt.Errorf("insert owner team: %w", err) } // insert units for team @@ -335,7 +335,7 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) { OrgID: org.ID, TeamID: t.ID, }); err != nil { - return fmt.Errorf("insert team-user relation: %v", err) + return fmt.Errorf("insert team-user relation: %w", err) } return committer.Commit() @@ -372,11 +372,11 @@ func DeleteOrganization(ctx context.Context, org *Organization) error { &TeamUnit{OrgID: org.ID}, &TeamInvite{OrgID: org.ID}, ); err != nil { - return fmt.Errorf("DeleteBeans: %v", err) + return fmt.Errorf("DeleteBeans: %w", err) } if _, err := db.GetEngine(ctx).ID(org.ID).Delete(new(user_model.User)); err != nil { - return fmt.Errorf("Delete: %v", err) + return fmt.Errorf("Delete: %w", err) } return nil @@ -760,7 +760,7 @@ func (env *accessibleReposEnv) CountRepos() (int64, error) { Distinct("`repository`.id"). Count(&repo_model.Repository{}) if err != nil { - return 0, fmt.Errorf("count user repositories in organization: %v", err) + return 0, fmt.Errorf("count user repositories in organization: %w", err) } return repoCount, nil } @@ -785,7 +785,7 @@ func (env *accessibleReposEnv) RepoIDs(page, pageSize int) ([]int64, error) { func (env *accessibleReposEnv) Repos(page, pageSize int) ([]*repo_model.Repository, error) { repoIDs, err := env.RepoIDs(page, pageSize) if err != nil { - return nil, fmt.Errorf("GetUserRepositoryIDs: %v", err) + return nil, fmt.Errorf("GetUserRepositoryIDs: %w", err) } repos := make([]*repo_model.Repository, 0, len(repoIDs)) @@ -814,7 +814,7 @@ func (env *accessibleReposEnv) MirrorRepoIDs() ([]int64, error) { func (env *accessibleReposEnv) MirrorRepos() ([]*repo_model.Repository, error) { repoIDs, err := env.MirrorRepoIDs() if err != nil { - return nil, fmt.Errorf("MirrorRepoIDs: %v", err) + return nil, fmt.Errorf("MirrorRepoIDs: %w", err) } repos := make([]*repo_model.Repository, 0, len(repoIDs)) diff --git a/models/organization/org_user.go b/models/organization/org_user.go index a7bc8f7d4c1..7a5d17a75a7 100644 --- a/models/organization/org_user.go +++ b/models/organization/org_user.go @@ -118,7 +118,7 @@ func loadOrganizationOwners(ctx context.Context, users user_model.UserList, orgI And("team_id=?", ownerTeam.ID). Find(&ownerMaps) if err != nil { - return nil, fmt.Errorf("find team users: %v", err) + return nil, fmt.Errorf("find team users: %w", err) } return ownerMaps, nil } diff --git a/models/perm/access/access.go b/models/perm/access/access.go index 0e5e4ff2bb5..7344e114a64 100644 --- a/models/perm/access/access.go +++ b/models/perm/access/access.go @@ -87,7 +87,7 @@ func updateUserAccess(accessMap map[int64]*userAccess, user *user_model.User, mo func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap map[int64]*userAccess) (err error) { minMode := perm.AccessModeRead if err := repo.GetOwner(ctx); err != nil { - return fmt.Errorf("GetOwner: %v", err) + return fmt.Errorf("GetOwner: %w", err) } // If the repo isn't private and isn't owned by a organization, @@ -111,14 +111,14 @@ func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap // Delete old accesses and insert new ones for repository. if _, err = db.DeleteByBean(ctx, &Access{RepoID: repo.ID}); err != nil { - return fmt.Errorf("delete old accesses: %v", err) + return fmt.Errorf("delete old accesses: %w", err) } if len(newAccesses) == 0 { return nil } if err = db.Insert(ctx, newAccesses); err != nil { - return fmt.Errorf("insert new accesses: %v", err) + return fmt.Errorf("insert new accesses: %w", err) } return nil } @@ -127,7 +127,7 @@ func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap func refreshCollaboratorAccesses(ctx context.Context, repoID int64, accessMap map[int64]*userAccess) error { collaborators, err := repo_model.GetCollaborators(ctx, repoID, db.ListOptions{}) if err != nil { - return fmt.Errorf("getCollaborations: %v", err) + return fmt.Errorf("getCollaborations: %w", err) } for _, c := range collaborators { if c.User.IsGhost() { @@ -151,7 +151,7 @@ func RecalculateTeamAccesses(ctx context.Context, repo *repo_model.Repository, i } if err = refreshCollaboratorAccesses(ctx, repo.ID, accessMap); err != nil { - return fmt.Errorf("refreshCollaboratorAccesses: %v", err) + return fmt.Errorf("refreshCollaboratorAccesses: %w", err) } teams, err := organization.FindOrgTeams(ctx, repo.Owner.ID) @@ -173,7 +173,7 @@ func RecalculateTeamAccesses(ctx context.Context, repo *repo_model.Repository, i } if err = t.GetMembersCtx(ctx); err != nil { - return fmt.Errorf("getMembers '%d': %v", t.ID, err) + return fmt.Errorf("getMembers '%d': %w", t.ID, err) } for _, m := range t.Members { updateUserAccess(accessMap, m, t.AccessMode) @@ -224,10 +224,10 @@ func RecalculateUserAccess(ctx context.Context, repo *repo_model.Repository, uid // Delete old user accesses and insert new one for repository. if _, err = e.Delete(&Access{RepoID: repo.ID, UserID: uid}); err != nil { - return fmt.Errorf("delete old user accesses: %v", err) + return fmt.Errorf("delete old user accesses: %w", err) } else if accessMode >= minMode { if err = db.Insert(ctx, &Access{RepoID: repo.ID, UserID: uid, Mode: accessMode}); err != nil { - return fmt.Errorf("insert new user accesses: %v", err) + return fmt.Errorf("insert new user accesses: %w", err) } } return nil @@ -241,7 +241,7 @@ func RecalculateAccesses(ctx context.Context, repo *repo_model.Repository) error accessMap := make(map[int64]*userAccess, 20) if err := refreshCollaboratorAccesses(ctx, repo.ID, accessMap); err != nil { - return fmt.Errorf("refreshCollaboratorAccesses: %v", err) + return fmt.Errorf("refreshCollaboratorAccesses: %w", err) } return refreshAccesses(ctx, repo, accessMap) } diff --git a/models/project/project.go b/models/project/project.go index af2c8ac2afe..ccdf5342d4f 100644 --- a/models/project/project.go +++ b/models/project/project.go @@ -147,7 +147,7 @@ func GetProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, er count, err := e.Where(cond).Count(new(Project)) if err != nil { - return nil, 0, fmt.Errorf("Count: %v", err) + return nil, 0, fmt.Errorf("Count: %w", err) } e = e.Where(cond) diff --git a/models/repo.go b/models/repo.go index 08fbb0abeac..b544853a5d4 100644 --- a/models/repo.go +++ b/models/repo.go @@ -74,12 +74,12 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error { // Delete Deploy Keys deployKeys, err := asymkey_model.ListDeployKeys(ctx, &asymkey_model.ListDeployKeysOptions{RepoID: repoID}) if err != nil { - return fmt.Errorf("listDeployKeys: %v", err) + return fmt.Errorf("listDeployKeys: %w", err) } needRewriteKeysFile := len(deployKeys) > 0 for _, dKey := range deployKeys { if err := DeleteDeployKey(ctx, doer, dKey.ID); err != nil { - return fmt.Errorf("deleteDeployKeys: %v", err) + return fmt.Errorf("deleteDeployKeys: %w", err) } } @@ -152,7 +152,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error { &repo_model.Watch{RepoID: repoID}, &webhook.Webhook{RepoID: repoID}, ); err != nil { - return fmt.Errorf("deleteBeans: %v", err) + return fmt.Errorf("deleteBeans: %w", err) } // Delete Labels and related objects @@ -178,7 +178,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error { if repo.IsFork { if _, err := db.Exec(ctx, "UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil { - return fmt.Errorf("decrease fork count: %v", err) + return fmt.Errorf("decrease fork count: %w", err) } } @@ -193,7 +193,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error { } if err := project_model.DeleteProjectByRepoIDCtx(ctx, repoID); err != nil { - return fmt.Errorf("unable to delete projects for repo[%d]: %v", repoID, err) + return fmt.Errorf("unable to delete projects for repo[%d]: %w", repoID, err) } // Remove LFS objects @@ -310,7 +310,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error { if len(repo.Avatar) > 0 { if err := storage.RepoAvatars.Delete(repo.CustomAvatarRelativePath()); err != nil { - return fmt.Errorf("Failed to remove %s: %v", repo.Avatar, err) + return fmt.Errorf("Failed to remove %s: %w", repo.Avatar, err) } } @@ -619,18 +619,18 @@ func DeleteDeployKey(ctx context.Context, doer *user_model.User, id int64) error if asymkey_model.IsErrDeployKeyNotExist(err) { return nil } - return fmt.Errorf("GetDeployKeyByID: %v", err) + return fmt.Errorf("GetDeployKeyByID: %w", err) } // Check if user has access to delete this key. if !doer.IsAdmin { repo, err := repo_model.GetRepositoryByIDCtx(ctx, key.RepoID) if err != nil { - return fmt.Errorf("GetRepositoryByID: %v", err) + return fmt.Errorf("GetRepositoryByID: %w", err) } has, err := access_model.IsUserRepoAdmin(ctx, repo, doer) if err != nil { - return fmt.Errorf("GetUserRepoPermission: %v", err) + return fmt.Errorf("GetUserRepoPermission: %w", err) } else if !has { return asymkey_model.ErrKeyAccessDenied{ UserID: doer.ID, @@ -643,7 +643,7 @@ func DeleteDeployKey(ctx context.Context, doer *user_model.User, id int64) error if _, err := db.DeleteByBean(ctx, &asymkey_model.DeployKey{ ID: key.ID, }); err != nil { - return fmt.Errorf("delete deploy key [%d]: %v", key.ID, err) + return fmt.Errorf("delete deploy key [%d]: %w", key.ID, err) } // Check if this is the last reference to same key content. diff --git a/models/repo/attachment.go b/models/repo/attachment.go index 5d4e11ae72a..180d7730ba7 100644 --- a/models/repo/attachment.go +++ b/models/repo/attachment.go @@ -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 diff --git a/models/repo/avatar.go b/models/repo/avatar.go index cdf85bf1ac1..1bc37598fee 100644 --- a/models/repo/avatar.go +++ b/models/repo/avatar.go @@ -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) diff --git a/models/repo/collaboration.go b/models/repo/collaboration.go index be05eba74c1..0aaa749210b 100644 --- a/models/repo/collaboration.go +++ b/models/repo/collaboration.go @@ -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 diff --git a/models/repo/release.go b/models/repo/release.go index 2e7bc6d3229..14428f15f73 100644 --- a/models/repo/release.go +++ b/models/repo/release.go @@ -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 diff --git a/models/repo/repo.go b/models/repo/repo.go index ce698baaefb..848138c8247 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -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 } diff --git a/models/repo/repo_indexer.go b/models/repo/repo_indexer.go index cba70a14e55..67ba3382dc6 100644 --- a/models/repo/repo_indexer.go +++ b/models/repo/repo_indexer.go @@ -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 } diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go index 0cd0a3c8e35..191970d2756 100644 --- a/models/repo/repo_list.go +++ b/models/repo/repo_list.go @@ -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()) diff --git a/models/repo/update.go b/models/repo/update.go index 64a225d2f59..cc21deb0bc4 100644 --- a/models/repo/update.go +++ b/models/repo/update.go @@ -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) } } diff --git a/models/repo/upload.go b/models/repo/upload.go index e3ce7e458fa..e115c8e50ec 100644 --- a/models/repo/upload.go +++ b/models/repo/upload.go @@ -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 diff --git a/models/repo_collaboration.go b/models/repo_collaboration.go index 05df2f29aa2..58d6b0f488c 100644 --- a/models/repo_collaboration.go +++ b/models/repo_collaboration.go @@ -66,7 +66,7 @@ func reconsiderRepoIssuesAssignee(ctx context.Context, repo *repo_model.Reposito if _, err := db.GetEngine(ctx).Where(builder.Eq{"assignee_id": uid}). In("issue_id", builder.Select("id").From("issue").Where(builder.Eq{"repo_id": repo.ID})). Delete(&issues_model.IssueAssignees{}); err != nil { - return fmt.Errorf("Could not delete assignee[%d] %v", uid, err) + return fmt.Errorf("Could not delete assignee[%d] %w", uid, err) } return nil } diff --git a/models/repo_transfer.go b/models/repo_transfer.go index 636d49b989b..d6a3985fe5f 100644 --- a/models/repo_transfer.go +++ b/models/repo_transfer.go @@ -179,7 +179,7 @@ func CreatePendingRepositoryTransfer(doer, newOwner *user_model.User, repoID int // Check if new owner has repository with same name. if has, err := repo_model.IsRepositoryExist(ctx, newOwner, repo.Name); err != nil { - return fmt.Errorf("IsRepositoryExist: %v", err) + return fmt.Errorf("IsRepositoryExist: %w", err) } else if has { return repo_model.ErrRepoAlreadyExist{ Uname: newOwner.LowerName, @@ -253,13 +253,13 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo newOwner, err := user_model.GetUserByName(ctx, newOwnerName) if err != nil { - return fmt.Errorf("get new owner '%s': %v", newOwnerName, err) + return fmt.Errorf("get new owner '%s': %w", newOwnerName, err) } newOwnerName = newOwner.Name // ensure capitalisation matches // Check if new owner has repository with same name. if has, err := repo_model.IsRepositoryExist(ctx, newOwner, repo.Name); err != nil { - return fmt.Errorf("IsRepositoryExist: %v", err) + return fmt.Errorf("IsRepositoryExist: %w", err) } else if has { return repo_model.ErrRepoAlreadyExist{ Uname: newOwnerName, @@ -278,13 +278,13 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo // Update repository. if _, err := sess.ID(repo.ID).Update(repo); err != nil { - return fmt.Errorf("update owner: %v", err) + return fmt.Errorf("update owner: %w", err) } // Remove redundant collaborators. collaborators, err := repo_model.GetCollaborators(ctx, repo.ID, db.ListOptions{}) if err != nil { - return fmt.Errorf("getCollaborators: %v", err) + return fmt.Errorf("getCollaborators: %w", err) } // Dummy object. @@ -293,7 +293,7 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo if c.IsGhost() { collaboration.ID = c.Collaboration.ID if _, err := sess.Delete(collaboration); err != nil { - return fmt.Errorf("remove collaborator '%d': %v", c.ID, err) + return fmt.Errorf("remove collaborator '%d': %w", c.ID, err) } collaboration.ID = 0 } @@ -301,14 +301,14 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo if c.ID != newOwner.ID { isMember, err := organization.IsOrganizationMember(ctx, newOwner.ID, c.ID) if err != nil { - return fmt.Errorf("IsOrgMember: %v", err) + return fmt.Errorf("IsOrgMember: %w", err) } else if !isMember { continue } } collaboration.UserID = c.ID if _, err := sess.Delete(collaboration); err != nil { - return fmt.Errorf("remove collaborator '%d': %v", c.ID, err) + return fmt.Errorf("remove collaborator '%d': %w", c.ID, err) } collaboration.UserID = 0 } @@ -316,42 +316,42 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo // Remove old team-repository relations. if oldOwner.IsOrganization() { if err := organization.RemoveOrgRepo(ctx, oldOwner.ID, repo.ID); err != nil { - return fmt.Errorf("removeOrgRepo: %v", err) + return fmt.Errorf("removeOrgRepo: %w", err) } } if newOwner.IsOrganization() { teams, err := organization.FindOrgTeams(ctx, newOwner.ID) if err != nil { - return fmt.Errorf("LoadTeams: %v", err) + return fmt.Errorf("LoadTeams: %w", err) } for _, t := range teams { if t.IncludesAllRepositories { if err := AddRepository(ctx, t, repo); err != nil { - return fmt.Errorf("AddRepository: %v", err) + return fmt.Errorf("AddRepository: %w", err) } } } } else if err := access_model.RecalculateAccesses(ctx, repo); err != nil { // Organization called this in addRepository method. - return fmt.Errorf("recalculateAccesses: %v", err) + return fmt.Errorf("recalculateAccesses: %w", err) } // Update repository count. if _, err := sess.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", newOwner.ID); err != nil { - return fmt.Errorf("increase new owner repository count: %v", err) + return fmt.Errorf("increase new owner repository count: %w", err) } else if _, err := sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", oldOwner.ID); err != nil { - return fmt.Errorf("decrease old owner repository count: %v", err) + return fmt.Errorf("decrease old owner repository count: %w", err) } if err := repo_model.WatchRepo(ctx, doer.ID, repo.ID, true); err != nil { - return fmt.Errorf("watchRepo: %v", err) + return fmt.Errorf("watchRepo: %w", err) } // Remove watch for organization. if oldOwner.IsOrganization() { if err := repo_model.WatchRepo(ctx, oldOwner.ID, repo.ID, false); err != nil { - return fmt.Errorf("watchRepo [false]: %v", err) + return fmt.Errorf("watchRepo [false]: %w", err) } } @@ -366,7 +366,7 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo WHERE issue.repo_id = ? AND ((label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != ?)) ) AS il_too )`, repo.ID, newOwner.ID); err != nil { - return fmt.Errorf("Unable to remove old org labels: %v", err) + return fmt.Errorf("Unable to remove old org labels: %w", err) } if _, err := sess.Exec(`DELETE FROM comment WHERE comment.id IN ( @@ -378,7 +378,7 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo WHERE com.type = ? AND issue.repo_id = ? AND ((label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != ?)) ) AS il_too)`, issues_model.CommentTypeLabel, repo.ID, newOwner.ID); err != nil { - return fmt.Errorf("Unable to remove old org label comments: %v", err) + return fmt.Errorf("Unable to remove old org label comments: %w", err) } } @@ -386,11 +386,11 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo dir := user_model.UserPath(newOwner.Name) if err := os.MkdirAll(dir, os.ModePerm); err != nil { - return fmt.Errorf("Failed to create dir %s: %v", dir, err) + return fmt.Errorf("Failed to create dir %s: %w", dir, err) } if err := util.Rename(repo_model.RepoPath(oldOwner.Name, repo.Name), repo_model.RepoPath(newOwner.Name, repo.Name)); err != nil { - return fmt.Errorf("rename repository directory: %v", err) + return fmt.Errorf("rename repository directory: %w", err) } repoRenamed = true @@ -402,13 +402,13 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo return err } else if isExist { if err := util.Rename(wikiPath, repo_model.WikiPath(newOwner.Name, repo.Name)); err != nil { - return fmt.Errorf("rename repository wiki: %v", err) + return fmt.Errorf("rename repository wiki: %w", err) } wikiRenamed = true } if err := deleteRepositoryTransfer(ctx, repo.ID); err != nil { - return fmt.Errorf("deleteRepositoryTransfer: %v", err) + return fmt.Errorf("deleteRepositoryTransfer: %w", err) } repo.Status = repo_model.RepositoryReady if err := repo_model.UpdateRepositoryCols(ctx, repo, "status"); err != nil { @@ -417,11 +417,11 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo // If there was previously a redirect at this location, remove it. if err := repo_model.DeleteRedirect(ctx, newOwner.ID, repo.Name); err != nil { - return fmt.Errorf("delete repo redirect: %v", err) + return fmt.Errorf("delete repo redirect: %w", err) } if err := repo_model.NewRedirect(ctx, oldOwner.ID, repo.ID, repo.Name, repo.Name); err != nil { - return fmt.Errorf("repo_model.NewRedirect: %v", err) + return fmt.Errorf("repo_model.NewRedirect: %w", err) } return committer.Commit() diff --git a/models/system/setting.go b/models/system/setting.go index ff8b48e6180..9711d38f3b2 100644 --- a/models/system/setting.go +++ b/models/system/setting.go @@ -243,7 +243,7 @@ func Init() error { var err error GravatarSourceURL, err = url.Parse(setting.GravatarSource) if err != nil { - return fmt.Errorf("Failed to parse Gravatar URL(%s): %v", setting.GravatarSource, err) + return fmt.Errorf("Failed to parse Gravatar URL(%s): %w", setting.GravatarSource, err) } } diff --git a/models/user.go b/models/user.go index 68be0d85550..85f465127ae 100644 --- a/models/user.go +++ b/models/user.go @@ -35,10 +35,10 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error) watchedRepoIDs := make([]int64, 0, 10) if err = e.Table("watch").Cols("watch.repo_id"). Where("watch.user_id = ?", u.ID).And("watch.mode <>?", repo_model.WatchModeDont).Find(&watchedRepoIDs); err != nil { - return fmt.Errorf("get all watches: %v", err) + return fmt.Errorf("get all watches: %w", err) } if _, err = e.Decr("num_watches").In("id", watchedRepoIDs).NoAutoTime().Update(new(repo_model.Repository)); err != nil { - return fmt.Errorf("decrease repository num_watches: %v", err) + return fmt.Errorf("decrease repository num_watches: %w", err) } // ***** END: Watch ***** @@ -46,9 +46,9 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error) starredRepoIDs := make([]int64, 0, 10) if err = e.Table("star").Cols("star.repo_id"). Where("star.uid = ?", u.ID).Find(&starredRepoIDs); err != nil { - return fmt.Errorf("get all stars: %v", err) + return fmt.Errorf("get all stars: %w", err) } else if _, err = e.Decr("num_stars").In("id", starredRepoIDs).NoAutoTime().Update(new(repo_model.Repository)); err != nil { - return fmt.Errorf("decrease repository num_stars: %v", err) + return fmt.Errorf("decrease repository num_stars: %w", err) } // ***** END: Star ***** @@ -56,17 +56,17 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error) followeeIDs := make([]int64, 0, 10) if err = e.Table("follow").Cols("follow.follow_id"). Where("follow.user_id = ?", u.ID).Find(&followeeIDs); err != nil { - return fmt.Errorf("get all followees: %v", err) + return fmt.Errorf("get all followees: %w", err) } else if _, err = e.Decr("num_followers").In("id", followeeIDs).Update(new(user_model.User)); err != nil { - return fmt.Errorf("decrease user num_followers: %v", err) + return fmt.Errorf("decrease user num_followers: %w", err) } followerIDs := make([]int64, 0, 10) if err = e.Table("follow").Cols("follow.user_id"). Where("follow.follow_id = ?", u.ID).Find(&followerIDs); err != nil { - return fmt.Errorf("get all followers: %v", err) + return fmt.Errorf("get all followers: %w", err) } else if _, err = e.Decr("num_following").In("id", followerIDs).Update(new(user_model.User)); err != nil { - return fmt.Errorf("decrease user num_following: %v", err) + return fmt.Errorf("decrease user num_following: %w", err) } // ***** END: Follow ***** @@ -90,7 +90,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error) &pull_model.AutoMerge{DoerID: u.ID}, &pull_model.ReviewState{UserID: u.ID}, ); err != nil { - return fmt.Errorf("deleteBeans: %v", err) + return fmt.Errorf("deleteBeans: %w", err) } if err := auth_model.DeleteOAuth2RelictsByUserID(ctx, u.ID); err != nil { @@ -135,7 +135,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error) // Also, as we didn't update branch protections when removing entries from `access` table, // it's safer to iterate all protected branches. if err = e.Limit(batchSize, start).Find(&protections); err != nil { - return fmt.Errorf("findProtectedBranches: %v", err) + return fmt.Errorf("findProtectedBranches: %w", err) } if len(protections) == 0 { break @@ -160,7 +160,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error) "merge_whitelist_user_i_ds", "approvals_whitelist_user_i_ds", ).Update(p); err != nil { - return fmt.Errorf("updateProtectedBranches: %v", err) + return fmt.Errorf("updateProtectedBranches: %w", err) } } } @@ -170,39 +170,39 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error) // ***** START: PublicKey ***** if _, err = db.DeleteByBean(ctx, &asymkey_model.PublicKey{OwnerID: u.ID}); err != nil { - return fmt.Errorf("deletePublicKeys: %v", err) + return fmt.Errorf("deletePublicKeys: %w", err) } // ***** END: PublicKey ***** // ***** START: GPGPublicKey ***** keys, err := asymkey_model.ListGPGKeys(ctx, u.ID, db.ListOptions{}) if err != nil { - return fmt.Errorf("ListGPGKeys: %v", err) + return fmt.Errorf("ListGPGKeys: %w", err) } // Delete GPGKeyImport(s). for _, key := range keys { if _, err = db.DeleteByBean(ctx, &asymkey_model.GPGKeyImport{KeyID: key.KeyID}); err != nil { - return fmt.Errorf("deleteGPGKeyImports: %v", err) + return fmt.Errorf("deleteGPGKeyImports: %w", err) } } if _, err = db.DeleteByBean(ctx, &asymkey_model.GPGKey{OwnerID: u.ID}); err != nil { - return fmt.Errorf("deleteGPGKeys: %v", err) + return fmt.Errorf("deleteGPGKeys: %w", err) } // ***** END: GPGPublicKey ***** // Clear assignee. if _, err = db.DeleteByBean(ctx, &issues_model.IssueAssignees{AssigneeID: u.ID}); err != nil { - return fmt.Errorf("clear assignee: %v", err) + return fmt.Errorf("clear assignee: %w", err) } // ***** START: ExternalLoginUser ***** if err = user_model.RemoveAllAccountLinks(ctx, u); err != nil { - return fmt.Errorf("ExternalLoginUser: %v", err) + return fmt.Errorf("ExternalLoginUser: %w", err) } // ***** END: ExternalLoginUser ***** if _, err = e.ID(u.ID).Delete(new(user_model.User)); err != nil { - return fmt.Errorf("delete: %v", err) + return fmt.Errorf("delete: %w", err) } return nil diff --git a/models/user/avatar.go b/models/user/avatar.go index 1c75c7406bd..f73ac56c5e4 100644 --- a/models/user/avatar.go +++ b/models/user/avatar.go @@ -35,7 +35,7 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error { img, err := avatar.RandomImage([]byte(seed)) if err != nil { - return fmt.Errorf("RandomImage: %v", err) + return fmt.Errorf("RandomImage: %w", err) } u.Avatar = avatars.HashEmail(seed) @@ -47,7 +47,7 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error { } return err }); err != nil { - return fmt.Errorf("Failed to create dir %s: %v", u.CustomAvatarRelativePath(), err) + return fmt.Errorf("Failed to create dir %s: %w", u.CustomAvatarRelativePath(), err) } if _, err := db.GetEngine(ctx).ID(u.ID).Cols("avatar").Update(u); err != nil { diff --git a/models/user/email_address.go b/models/user/email_address.go index 964e7ae08cc..d6279b6639a 100644 --- a/models/user/email_address.go +++ b/models/user/email_address.go @@ -264,7 +264,7 @@ func AddEmailAddresses(emails []*EmailAddress) error { } if err := db.Insert(db.DefaultContext, emails); err != nil { - return fmt.Errorf("Insert: %v", err) + return fmt.Errorf("Insert: %w", err) } return nil @@ -485,7 +485,7 @@ func SearchEmails(opts *SearchEmailOptions) ([]*SearchEmailResult, int64, error) count, err := db.GetEngine(db.DefaultContext).Join("INNER", "`user`", "`user`.ID = email_address.uid"). Where(cond).Count(new(EmailAddress)) if err != nil { - return nil, 0, fmt.Errorf("Count: %v", err) + return nil, 0, fmt.Errorf("Count: %w", err) } orderby := opts.SortType.String() @@ -530,7 +530,7 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) { } if activate { if used, err := IsEmailActive(ctx, email, addr.ID); err != nil { - return fmt.Errorf("unable to check isEmailActive() for %s: %v", email, err) + return fmt.Errorf("unable to check isEmailActive() for %s: %w", email, err) } else if used { return ErrEmailAlreadyUsed{Email: email} } @@ -551,10 +551,10 @@ func ActivateUserEmail(userID int64, email string, activate bool) (err error) { if user.IsActive != activate { user.IsActive = activate if user.Rands, err = GetUserSalt(); err != nil { - return fmt.Errorf("unable to generate salt: %v", err) + return fmt.Errorf("unable to generate salt: %w", err) } if err = UpdateUserCols(ctx, &user, "is_active", "rands"); err != nil { - return fmt.Errorf("unable to updateUserCols() for user ID: %d: %v", userID, err) + return fmt.Errorf("unable to updateUserCols() for user ID: %d: %w", userID, err) } } } diff --git a/models/user/list.go b/models/user/list.go index 68e62ca15d3..6c43c961c8d 100644 --- a/models/user/list.go +++ b/models/user/list.go @@ -55,7 +55,7 @@ func (users UserList) loadTwoFactorStatus(ctx context.Context) (map[int64]*auth. userIDs := users.GetUserIDs() tokenMaps := make(map[int64]*auth.TwoFactor, len(userIDs)) if err := db.GetEngine(ctx).In("uid", userIDs).Find(&tokenMaps); err != nil { - return nil, fmt.Errorf("find two factor: %v", err) + return nil, fmt.Errorf("find two factor: %w", err) } return tokenMaps, nil } @@ -66,7 +66,7 @@ func (users UserList) userIDsWithWebAuthn(ctx context.Context) ([]int64, error) } ids := make([]int64, 0, len(users)) if err := db.GetEngine(ctx).Table(new(auth.WebAuthnCredential)).In("user_id", users.GetUserIDs()).Select("user_id").Distinct("user_id").Find(&ids); err != nil { - return nil, fmt.Errorf("find two factor: %v", err) + return nil, fmt.Errorf("find two factor: %w", err) } return ids, nil } diff --git a/models/user/search.go b/models/user/search.go index 0aa9949367a..fa4a021a473 100644 --- a/models/user/search.go +++ b/models/user/search.go @@ -105,7 +105,7 @@ func SearchUsers(opts *SearchUserOptions) (users []*User, _ int64, _ error) { defer sessCount.Close() count, err := sessCount.Count(new(User)) if err != nil { - return nil, 0, fmt.Errorf("Count: %v", err) + return nil, 0, fmt.Errorf("Count: %w", err) } if len(opts.OrderBy) == 0 { diff --git a/models/user/user.go b/models/user/user.go index a3c10c2492d..9a2da6dbc1a 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -827,12 +827,12 @@ func ChangeUserName(u *User, newUserName string) (err error) { } if _, err = db.GetEngine(ctx).Exec("UPDATE `repository` SET owner_name=? WHERE owner_name=?", newUserName, oldUserName); err != nil { - return fmt.Errorf("Change repo owner name: %v", err) + return fmt.Errorf("Change repo owner name: %w", err) } // Do not fail if directory does not exist if err = util.Rename(UserPath(oldUserName), UserPath(newUserName)); err != nil && !os.IsNotExist(err) { - return fmt.Errorf("Rename user directory: %v", err) + return fmt.Errorf("Rename user directory: %w", err) } if err = NewUserRedirect(ctx, u.ID, oldUserName, newUserName); err != nil { diff --git a/models/webhook/webhook.go b/models/webhook/webhook.go index 4551dcff5fb..aebe0d6e72f 100644 --- a/models/webhook/webhook.go +++ b/models/webhook/webhook.go @@ -608,14 +608,14 @@ func DeleteDefaultSystemWebhook(id int64) error { func CopyDefaultWebhooksToRepo(ctx context.Context, repoID int64) error { ws, err := GetDefaultWebhooks(ctx) if err != nil { - return fmt.Errorf("GetDefaultWebhooks: %v", err) + return fmt.Errorf("GetDefaultWebhooks: %w", err) } for _, w := range ws { w.ID = 0 w.RepoID = repoID if err := CreateWebhook(ctx, w); err != nil { - return fmt.Errorf("CreateWebhook: %v", err) + return fmt.Errorf("CreateWebhook: %w", err) } } return nil diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go index 6ca75ed90f0..2de77de0091 100644 --- a/modules/avatar/avatar.go +++ b/modules/avatar/avatar.go @@ -30,7 +30,7 @@ func RandomImageSize(size int, data []byte) (image.Image, error) { // we use white as background, and use dark colors to draw blocks imgMaker, err := identicon.New(size, color.White, identicon.DarkColors...) if err != nil { - return nil, fmt.Errorf("identicon.New: %v", err) + return nil, fmt.Errorf("identicon.New: %w", err) } return imgMaker.Make(data), nil } @@ -46,7 +46,7 @@ func RandomImage(data []byte) (image.Image, error) { func Prepare(data []byte) (*image.Image, error) { imgCfg, _, err := image.DecodeConfig(bytes.NewReader(data)) if err != nil { - return nil, fmt.Errorf("DecodeConfig: %v", err) + return nil, fmt.Errorf("DecodeConfig: %w", err) } if imgCfg.Width > setting.Avatar.MaxWidth { return nil, fmt.Errorf("Image width is too large: %d > %d", imgCfg.Width, setting.Avatar.MaxWidth) @@ -57,7 +57,7 @@ func Prepare(data []byte) (*image.Image, error) { img, _, err := image.Decode(bytes.NewReader(data)) if err != nil { - return nil, fmt.Errorf("Decode: %v", err) + return nil, fmt.Errorf("Decode: %w", err) } if imgCfg.Width != imgCfg.Height { diff --git a/modules/doctor/authorizedkeys.go b/modules/doctor/authorizedkeys.go index d4ceef87c0f..b3e9699a020 100644 --- a/modules/doctor/authorizedkeys.go +++ b/modules/doctor/authorizedkeys.go @@ -31,12 +31,12 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e if err != nil { if !autofix { logger.Critical("Unable to open authorized_keys file. ERROR: %v", err) - return fmt.Errorf("Unable to open authorized_keys file. ERROR: %v", err) + return fmt.Errorf("Unable to open authorized_keys file. ERROR: %w", err) } logger.Warn("Unable to open authorized_keys. (ERROR: %v). Attempting to rewrite...", err) if err = asymkey_model.RewriteAllPublicKeys(); err != nil { logger.Critical("Unable to rewrite authorized_keys file. ERROR: %v", err) - return fmt.Errorf("Unable to rewrite authorized_keys file. ERROR: %v", err) + return fmt.Errorf("Unable to rewrite authorized_keys file. ERROR: %w", err) } } defer f.Close() @@ -57,7 +57,7 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e regenerated := &bytes.Buffer{} if err := asymkey_model.RegeneratePublicKeys(ctx, regenerated); err != nil { logger.Critical("Unable to regenerate authorized_keys file. ERROR: %v", err) - return fmt.Errorf("Unable to regenerate authorized_keys file. ERROR: %v", err) + return fmt.Errorf("Unable to regenerate authorized_keys file. ERROR: %w", err) } scanner = bufio.NewScanner(regenerated) for scanner.Scan() { @@ -80,7 +80,7 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e err = asymkey_model.RewriteAllPublicKeys() if err != nil { logger.Critical("Unable to rewrite authorized_keys file. ERROR: %v", err) - return fmt.Errorf("Unable to rewrite authorized_keys file. ERROR: %v", err) + return fmt.Errorf("Unable to rewrite authorized_keys file. ERROR: %w", err) } } return nil diff --git a/modules/doctor/breaking.go b/modules/doctor/breaking.go index 391c8e76c59..51122d9a61a 100644 --- a/modules/doctor/breaking.go +++ b/modules/doctor/breaking.go @@ -47,7 +47,7 @@ func checkUserEmail(ctx context.Context, logger log.Logger, _ bool) error { } return nil }); err != nil { - return fmt.Errorf("iterateUserAccounts: %v", err) + return fmt.Errorf("iterateUserAccounts: %w", err) } if invalidUserCount == 0 { @@ -70,7 +70,7 @@ func checkUserName(ctx context.Context, logger log.Logger, _ bool) error { } return nil }); err != nil { - return fmt.Errorf("iterateUserAccounts: %v", err) + return fmt.Errorf("iterateUserAccounts: %w", err) } if invalidUserCount == 0 { diff --git a/modules/doctor/mergebase.go b/modules/doctor/mergebase.go index 4a10c72e6e7..b279c453f79 100644 --- a/modules/doctor/mergebase.go +++ b/modules/doctor/mergebase.go @@ -78,7 +78,7 @@ func checkPRMergeBase(ctx context.Context, logger log.Logger, autofix bool) erro if autofix { if err := pr.UpdateCols("merge_base"); err != nil { logger.Critical("Failed to update merge_base. ERROR: %v", err) - return fmt.Errorf("Failed to update merge_base. ERROR: %v", err) + return fmt.Errorf("Failed to update merge_base. ERROR: %w", err) } } else { logger.Info("#%d onto %s in %s/%s: MergeBase should be %s but is %s", pr.Index, pr.BaseBranch, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, oldMergeBase, pr.MergeBase) diff --git a/modules/doctor/misc.go b/modules/doctor/misc.go index 2d2bcb910db..277d66a1777 100644 --- a/modules/doctor/misc.go +++ b/modules/doctor/misc.go @@ -43,7 +43,7 @@ func checkScriptType(ctx context.Context, logger log.Logger, autofix bool) error path, err := exec.LookPath(setting.ScriptType) if err != nil { logger.Critical("ScriptType \"%q\" is not on the current PATH. Error: %v", setting.ScriptType, err) - return fmt.Errorf("ScriptType \"%q\" is not on the current PATH. Error: %v", setting.ScriptType, err) + return fmt.Errorf("ScriptType \"%q\" is not on the current PATH. Error: %w", setting.ScriptType, err) } logger.Info("ScriptType %s is on the current PATH at %s", setting.ScriptType, path) return nil @@ -54,13 +54,13 @@ func checkHooks(ctx context.Context, logger log.Logger, autofix bool) error { results, err := repository.CheckDelegateHooks(repo.RepoPath()) if err != nil { logger.Critical("Unable to check delegate hooks for repo %-v. ERROR: %v", repo, err) - return fmt.Errorf("Unable to check delegate hooks for repo %-v. ERROR: %v", repo, err) + return fmt.Errorf("Unable to check delegate hooks for repo %-v. ERROR: %w", repo, err) } if len(results) > 0 && autofix { logger.Warn("Regenerated hooks for %s", repo.FullName()) if err := repository.CreateDelegateHooks(repo.RepoPath()); err != nil { logger.Critical("Unable to recreate delegate hooks for %-v. ERROR: %v", repo, err) - return fmt.Errorf("Unable to recreate delegate hooks for %-v. ERROR: %v", repo, err) + return fmt.Errorf("Unable to recreate delegate hooks for %-v. ERROR: %w", repo, err) } } for _, result := range results { diff --git a/modules/doctor/paths.go b/modules/doctor/paths.go index 22c095c2279..5a270454574 100644 --- a/modules/doctor/paths.go +++ b/modules/doctor/paths.go @@ -29,7 +29,7 @@ func checkConfigurationFile(logger log.Logger, autofix bool, fileOpts configurat if os.IsNotExist(err) && autofix && fileOpts.IsDirectory { if err := os.MkdirAll(fileOpts.Path, 0o777); err != nil { logger.Error(" Directory does not exist and could not be created. ERROR: %v", err) - return fmt.Errorf("Configuration directory: \"%q\" does not exist and could not be created. ERROR: %v", fileOpts.Path, err) + return fmt.Errorf("Configuration directory: \"%q\" does not exist and could not be created. ERROR: %w", fileOpts.Path, err) } fi, err = os.Stat(fileOpts.Path) } @@ -37,7 +37,7 @@ func checkConfigurationFile(logger log.Logger, autofix bool, fileOpts configurat if err != nil { if fileOpts.Required { logger.Error(" Is REQUIRED but is not accessible. ERROR: %v", err) - return fmt.Errorf("Configuration file \"%q\" is not accessible but is required. Error: %v", fileOpts.Path, err) + return fmt.Errorf("Configuration file \"%q\" is not accessible but is required. Error: %w", fileOpts.Path, err) } logger.Warn(" NOTICE: is not accessible (Error: %v)", err) // this is a non-critical error @@ -46,14 +46,14 @@ func checkConfigurationFile(logger log.Logger, autofix bool, fileOpts configurat if fileOpts.IsDirectory && !fi.IsDir() { logger.Error(" ERROR: not a directory") - return fmt.Errorf("Configuration directory \"%q\" is not a directory. Error: %v", fileOpts.Path, err) + return fmt.Errorf("Configuration directory \"%q\" is not a directory. Error: %w", fileOpts.Path, err) } else if !fileOpts.IsDirectory && !fi.Mode().IsRegular() { logger.Error(" ERROR: not a regular file") - return fmt.Errorf("Configuration file \"%q\" is not a regular file. Error: %v", fileOpts.Path, err) + return fmt.Errorf("Configuration file \"%q\" is not a regular file. Error: %w", fileOpts.Path, err) } else if fileOpts.Writable { if err := isWritableDir(fileOpts.Path); err != nil { logger.Error(" ERROR: is required to be writable but is not writable: %v", err) - return fmt.Errorf("Configuration file \"%q\" is required to be writable but is not. Error: %v", fileOpts.Path, err) + return fmt.Errorf("Configuration file \"%q\" is required to be writable but is not. Error: %w", fileOpts.Path, err) } } return nil diff --git a/modules/git/blame.go b/modules/git/blame.go index 1653ecbf854..832b12213c8 100644 --- a/modules/git/blame.go +++ b/modules/git/blame.go @@ -106,7 +106,7 @@ func (r *BlameReader) Close() error { _ = r.output.Close() if err := r.cmd.Wait(); err != nil { - return fmt.Errorf("Wait: %v", err) + return fmt.Errorf("Wait: %w", err) } return nil @@ -129,13 +129,13 @@ func createBlameReader(ctx context.Context, dir string, command ...string) (*Bla stdout, err := cmd.StdoutPipe() if err != nil { defer finished() - return nil, fmt.Errorf("StdoutPipe: %v", err) + return nil, fmt.Errorf("StdoutPipe: %w", err) } if err = cmd.Start(); err != nil { defer finished() _ = stdout.Close() - return nil, fmt.Errorf("Start: %v", err) + return nil, fmt.Errorf("Start: %w", err) } reader := bufio.NewReader(stdout) diff --git a/modules/git/diff.go b/modules/git/diff.go index 13ff6bd1e6a..1a43d0dd4ab 100644 --- a/modules/git/diff.go +++ b/modules/git/diff.go @@ -41,7 +41,7 @@ func GetReverseRawDiff(ctx context.Context, repoPath, commitID string, writer io Stdout: writer, Stderr: stderr, }); err != nil { - return fmt.Errorf("Run: %v - %s", err, stderr) + return fmt.Errorf("Run: %w - %s", err, stderr) } return nil } @@ -89,7 +89,7 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff Stdout: writer, Stderr: stderr, }); err != nil { - return fmt.Errorf("Run: %v - %s", err, stderr) + return fmt.Errorf("Run: %w - %s", err, stderr) } return nil } diff --git a/modules/git/error.go b/modules/git/error.go index 40c41064141..ebfea8e702c 100644 --- a/modules/git/error.go +++ b/modules/git/error.go @@ -116,7 +116,7 @@ func (err *ErrPushOutOfDate) Error() string { // Unwrap unwraps the underlying error func (err *ErrPushOutOfDate) Unwrap() error { - return fmt.Errorf("%v - %s", err.Err, err.StdErr) + return fmt.Errorf("%w - %s", err.Err, err.StdErr) } // ErrPushRejected represents an error if merging fails due to rejection from a hook @@ -139,7 +139,7 @@ func (err *ErrPushRejected) Error() string { // Unwrap unwraps the underlying error func (err *ErrPushRejected) Unwrap() error { - return fmt.Errorf("%v - %s", err.Err, err.StdErr) + return fmt.Errorf("%w - %s", err.Err, err.StdErr) } // GenerateMessage generates the remote message from the stderr diff --git a/modules/git/parse_gogit.go b/modules/git/parse_gogit.go index 409432c5d6a..4a8dcfdf353 100644 --- a/modules/git/parse_gogit.go +++ b/modules/git/parse_gogit.go @@ -56,7 +56,7 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) { } id, err := NewIDFromString(string(data[pos : pos+40])) if err != nil { - return nil, fmt.Errorf("Invalid ls-tree output: %v", err) + return nil, fmt.Errorf("Invalid ls-tree output: %w", err) } entry.ID = id entry.gogitTreeEntry.Hash = id @@ -80,7 +80,7 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) { if data[pos] == '"' { entry.gogitTreeEntry.Name, err = strconv.Unquote(string(data[pos:end])) if err != nil { - return nil, fmt.Errorf("Invalid ls-tree output: %v", err) + return nil, fmt.Errorf("Invalid ls-tree output: %w", err) } } else { entry.gogitTreeEntry.Name = string(data[pos:end]) diff --git a/modules/git/pipeline/catfile.go b/modules/git/pipeline/catfile.go index 40dd2bca293..c1d4bd16655 100644 --- a/modules/git/pipeline/catfile.go +++ b/modules/git/pipeline/catfile.go @@ -33,7 +33,7 @@ func CatFileBatchCheck(ctx context.Context, shasToCheckReader *io.PipeReader, ca Stdout: catFileCheckWriter, Stderr: stderr, }); err != nil { - _ = catFileCheckWriter.CloseWithError(fmt.Errorf("git cat-file --batch-check [%s]: %v - %s", tmpBasePath, err, errbuf.String())) + _ = catFileCheckWriter.CloseWithError(fmt.Errorf("git cat-file --batch-check [%s]: %w - %s", tmpBasePath, err, errbuf.String())) } } @@ -51,7 +51,7 @@ func CatFileBatchCheckAllObjects(ctx context.Context, catFileCheckWriter *io.Pip Stderr: stderr, }); err != nil { log.Error("git cat-file --batch-check --batch-all-object [%s]: %v - %s", tmpBasePath, err, errbuf.String()) - err = fmt.Errorf("git cat-file --batch-check --batch-all-object [%s]: %v - %s", tmpBasePath, err, errbuf.String()) + err = fmt.Errorf("git cat-file --batch-check --batch-all-object [%s]: %w - %s", tmpBasePath, err, errbuf.String()) _ = catFileCheckWriter.CloseWithError(err) errChan <- err } @@ -71,7 +71,7 @@ func CatFileBatch(ctx context.Context, shasToBatchReader *io.PipeReader, catFile Stdin: shasToBatchReader, Stderr: stderr, }); err != nil { - _ = shasToBatchReader.CloseWithError(fmt.Errorf("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String())) + _ = shasToBatchReader.CloseWithError(fmt.Errorf("git rev-list [%s]: %w - %s", tmpBasePath, err, errbuf.String())) } } diff --git a/modules/git/pipeline/namerev.go b/modules/git/pipeline/namerev.go index 8356e702344..85ba7db23ed 100644 --- a/modules/git/pipeline/namerev.go +++ b/modules/git/pipeline/namerev.go @@ -29,6 +29,6 @@ func NameRevStdin(ctx context.Context, shasToNameReader *io.PipeReader, nameRevS Stdin: shasToNameReader, Stderr: stderr, }); err != nil { - _ = shasToNameReader.CloseWithError(fmt.Errorf("git name-rev [%s]: %v - %s", tmpBasePath, err, errbuf.String())) + _ = shasToNameReader.CloseWithError(fmt.Errorf("git name-rev [%s]: %w - %s", tmpBasePath, err, errbuf.String())) } } diff --git a/modules/git/pipeline/revlist.go b/modules/git/pipeline/revlist.go index 5f62e85e7f7..93142034ec1 100644 --- a/modules/git/pipeline/revlist.go +++ b/modules/git/pipeline/revlist.go @@ -31,7 +31,7 @@ func RevListAllObjects(ctx context.Context, revListWriter *io.PipeWriter, wg *sy Stderr: stderr, }); err != nil { log.Error("git rev-list --objects --all [%s]: %v - %s", basePath, err, errbuf.String()) - err = fmt.Errorf("git rev-list --objects --all [%s]: %v - %s", basePath, err, errbuf.String()) + err = fmt.Errorf("git rev-list --objects --all [%s]: %w - %s", basePath, err, errbuf.String()) _ = revListWriter.CloseWithError(err) errChan <- err } @@ -50,7 +50,7 @@ func RevListObjects(ctx context.Context, revListWriter *io.PipeWriter, wg *sync. Stderr: stderr, }); err != nil { log.Error("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String()) - errChan <- fmt.Errorf("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String()) + errChan <- fmt.Errorf("git rev-list [%s]: %w - %s", tmpBasePath, err, errbuf.String()) } } diff --git a/modules/git/repo.go b/modules/git/repo.go index 575b686e296..8ba3ae4fdaf 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -90,7 +90,7 @@ func (repo *Repository) IsEmpty() (bool, error) { if err.Error() == "exit status 1" && errbuf.String() == "" { return true, nil } - return true, fmt.Errorf("check empty: %v - %s", err, errbuf.String()) + return true, fmt.Errorf("check empty: %w - %s", err, errbuf.String()) } return strings.TrimSpace(output.String()) == "", nil @@ -251,7 +251,7 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error { } if errbuf.Len() > 0 && err != nil { - return fmt.Errorf("%v - %s", err, errbuf.String()) + return fmt.Errorf("%w - %s", err, errbuf.String()) } return err diff --git a/modules/git/repo_attribute.go b/modules/git/repo_attribute.go index 60dc993dc20..d9c50be6f7a 100644 --- a/modules/git/repo_attribute.go +++ b/modules/git/repo_attribute.go @@ -68,7 +68,7 @@ func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[ Stdout: stdOut, Stderr: stdErr, }); err != nil { - return nil, fmt.Errorf("failed to run check-attr: %v\n%s\n%s", err, stdOut.String(), stdErr.String()) + return nil, fmt.Errorf("failed to run check-attr: %w\n%s\n%s", err, stdOut.String(), stdErr.String()) } // FIXME: This is incorrect on versions < 1.8.5 diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go index aad78370ff2..7575b116586 100644 --- a/modules/git/repo_compare.go +++ b/modules/git/repo_compare.go @@ -62,7 +62,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string, // Add a temporary remote tmpRemote = strconv.FormatInt(time.Now().UnixNano(), 10) if err = repo.AddRemote(tmpRemote, basePath, false); err != nil { - return nil, fmt.Errorf("AddRemote: %v", err) + return nil, fmt.Errorf("AddRemote: %w", err) } defer func() { if err := repo.RemoveRemote(tmpRemote); err != nil { @@ -100,7 +100,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string, } compareInfo.Commits, err = repo.parsePrettyFormatLogToList(logs) if err != nil { - return nil, fmt.Errorf("parsePrettyFormatLogToList: %v", err) + return nil, fmt.Errorf("parsePrettyFormatLogToList: %w", err) } } else { compareInfo.Commits = []*Commit{} @@ -166,7 +166,7 @@ func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparis return w.numLines, nil } } - return 0, fmt.Errorf("%v: Stderr: %s", err, stderr) + return 0, fmt.Errorf("%w: Stderr: %s", err, stderr) } return w.numLines, nil } @@ -215,20 +215,20 @@ func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int, numFiles, err = strconv.Atoi(groups[1]) if err != nil { - return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumFiles %v", stdout, err) + return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumFiles %w", stdout, err) } if len(groups[2]) != 0 { totalAdditions, err = strconv.Atoi(groups[2]) if err != nil { - return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumAdditions %v", stdout, err) + return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumAdditions %w", stdout, err) } } if len(groups[3]) != 0 { totalDeletions, err = strconv.Atoi(groups[3]) if err != nil { - return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumDeletions %v", stdout, err) + return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumDeletions %w", stdout, err) } } return numFiles, totalAdditions, totalDeletions, err diff --git a/modules/git/repo_gpg.go b/modules/git/repo_gpg.go index abbb349159d..25188d07e30 100644 --- a/modules/git/repo_gpg.go +++ b/modules/git/repo_gpg.go @@ -18,7 +18,7 @@ func (gpgSettings *GPGSettings) LoadPublicKeyContent() error { "gpg -a --export", "gpg", "-a", "--export", gpgSettings.KeyID) if err != nil { - return fmt.Errorf("Unable to get default signing key: %s, %s, %v", gpgSettings.KeyID, stderr, err) + return fmt.Errorf("Unable to get default signing key: %s, %s, %w", gpgSettings.KeyID, stderr, err) } gpgSettings.PublicKeyContent = content return nil diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go index fd0de7b3a1c..8585d824f91 100644 --- a/modules/git/repo_tag.go +++ b/modules/git/repo_tag.go @@ -166,7 +166,7 @@ func parseTagRef(ref map[string]string) (tag *Tag, err error) { tag.ID, err = NewIDFromString(ref["objectname"]) if err != nil { - return nil, fmt.Errorf("parse objectname '%s': %v", ref["objectname"], err) + return nil, fmt.Errorf("parse objectname '%s': %w", ref["objectname"], err) } if tag.Type == "commit" { @@ -176,7 +176,7 @@ func parseTagRef(ref map[string]string) (tag *Tag, err error) { // annotated tag tag.Object, err = NewIDFromString(ref["object"]) if err != nil { - return nil, fmt.Errorf("parse object '%s': %v", ref["object"], err) + return nil, fmt.Errorf("parse object '%s': %w", ref["object"], err) } } diff --git a/modules/graceful/net_unix.go b/modules/graceful/net_unix.go index c7524a79dbc..0bb589e2313 100644 --- a/modules/graceful/net_unix.go +++ b/modules/graceful/net_unix.go @@ -52,7 +52,7 @@ func getProvidedFDs() (savedErr error) { } n, err := strconv.Atoi(numFDs) if err != nil { - savedErr = fmt.Errorf("%s is not a number: %s. Err: %v", listenFDs, numFDs, err) + savedErr = fmt.Errorf("%s is not a number: %s. Err: %w", listenFDs, numFDs, err) return } @@ -81,7 +81,7 @@ func getProvidedFDs() (savedErr error) { } // If needed we can handle packetconns here. - savedErr = fmt.Errorf("Error getting provided socket fd %d: %v", i, err) + savedErr = fmt.Errorf("Error getting provided socket fd %d: %w", i, err) return } }) @@ -98,7 +98,7 @@ func CloseProvidedListeners() error { if err != nil { log.Error("Error in closing unused provided listener: %v", err) if returnableError != nil { - returnableError = fmt.Errorf("%v & %v", returnableError, err) + returnableError = fmt.Errorf("%v & %w", returnableError, err) } else { returnableError = err } @@ -198,7 +198,7 @@ func GetListenerUnix(network string, address *net.UnixAddr) (*net.UnixListener, // make a fresh listener if err := util.Remove(address.Name); err != nil && !os.IsNotExist(err) { - return nil, fmt.Errorf("Failed to remove unix socket %s: %v", address.Name, err) + return nil, fmt.Errorf("Failed to remove unix socket %s: %w", address.Name, err) } l, err := net.ListenUnix(network, address) @@ -208,7 +208,7 @@ func GetListenerUnix(network string, address *net.UnixAddr) (*net.UnixListener, fileMode := os.FileMode(setting.UnixSocketPermission) if err = os.Chmod(address.Name, fileMode); err != nil { - return nil, fmt.Errorf("Failed to set permission of unix socket to %s: %v", fileMode.String(), err) + return nil, fmt.Errorf("Failed to set permission of unix socket to %s: %w", fileMode.String(), err) } activeListeners = append(activeListeners, l) diff --git a/modules/hostmatcher/http.go b/modules/hostmatcher/http.go index 31430a95958..84cd2974ec8 100644 --- a/modules/hostmatcher/http.go +++ b/modules/hostmatcher/http.go @@ -35,7 +35,7 @@ func NewDialContext(usage string, allowList, blockList *HostMatchList) func(ctx // in Control func, the addr was already resolved to IP:PORT format, there is no cost to do ResolveTCPAddr here tcpAddr, err := net.ResolveTCPAddr(network, ipAddr) if err != nil { - return fmt.Errorf("%s can only call HTTP servers via TCP, deny '%s(%s:%s)', err=%v", usage, host, network, ipAddr, err) + return fmt.Errorf("%s can only call HTTP servers via TCP, deny '%s(%s:%s)', err=%w", usage, host, network, ipAddr, err) } var blockedError error diff --git a/modules/indexer/code/bleve.go b/modules/indexer/code/bleve.go index f1298b01ed7..3ea1c861784 100644 --- a/modules/indexer/code/bleve.go +++ b/modules/indexer/code/bleve.go @@ -199,7 +199,7 @@ func (b *BleveIndexer) addUpdate(ctx context.Context, batchWriter git.WriteClose return err } if size, err = strconv.ParseInt(strings.TrimSpace(stdout), 10, 64); err != nil { - return fmt.Errorf("Misformatted git cat-file output: %v", err) + return fmt.Errorf("Misformatted git cat-file output: %w", err) } } diff --git a/modules/indexer/code/elastic_search.go b/modules/indexer/code/elastic_search.go index 108a2246756..dd3c9c97714 100644 --- a/modules/indexer/code/elastic_search.go +++ b/modules/indexer/code/elastic_search.go @@ -228,7 +228,7 @@ func (b *ElasticSearchIndexer) addUpdate(ctx context.Context, batchWriter git.Wr return nil, err } if size, err = strconv.ParseInt(strings.TrimSpace(stdout), 10, 64); err != nil { - return nil, fmt.Errorf("misformatted git cat-file output: %v", err) + return nil, fmt.Errorf("misformatted git cat-file output: %w", err) } } diff --git a/modules/indexer/issues/bleve.go b/modules/indexer/issues/bleve.go index c298b7de3e1..dff1cf0c60b 100644 --- a/modules/indexer/issues/bleve.go +++ b/modules/indexer/issues/bleve.go @@ -40,7 +40,7 @@ func indexerID(id int64) string { func idOfIndexerID(indexerID string) (int64, error) { id, err := strconv.ParseInt(indexerID, 36, 64) if err != nil { - return 0, fmt.Errorf("Unexpected indexer ID %s: %v", indexerID, err) + return 0, fmt.Errorf("Unexpected indexer ID %s: %w", indexerID, err) } return id, nil } diff --git a/modules/log/conn.go b/modules/log/conn.go index bd1d76d071d..155f2866cae 100644 --- a/modules/log/conn.go +++ b/modules/log/conn.go @@ -108,7 +108,7 @@ func NewConn() LoggerProvider { func (log *ConnLogger) Init(jsonconfig string) error { err := json.Unmarshal([]byte(jsonconfig), log) if err != nil { - return fmt.Errorf("Unable to parse JSON: %v", err) + return fmt.Errorf("Unable to parse JSON: %w", err) } log.NewWriterLogger(&connWriter{ ReconnectOnMsg: log.ReconnectOnMsg, diff --git a/modules/log/console.go b/modules/log/console.go index 8c78add4743..fc7c9b49672 100644 --- a/modules/log/console.go +++ b/modules/log/console.go @@ -54,7 +54,7 @@ func NewConsoleLogger() LoggerProvider { func (log *ConsoleLogger) Init(config string) error { err := json.Unmarshal([]byte(config), log) if err != nil { - return fmt.Errorf("Unable to parse JSON: %v", err) + return fmt.Errorf("Unable to parse JSON: %w", err) } if log.Stderr { log.NewWriterLogger(&nopWriteCloser{ diff --git a/modules/log/event.go b/modules/log/event.go index 41bb241da84..aebd1562125 100644 --- a/modules/log/event.go +++ b/modules/log/event.go @@ -293,9 +293,9 @@ func (m *MultiChannelledLog) ReleaseReopen() error { for _, logger := range m.loggers { if err := logger.ReleaseReopen(); err != nil { if accumulatedErr == nil { - accumulatedErr = fmt.Errorf("Error whilst reopening: %s Error: %v", logger.GetName(), err) + accumulatedErr = fmt.Errorf("Error whilst reopening: %s Error: %w", logger.GetName(), err) } else { - accumulatedErr = fmt.Errorf("Error whilst reopening: %s Error: %v & %v", logger.GetName(), err, accumulatedErr) + accumulatedErr = fmt.Errorf("Error whilst reopening: %s Error: %v & %w", logger.GetName(), err, accumulatedErr) } } } diff --git a/modules/log/file.go b/modules/log/file.go index 8110a9587ee..d0cba7817c3 100644 --- a/modules/log/file.go +++ b/modules/log/file.go @@ -103,7 +103,7 @@ func NewFileLogger() LoggerProvider { // } func (log *FileLogger) Init(config string) error { if err := json.Unmarshal([]byte(config), log); err != nil { - return fmt.Errorf("Unable to parse JSON: %v", err) + return fmt.Errorf("Unable to parse JSON: %w", err) } if len(log.Filename) == 0 { return errors.New("config must have filename") @@ -145,7 +145,7 @@ func (log *FileLogger) initFd() error { fd := log.mw.fd finfo, err := fd.Stat() if err != nil { - return fmt.Errorf("get stat: %v", err) + return fmt.Errorf("get stat: %w", err) } log.maxsizeCursize = int(finfo.Size()) log.dailyOpenDate = time.Now().Day() @@ -178,7 +178,7 @@ func (log *FileLogger) DoRotate() error { // close fd before rename // Rename the file to its newfound home if err = util.Rename(log.Filename, fname); err != nil { - return fmt.Errorf("Rotate: %v", err) + return fmt.Errorf("Rotate: %w", err) } if log.Compress { @@ -187,7 +187,7 @@ func (log *FileLogger) DoRotate() error { // re-start logger if err = log.StartLogger(); err != nil { - return fmt.Errorf("Rotate StartLogger: %v", err) + return fmt.Errorf("Rotate StartLogger: %w", err) } go log.deleteOldLog() @@ -236,7 +236,7 @@ func (log *FileLogger) deleteOldLog() { if !info.IsDir() && info.ModTime().Unix() < (time.Now().Unix()-60*60*24*log.Maxdays) { if strings.HasPrefix(filepath.Base(path), filepath.Base(log.Filename)) { if err := util.Remove(path); err != nil { - returnErr = fmt.Errorf("Failed to remove %s: %v", path, err) + returnErr = fmt.Errorf("Failed to remove %s: %w", path, err) } } } diff --git a/modules/log/log.go b/modules/log/log.go index f805a36231b..4303ecf4c03 100644 --- a/modules/log/log.go +++ b/modules/log/log.go @@ -219,9 +219,9 @@ func ReleaseReopen() error { logger := value.(*MultiChannelledLogger) if err := logger.ReleaseReopen(); err != nil { if accumulatedErr == nil { - accumulatedErr = fmt.Errorf("Error reopening %s: %v", key.(string), err) + accumulatedErr = fmt.Errorf("Error reopening %s: %w", key.(string), err) } else { - accumulatedErr = fmt.Errorf("Error reopening %s: %v & %v", key.(string), err, accumulatedErr) + accumulatedErr = fmt.Errorf("Error reopening %s: %v & %w", key.(string), err, accumulatedErr) } } return true diff --git a/modules/log/smtp.go b/modules/log/smtp.go index 1706517d6a5..61af50b81a9 100644 --- a/modules/log/smtp.go +++ b/modules/log/smtp.go @@ -60,7 +60,7 @@ func NewSMTPLogger() LoggerProvider { func (log *SMTPLogger) Init(jsonconfig string) error { err := json.Unmarshal([]byte(jsonconfig), log) if err != nil { - return fmt.Errorf("Unable to parse JSON: %v", err) + return fmt.Errorf("Unable to parse JSON: %w", err) } log.NewWriterLogger(&smtpWriter{ owner: log, diff --git a/modules/markup/external/external.go b/modules/markup/external/external.go index 23dd45ba0a1..0eeb2d70a5f 100644 --- a/modules/markup/external/external.go +++ b/modules/markup/external/external.go @@ -90,7 +90,7 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io. // write to temp file f, err := os.CreateTemp("", "gitea_input") if err != nil { - return fmt.Errorf("%s create temp file when rendering %s failed: %v", p.Name(), p.Command, err) + return fmt.Errorf("%s create temp file when rendering %s failed: %w", p.Name(), p.Command, err) } tmpPath := f.Name() defer func() { @@ -102,12 +102,12 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io. _, err = io.Copy(f, input) if err != nil { f.Close() - return fmt.Errorf("%s write data to temp file when rendering %s failed: %v", p.Name(), p.Command, err) + return fmt.Errorf("%s write data to temp file when rendering %s failed: %w", p.Name(), p.Command, err) } err = f.Close() if err != nil { - return fmt.Errorf("%s close temp file when rendering %s failed: %v", p.Name(), p.Command, err) + return fmt.Errorf("%s close temp file when rendering %s failed: %w", p.Name(), p.Command, err) } args = append(args, f.Name()) } @@ -137,7 +137,7 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io. process.SetSysProcAttribute(cmd) if err := cmd.Run(); err != nil { - return fmt.Errorf("%s render run command %s %v failed: %v", p.Name(), commands[0], args, err) + return fmt.Errorf("%s render run command %s %v failed: %w", p.Name(), commands[0], args, err) } return nil } diff --git a/modules/markup/orgmode/orgmode.go b/modules/markup/orgmode/orgmode.go index 1c02f274ba6..abbff1e435e 100644 --- a/modules/markup/orgmode/orgmode.go +++ b/modules/markup/orgmode/orgmode.go @@ -110,7 +110,7 @@ func Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error res, err := org.New().Silent().Parse(input, "").Write(w) if err != nil { - return fmt.Errorf("orgmode.Render failed: %v", err) + return fmt.Errorf("orgmode.Render failed: %w", err) } _, err = io.Copy(output, strings.NewReader(res)) return err diff --git a/modules/mcaptcha/mcaptcha.go b/modules/mcaptcha/mcaptcha.go index b889cf423b6..0c0fcce49d9 100644 --- a/modules/mcaptcha/mcaptcha.go +++ b/modules/mcaptcha/mcaptcha.go @@ -21,7 +21,7 @@ func Verify(ctx context.Context, token string) (bool, error) { Token: token, }) if err != nil { - return false, fmt.Errorf("wasn't able to verify mCaptcha: %v", err) + return false, fmt.Errorf("wasn't able to verify mCaptcha: %w", err) } return valid, nil } diff --git a/modules/options/dynamic.go b/modules/options/dynamic.go index eeef11e8daa..37398675809 100644 --- a/modules/options/dynamic.go +++ b/modules/options/dynamic.go @@ -32,12 +32,12 @@ func Dir(name string) ([]string, error) { isDir, err := util.IsDir(customDir) if err != nil { - return []string{}, fmt.Errorf("Unabe to check if custom directory %s is a directory. %v", customDir, err) + return []string{}, fmt.Errorf("Unabe to check if custom directory %s is a directory. %w", customDir, err) } if isDir { files, err := util.StatDir(customDir, true) if err != nil { - return []string{}, fmt.Errorf("Failed to read custom directory. %v", err) + return []string{}, fmt.Errorf("Failed to read custom directory. %w", err) } result = append(result, files...) @@ -47,12 +47,12 @@ func Dir(name string) ([]string, error) { isDir, err = util.IsDir(staticDir) if err != nil { - return []string{}, fmt.Errorf("unable to check if static directory %s is a directory. %v", staticDir, err) + return []string{}, fmt.Errorf("unable to check if static directory %s is a directory. %w", staticDir, err) } if isDir { files, err := util.StatDir(staticDir, true) if err != nil { - return []string{}, fmt.Errorf("Failed to read static directory. %v", err) + return []string{}, fmt.Errorf("Failed to read static directory. %w", err) } result = append(result, files...) diff --git a/modules/packages/nuget/symbol_extractor.go b/modules/packages/nuget/symbol_extractor.go index 13641ca6ef9..9c04d7bfb4e 100644 --- a/modules/packages/nuget/symbol_extractor.go +++ b/modules/packages/nuget/symbol_extractor.go @@ -75,7 +75,7 @@ func ExtractPortablePdb(r io.ReaderAt, size int64) (PortablePdbList, error) { id, err := ParseDebugHeaderID(buf) if err != nil { buf.Close() - return fmt.Errorf("Invalid PDB file: %v", err) + return fmt.Errorf("Invalid PDB file: %w", err) } if _, err := buf.Seek(0, io.SeekStart); err != nil { diff --git a/modules/private/hook.go b/modules/private/hook.go index 559019344e4..e208c143789 100644 --- a/modules/private/hook.go +++ b/modules/private/hook.go @@ -163,7 +163,7 @@ func HookProcReceive(ctx context.Context, ownerName, repoName string, opts HookO req.Body(jsonBytes) resp, err := req.Response() if err != nil { - return nil, fmt.Errorf("Unable to contact gitea: %v", err.Error()) + return nil, fmt.Errorf("Unable to contact gitea: %w", err) } defer resp.Body.Close() @@ -189,7 +189,7 @@ func SetDefaultBranch(ctx context.Context, ownerName, repoName, branch string) e req.SetTimeout(60*time.Second, 60*time.Second) resp, err := req.Response() if err != nil { - return fmt.Errorf("Unable to contact gitea: %v", err) + return fmt.Errorf("Unable to contact gitea: %w", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { @@ -213,7 +213,7 @@ func SSHLog(ctx context.Context, isErr bool, msg string) error { req.SetTimeout(60*time.Second, 60*time.Second) resp, err := req.Response() if err != nil { - return fmt.Errorf("unable to contact gitea: %v", err) + return fmt.Errorf("unable to contact gitea: %w", err) } defer resp.Body.Close() diff --git a/modules/queue/queue_wrapped.go b/modules/queue/queue_wrapped.go index 02f7818aa89..e581ba75f30 100644 --- a/modules/queue/queue_wrapped.go +++ b/modules/queue/queue_wrapped.go @@ -76,9 +76,9 @@ func (q *delayedStarter) setInternal(atShutdown func(func()), handle HandlerFunc i++ if q.maxAttempts > 0 && i > q.maxAttempts { if bs, ok := q.cfg.([]byte); ok { - return fmt.Errorf("unable to create queue %v for %s with cfg %s by max attempts: error: %v", q.underlying, q.name, string(bs), err) + return fmt.Errorf("unable to create queue %v for %s with cfg %s by max attempts: error: %w", q.underlying, q.name, string(bs), err) } - return fmt.Errorf("unable to create queue %v for %s with cfg %#v by max attempts: error: %v", q.underlying, q.name, q.cfg, err) + return fmt.Errorf("unable to create queue %v for %s with cfg %#v by max attempts: error: %w", q.underlying, q.name, q.cfg, err) } sleepTime := 100 * time.Millisecond if q.timeout > 0 && q.maxAttempts > 0 { diff --git a/modules/recaptcha/recaptcha.go b/modules/recaptcha/recaptcha.go index c6798f71177..91b70dc588a 100644 --- a/modules/recaptcha/recaptcha.go +++ b/modules/recaptcha/recaptcha.go @@ -37,7 +37,7 @@ func Verify(ctx context.Context, response string) (bool, error) { req, err := http.NewRequestWithContext(ctx, http.MethodPost, util.URLJoin(setting.Service.RecaptchaURL, apiURL), strings.NewReader(post.Encode())) if err != nil { - return false, fmt.Errorf("Failed to create CAPTCHA request: %v", err) + return false, fmt.Errorf("Failed to create CAPTCHA request: %w", err) } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") diff --git a/modules/repository/commits.go b/modules/repository/commits.go index c4a69f4a019..7d6eec151f4 100644 --- a/modules/repository/commits.go +++ b/modules/repository/commits.go @@ -78,7 +78,7 @@ func (pc *PushCommits) toAPIPayloadCommit(ctx context.Context, repoPath, repoLin fileStatus, err := git.GetCommitFileStatus(ctx, repoPath, commit.Sha1) if err != nil { - return nil, fmt.Errorf("FileStatus [commit_sha1: %s]: %v", commit.Sha1, err) + return nil, fmt.Errorf("FileStatus [commit_sha1: %s]: %w", commit.Sha1, err) } return &api.PayloadCommit{ diff --git a/modules/repository/create.go b/modules/repository/create.go index 966a6a2f211..1fec0335a28 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -37,7 +37,7 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re has, err := repo_model.IsRepositoryExist(ctx, u, repo.Name) if err != nil { - return fmt.Errorf("IsRepositoryExist: %v", err) + return fmt.Errorf("IsRepositoryExist: %w", err) } else if has { return repo_model.ErrRepoAlreadyExist{ Uname: u.Name, @@ -100,11 +100,11 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re // Remember visibility preference. u.LastRepoVisibility = repo.IsPrivate if err = user_model.UpdateUserCols(ctx, u, "last_repo_visibility"); err != nil { - return fmt.Errorf("UpdateUserCols: %v", err) + return fmt.Errorf("UpdateUserCols: %w", err) } if err = user_model.IncrUserRepoNum(ctx, u.ID); err != nil { - return fmt.Errorf("IncrUserRepoNum: %v", err) + return fmt.Errorf("IncrUserRepoNum: %w", err) } u.NumRepos++ @@ -112,40 +112,40 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re if u.IsOrganization() { teams, err := organization.FindOrgTeams(ctx, u.ID) if err != nil { - return fmt.Errorf("FindOrgTeams: %v", err) + return fmt.Errorf("FindOrgTeams: %w", err) } for _, t := range teams { if t.IncludesAllRepositories { if err := models.AddRepository(ctx, t, repo); err != nil { - return fmt.Errorf("AddRepository: %v", err) + return fmt.Errorf("AddRepository: %w", err) } } } if isAdmin, err := access_model.IsUserRepoAdmin(ctx, repo, doer); err != nil { - return fmt.Errorf("IsUserRepoAdmin: %v", err) + return fmt.Errorf("IsUserRepoAdmin: %w", err) } else if !isAdmin { // Make creator repo admin if it wasn't assigned automatically if err = addCollaborator(ctx, repo, doer); err != nil { - return fmt.Errorf("addCollaborator: %v", err) + return fmt.Errorf("addCollaborator: %w", err) } if err = repo_model.ChangeCollaborationAccessModeCtx(ctx, repo, doer.ID, perm.AccessModeAdmin); err != nil { - return fmt.Errorf("ChangeCollaborationAccessModeCtx: %v", err) + return fmt.Errorf("ChangeCollaborationAccessModeCtx: %w", err) } } } else if err = access_model.RecalculateAccesses(ctx, repo); err != nil { // Organization automatically called this in AddRepository method. - return fmt.Errorf("RecalculateAccesses: %v", err) + return fmt.Errorf("RecalculateAccesses: %w", err) } if setting.Service.AutoWatchNewRepos { if err = repo_model.WatchRepo(ctx, doer.ID, repo.ID, true); err != nil { - return fmt.Errorf("WatchRepo: %v", err) + return fmt.Errorf("WatchRepo: %w", err) } } if err = webhook.CopyDefaultWebhooksToRepo(ctx, repo.ID); err != nil { - return fmt.Errorf("CopyDefaultWebhooksToRepo: %v", err) + return fmt.Errorf("CopyDefaultWebhooksToRepo: %w", err) } return nil @@ -248,7 +248,7 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m return fmt.Errorf( "delete repo directory %s/%s failed(2): %v", u.Name, repo.Name, err2) } - return fmt.Errorf("initRepository: %v", err) + return fmt.Errorf("initRepository: %w", err) } // Initialize Issue Labels if selected @@ -256,12 +256,12 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m if err = InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil { rollbackRepo = repo rollbackRepo.OwnerID = u.ID - return fmt.Errorf("InitializeLabels: %v", err) + return fmt.Errorf("InitializeLabels: %w", err) } } if err := CheckDaemonExportOK(ctx, repo); err != nil { - return fmt.Errorf("checkDaemonExportOK: %v", err) + return fmt.Errorf("checkDaemonExportOK: %w", err) } if stdout, _, err := git.NewCommand(ctx, "update-server-info"). @@ -270,7 +270,7 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err) rollbackRepo = repo rollbackRepo.OwnerID = u.ID - return fmt.Errorf("CreateRepository(git update-server-info): %v", err) + return fmt.Errorf("CreateRepository(git update-server-info): %w", err) } return nil }); err != nil { @@ -290,12 +290,12 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m func UpdateRepoSize(ctx context.Context, repo *repo_model.Repository) error { size, err := util.GetDirectorySize(repo.RepoPath()) if err != nil { - return fmt.Errorf("updateSize: %v", err) + return fmt.Errorf("updateSize: %w", err) } lfsSize, err := git_model.GetRepoLFSSize(ctx, repo.ID) if err != nil { - return fmt.Errorf("updateSize: GetLFSMetaObjects: %v", err) + return fmt.Errorf("updateSize: GetLFSMetaObjects: %w", err) } return repo_model.UpdateRepoSize(ctx, repo.ID, size+lfsSize) @@ -339,7 +339,7 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili e := db.GetEngine(ctx) if _, err = e.ID(repo.ID).AllCols().Update(repo); err != nil { - return fmt.Errorf("update: %v", err) + return fmt.Errorf("update: %w", err) } if err = UpdateRepoSize(ctx, repo); err != nil { @@ -348,12 +348,12 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili if visibilityChanged { if err = repo.GetOwner(ctx); err != nil { - return fmt.Errorf("getOwner: %v", err) + return fmt.Errorf("getOwner: %w", err) } if repo.Owner.IsOrganization() { // Organization repository need to recalculate access table when visibility is changed. if err = access_model.RecalculateTeamAccesses(ctx, repo, 0); err != nil { - return fmt.Errorf("recalculateTeamAccesses: %v", err) + return fmt.Errorf("recalculateTeamAccesses: %w", err) } } @@ -374,12 +374,12 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili forkRepos, err := repo_model.GetRepositoriesByForkID(ctx, repo.ID) if err != nil { - return fmt.Errorf("getRepositoriesByForkID: %v", err) + return fmt.Errorf("getRepositoriesByForkID: %w", err) } for i := range forkRepos { forkRepos[i].IsPrivate = repo.IsPrivate || repo.Owner.Visibility == api.VisibleTypePrivate if err = UpdateRepository(ctx, forkRepos[i], true); err != nil { - return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err) + return fmt.Errorf("updateRepository[%d]: %w", forkRepos[i].ID, err) } } } diff --git a/modules/repository/generate.go b/modules/repository/generate.go index a69dd12a789..c5fd7d60bfc 100644 --- a/modules/repository/generate.go +++ b/modules/repository/generate.go @@ -153,22 +153,22 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r Depth: 1, Branch: templateRepo.DefaultBranch, }); err != nil { - return fmt.Errorf("git clone: %v", err) + return fmt.Errorf("git clone: %w", err) } if err := util.RemoveAll(path.Join(tmpDir, ".git")); err != nil { - return fmt.Errorf("remove git dir: %v", err) + return fmt.Errorf("remove git dir: %w", err) } // Variable expansion gt, err := checkGiteaTemplate(tmpDir) if err != nil { - return fmt.Errorf("checkGiteaTemplate: %v", err) + return fmt.Errorf("checkGiteaTemplate: %w", err) } if gt != nil { if err := util.Remove(gt.Path); err != nil { - return fmt.Errorf("remove .giteatemplate: %v", err) + return fmt.Errorf("remove .giteatemplate: %w", err) } // Avoid walking tree if there are no globs @@ -215,7 +215,7 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r SetDescription(fmt.Sprintf("generateRepoCommit (git remote add): %s to %s", templateRepoPath, tmpDir)). RunStdString(&git.RunOpts{Dir: tmpDir, Env: env}); err != nil { log.Error("Unable to add %v as remote origin to temporary repo to %s: stdout %s\nError: %v", repo, tmpDir, stdout, err) - return fmt.Errorf("git remote add: %v", err) + return fmt.Errorf("git remote add: %w", err) } // set default branch based on whether it's specified in the newly generated repo or not @@ -230,7 +230,7 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *repo_model.Repository) (err error) { tmpDir, err := os.MkdirTemp(os.TempDir(), "gitea-"+repo.Name) if err != nil { - return fmt.Errorf("Failed to create temp dir for repository %s: %v", repo.RepoPath(), err) + return fmt.Errorf("Failed to create temp dir for repository %s: %w", repo.RepoPath(), err) } defer func() { @@ -240,12 +240,12 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r }() if err = generateRepoCommit(ctx, repo, templateRepo, generateRepo, tmpDir); err != nil { - return fmt.Errorf("generateRepoCommit: %v", err) + return fmt.Errorf("generateRepoCommit: %w", err) } // re-fetch repo if repo, err = repo_model.GetRepositoryByIDCtx(ctx, repo.ID); err != nil { - return fmt.Errorf("getRepositoryByID: %v", err) + return fmt.Errorf("getRepositoryByID: %w", err) } // if there was no default branch supplied when generating the repo, use the default one from the template @@ -255,14 +255,14 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r 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() if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { - return fmt.Errorf("setDefaultBranch: %v", err) + return fmt.Errorf("setDefaultBranch: %w", err) } if err = UpdateRepository(ctx, repo, false); err != nil { - return fmt.Errorf("updateRepository: %v", err) + return fmt.Errorf("updateRepository: %w", err) } return nil @@ -275,11 +275,11 @@ func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *repo_mo } if err := UpdateRepoSize(ctx, generateRepo); err != nil { - return fmt.Errorf("failed to update size for repository: %v", err) + return fmt.Errorf("failed to update size for repository: %w", err) } if err := git_model.CopyLFS(ctx, generateRepo, templateRepo); err != nil { - return fmt.Errorf("failed to copy LFS: %v", err) + return fmt.Errorf("failed to copy LFS: %w", err) } return nil } @@ -342,14 +342,14 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ } if err = CheckDaemonExportOK(ctx, generateRepo); err != nil { - return generateRepo, fmt.Errorf("checkDaemonExportOK: %v", err) + return generateRepo, fmt.Errorf("checkDaemonExportOK: %w", err) } if stdout, _, err := git.NewCommand(ctx, "update-server-info"). SetDescription(fmt.Sprintf("GenerateRepository(git update-server-info): %s", repoPath)). RunStdString(&git.RunOpts{Dir: repoPath}); err != nil { log.Error("GenerateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", generateRepo, stdout, err) - return generateRepo, fmt.Errorf("error in GenerateRepository(git update-server-info): %v", err) + return generateRepo, fmt.Errorf("error in GenerateRepository(git update-server-info): %w", err) } return generateRepo, nil diff --git a/modules/repository/hooks.go b/modules/repository/hooks.go index 7bc77552bd0..4d7d294a921 100644 --- a/modules/repository/hooks.go +++ b/modules/repository/hooks.go @@ -123,30 +123,30 @@ func createDelegateHooks(repoPath string) (err error) { newHookPath := filepath.Join(hookDir, hookName+".d", "gitea") if err := os.MkdirAll(filepath.Join(hookDir, hookName+".d"), os.ModePerm); err != nil { - return fmt.Errorf("create hooks dir '%s': %v", filepath.Join(hookDir, hookName+".d"), err) + return fmt.Errorf("create hooks dir '%s': %w", filepath.Join(hookDir, hookName+".d"), err) } // WARNING: This will override all old server-side hooks if err = util.Remove(oldHookPath); err != nil && !os.IsNotExist(err) { - return fmt.Errorf("unable to pre-remove old hook file '%s' prior to rewriting: %v ", oldHookPath, err) + return fmt.Errorf("unable to pre-remove old hook file '%s' prior to rewriting: %w ", oldHookPath, err) } if err = os.WriteFile(oldHookPath, []byte(hookTpls[i]), 0o777); err != nil { - return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err) + return fmt.Errorf("write old hook file '%s': %w", oldHookPath, err) } if err = ensureExecutable(oldHookPath); err != nil { - return fmt.Errorf("Unable to set %s executable. Error %v", oldHookPath, err) + return fmt.Errorf("Unable to set %s executable. Error %w", oldHookPath, err) } if err = util.Remove(newHookPath); err != nil && !os.IsNotExist(err) { - return fmt.Errorf("unable to pre-remove new hook file '%s' prior to rewriting: %v", newHookPath, err) + return fmt.Errorf("unable to pre-remove new hook file '%s' prior to rewriting: %w", newHookPath, err) } if err = os.WriteFile(newHookPath, []byte(giteaHookTpls[i]), 0o777); err != nil { - return fmt.Errorf("write new hook file '%s': %v", newHookPath, err) + return fmt.Errorf("write new hook file '%s': %w", newHookPath, err) } if err = ensureExecutable(newHookPath); err != nil { - return fmt.Errorf("Unable to set %s executable. Error %v", oldHookPath, err) + return fmt.Errorf("Unable to set %s executable. Error %w", oldHookPath, err) } } diff --git a/modules/repository/init.go b/modules/repository/init.go index 473729a5997..65072a95994 100644 --- a/modules/repository/init.go +++ b/modules/repository/init.go @@ -91,7 +91,7 @@ func GetRepoInitFile(tp, name string) ([]byte, error) { func GetLabelTemplateFile(name string) ([][3]string, error) { data, err := GetRepoInitFile("label", name) if err != nil { - return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("GetRepoInitFile: %v", err)} + return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("GetRepoInitFile: %w", err)} } lines := strings.Split(string(data), "\n") @@ -232,13 +232,13 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir, SetDescription(fmt.Sprintf("prepareRepoCommit (git clone): %s to %s", repoPath, tmpDir)). RunStdString(&git.RunOpts{Dir: "", Env: env}); err != nil { log.Error("Failed to clone from %v into %s: stdout: %s\nError: %v", repo, tmpDir, stdout, err) - return fmt.Errorf("git clone: %v", err) + return fmt.Errorf("git clone: %w", err) } // README data, err := GetRepoInitFile("readme", opts.Readme) if err != nil { - return fmt.Errorf("GetRepoInitFile[%s]: %v", opts.Readme, err) + return fmt.Errorf("GetRepoInitFile[%s]: %w", opts.Readme, err) } cloneLink := repo.CloneLink() @@ -256,7 +256,7 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir, } if err = os.WriteFile(filepath.Join(tmpDir, "README.md"), []byte(res), 0o644); err != nil { - return fmt.Errorf("write README.md: %v", err) + return fmt.Errorf("write README.md: %w", err) } // .gitignore @@ -266,7 +266,7 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir, for _, name := range names { data, err = GetRepoInitFile("gitignore", name) if err != nil { - return fmt.Errorf("GetRepoInitFile[%s]: %v", name, err) + return fmt.Errorf("GetRepoInitFile[%s]: %w", name, err) } buf.WriteString("# ---> " + name + "\n") buf.Write(data) @@ -275,7 +275,7 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir, if buf.Len() > 0 { if err = os.WriteFile(filepath.Join(tmpDir, ".gitignore"), buf.Bytes(), 0o644); err != nil { - return fmt.Errorf("write .gitignore: %v", err) + return fmt.Errorf("write .gitignore: %w", err) } } } @@ -284,11 +284,11 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir, if len(opts.License) > 0 { data, err = GetRepoInitFile("license", opts.License) if err != nil { - return fmt.Errorf("GetRepoInitFile[%s]: %v", opts.License, err) + return fmt.Errorf("GetRepoInitFile[%s]: %w", opts.License, err) } if err = os.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0o644); err != nil { - return fmt.Errorf("write LICENSE: %v", err) + return fmt.Errorf("write LICENSE: %w", err) } } @@ -314,7 +314,7 @@ func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Reposi SetDescription(fmt.Sprintf("initRepoCommit (git add): %s", tmpPath)). RunStdString(&git.RunOpts{Dir: tmpPath}); err != nil { log.Error("git add --all failed: Stdout: %s\nError: %v", stdout, err) - return fmt.Errorf("git add --all: %v", err) + return fmt.Errorf("git add --all: %w", err) } cmd := git.NewCommand(ctx, @@ -344,7 +344,7 @@ func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Reposi SetDescription(fmt.Sprintf("initRepoCommit (git commit): %s", tmpPath)). RunStdString(&git.RunOpts{Dir: tmpPath, Env: env}); err != nil { log.Error("Failed to commit: %v: Stdout: %s\nError: %v", cmd.String(), stdout, err) - return fmt.Errorf("git commit: %v", err) + return fmt.Errorf("git commit: %w", err) } if len(defaultBranch) == 0 { @@ -355,7 +355,7 @@ func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Reposi SetDescription(fmt.Sprintf("initRepoCommit (git push): %s", tmpPath)). RunStdString(&git.RunOpts{Dir: tmpPath, Env: InternalPushingEnvironment(u, repo)}); err != nil { log.Error("Failed to push back to HEAD: Stdout: %s\nError: %v", stdout, err) - return fmt.Errorf("git push: %v", err) + return fmt.Errorf("git push: %w", err) } return nil @@ -378,9 +378,9 @@ func checkInitRepository(ctx context.Context, owner, name string) (err error) { // Init git bare new repository. if err = git.InitRepository(ctx, repoPath, true); err != nil { - return fmt.Errorf("git.InitRepository: %v", err) + return fmt.Errorf("git.InitRepository: %w", err) } else if err = createDelegateHooks(repoPath); err != nil { - return fmt.Errorf("createDelegateHooks: %v", err) + return fmt.Errorf("createDelegateHooks: %w", err) } return nil } @@ -395,7 +395,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re if opts.AutoInit { tmpDir, err := os.MkdirTemp(os.TempDir(), "gitea-"+repo.Name) if err != nil { - return fmt.Errorf("Failed to create temp dir for repository %s: %v", repo.RepoPath(), err) + return fmt.Errorf("Failed to create temp dir for repository %s: %w", repo.RepoPath(), err) } defer func() { if err := util.RemoveAll(tmpDir); err != nil { @@ -404,19 +404,19 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re }() if err = prepareRepoCommit(ctx, repo, tmpDir, repoPath, opts); err != nil { - return fmt.Errorf("prepareRepoCommit: %v", err) + return fmt.Errorf("prepareRepoCommit: %w", err) } // Apply changes and commit. if err = initRepoCommit(ctx, tmpDir, repo, u, opts.DefaultBranch); err != nil { - return fmt.Errorf("initRepoCommit: %v", err) + return fmt.Errorf("initRepoCommit: %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) } if !opts.AutoInit { @@ -429,16 +429,16 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re repo.DefaultBranch = opts.DefaultBranch 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() if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { - return fmt.Errorf("setDefaultBranch: %v", err) + return fmt.Errorf("setDefaultBranch: %w", err) } } if err = UpdateRepository(ctx, repo, false); err != nil { - return fmt.Errorf("updateRepository: %v", err) + return fmt.Errorf("updateRepository: %w", err) } return nil diff --git a/modules/repository/repo.go b/modules/repository/repo.go index b01be322d2f..de6de3bda44 100644 --- a/modules/repository/repo.go +++ b/modules/repository/repo.go @@ -70,7 +70,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, var err error if err = util.RemoveAll(repoPath); err != nil { - return repo, fmt.Errorf("Failed to remove %s: %v", repoPath, err) + return repo, fmt.Errorf("Failed to remove %s: %w", repoPath, err) } if err = git.Clone(ctx, opts.CloneAddr, repoPath, git.CloneRepoOptions{ @@ -79,7 +79,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, Timeout: migrateTimeout, SkipTLSVerify: setting.Migrations.SkipTLSVerify, }); err != nil { - return repo, fmt.Errorf("Clone: %v", err) + return repo, fmt.Errorf("Clone: %w", err) } if err := git.WriteCommitGraph(ctx, repoPath); err != nil { @@ -91,7 +91,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, wikiRemotePath := WikiRemoteURL(ctx, opts.CloneAddr) if len(wikiRemotePath) > 0 { if err := util.RemoveAll(wikiPath); err != nil { - return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err) + return repo, fmt.Errorf("Failed to remove %s: %w", wikiPath, err) } if err := git.Clone(ctx, wikiRemotePath, wikiPath, git.CloneRepoOptions{ @@ -103,7 +103,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, }); err != nil { log.Warn("Clone wiki: %v", err) if err := util.RemoveAll(wikiPath); err != nil { - return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err) + return repo, fmt.Errorf("Failed to remove %s: %w", wikiPath, err) } } else { if err := git.WriteCommitGraph(ctx, wikiPath); err != nil { @@ -118,25 +118,25 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, } if err = CheckDaemonExportOK(ctx, repo); err != nil { - return repo, fmt.Errorf("checkDaemonExportOK: %v", err) + return repo, fmt.Errorf("checkDaemonExportOK: %w", err) } if stdout, _, err := git.NewCommand(ctx, "update-server-info"). SetDescription(fmt.Sprintf("MigrateRepositoryGitData(git update-server-info): %s", repoPath)). RunStdString(&git.RunOpts{Dir: repoPath}); err != nil { log.Error("MigrateRepositoryGitData(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err) - return repo, fmt.Errorf("error in MigrateRepositoryGitData(git update-server-info): %v", err) + return repo, fmt.Errorf("error in MigrateRepositoryGitData(git update-server-info): %w", err) } gitRepo, err := git.OpenRepository(ctx, repoPath) if err != nil { - return repo, fmt.Errorf("OpenRepository: %v", err) + return repo, fmt.Errorf("OpenRepository: %w", err) } defer gitRepo.Close() repo.IsEmpty, err = gitRepo.IsEmpty() if err != nil { - return repo, fmt.Errorf("git.IsEmpty: %v", err) + return repo, fmt.Errorf("git.IsEmpty: %w", err) } if !repo.IsEmpty { @@ -144,7 +144,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, // Try to get HEAD branch and set it as default branch. headBranch, err := gitRepo.GetHEADBranch() if err != nil { - return repo, fmt.Errorf("GetHEADBranch: %v", err) + return repo, fmt.Errorf("GetHEADBranch: %w", err) } if headBranch != nil { repo.DefaultBranch = headBranch.Name @@ -207,7 +207,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, } if err = repo_model.InsertMirror(ctx, &mirrorModel); err != nil { - return repo, fmt.Errorf("InsertOne: %v", err) + return repo, fmt.Errorf("InsertOne: %w", err) } repo.IsMirror = true @@ -231,11 +231,11 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, func cleanUpMigrateGitConfig(configPath string) error { cfg, err := ini.Load(configPath) if err != nil { - return fmt.Errorf("open config file: %v", err) + return fmt.Errorf("open config file: %w", err) } cfg.DeleteSection("remote \"origin\"") if err = cfg.SaveToIndent(configPath, "\t"); err != nil { - return fmt.Errorf("save config file: %v", err) + return fmt.Errorf("save config file: %w", err) } return nil } @@ -244,22 +244,22 @@ func cleanUpMigrateGitConfig(configPath string) error { func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo_model.Repository, error) { repoPath := repo.RepoPath() if err := createDelegateHooks(repoPath); err != nil { - return repo, fmt.Errorf("createDelegateHooks: %v", err) + return repo, fmt.Errorf("createDelegateHooks: %w", err) } if repo.HasWiki() { if err := createDelegateHooks(repo.WikiPath()); err != nil { - return repo, fmt.Errorf("createDelegateHooks.(wiki): %v", err) + return repo, fmt.Errorf("createDelegateHooks.(wiki): %w", err) } } _, _, err := git.NewCommand(ctx, "remote", "rm", "origin").RunStdString(&git.RunOpts{Dir: repoPath}) if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") { - return repo, fmt.Errorf("CleanUpMigrateInfo: %v", err) + return repo, fmt.Errorf("CleanUpMigrateInfo: %w", err) } if repo.HasWiki() { if err := cleanUpMigrateGitConfig(path.Join(repo.WikiPath(), "config")); err != nil { - return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %v", err) + return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %w", err) } } diff --git a/modules/repository/temp.go b/modules/repository/temp.go index 5947d299654..21af0394690 100644 --- a/modules/repository/temp.go +++ b/modules/repository/temp.go @@ -27,12 +27,12 @@ func LocalCopyPath() string { func CreateTemporaryPath(prefix string) (string, error) { if err := os.MkdirAll(LocalCopyPath(), os.ModePerm); err != nil { log.Error("Unable to create localcopypath directory: %s (%v)", LocalCopyPath(), err) - return "", fmt.Errorf("Failed to create localcopypath directory %s: %v", LocalCopyPath(), err) + return "", fmt.Errorf("Failed to create localcopypath directory %s: %w", LocalCopyPath(), err) } basePath, err := os.MkdirTemp(LocalCopyPath(), prefix+".git") if err != nil { log.Error("Unable to create temporary directory: %s-*.git (%v)", prefix, err) - return "", fmt.Errorf("Failed to create dir %s-*.git: %v", prefix, err) + return "", fmt.Errorf("Failed to create dir %s-*.git: %w", prefix, err) } return basePath, nil diff --git a/modules/setting/database.go b/modules/setting/database.go index af4e780d76b..4e554573959 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -137,7 +137,7 @@ func DBConnStr() (string, error) { return "", errors.New("this binary version does not build support for SQLite3") } if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil { - return "", fmt.Errorf("Failed to create directories: %v", err) + return "", fmt.Errorf("Failed to create directories: %w", err) } journalMode := "" if Database.SQLiteJournalMode != "" { diff --git a/modules/setting/directory.go b/modules/setting/directory.go index 5dcdd89c04f..26415102860 100644 --- a/modules/setting/directory.go +++ b/modules/setting/directory.go @@ -23,13 +23,13 @@ func PrepareAppDataPath() error { if os.IsNotExist(err) { err = os.MkdirAll(AppDataPath, os.ModePerm) if err != nil { - return fmt.Errorf("unable to create the APP_DATA_PATH directory: %q, Error: %v", AppDataPath, err) + return fmt.Errorf("unable to create the APP_DATA_PATH directory: %q, Error: %w", AppDataPath, err) } return nil } if err != nil { - return fmt.Errorf("unable to use APP_DATA_PATH %q. Error: %v", AppDataPath, err) + return fmt.Errorf("unable to use APP_DATA_PATH %q. Error: %w", AppDataPath, err) } if !st.IsDir() /* also works for symlink */ { diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 5c0776602bc..649cb488b39 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -26,7 +26,7 @@ func getPublicKeyFromResponse(b []byte, keyID *url.URL) (p crypto.PublicKey, err person := ap.PersonNew(ap.IRI(keyID.String())) err = person.UnmarshalJSON(b) if err != nil { - err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %v", err) + err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %w", err) return } pubKey := person.PublicKey diff --git a/routers/api/v1/misc/signing.go b/routers/api/v1/misc/signing.go index b99e560ccfd..1070cc78cb4 100644 --- a/routers/api/v1/misc/signing.go +++ b/routers/api/v1/misc/signing.go @@ -59,6 +59,6 @@ func SigningKey(ctx *context.APIContext) { } _, err = ctx.Write([]byte(content)) if err != nil { - ctx.Error(http.StatusInternalServerError, "gpg export", fmt.Errorf("Error writing key content %v", err)) + ctx.Error(http.StatusInternalServerError, "gpg export", fmt.Errorf("Error writing key content %w", err)) } } diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go index 0c780eb97d0..14f6aa61486 100644 --- a/routers/api/v1/repo/key.go +++ b/routers/api/v1/repo/key.go @@ -174,7 +174,7 @@ func HandleCheckKeyStringError(ctx *context.APIContext, err error) { } else if asymkey_model.IsErrKeyUnableVerify(err) { ctx.Error(http.StatusUnprocessableEntity, "", "Unable to verify key content") } else { - ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid key content: %v", err)) + ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid key content: %w", err)) } } diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go index 10e78f2a9b9..97ef69a6ea6 100644 --- a/routers/api/v1/repo/status.go +++ b/routers/api/v1/repo/status.go @@ -194,7 +194,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) { State: ctx.FormTrim("state"), }) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetCommitStatuses", fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %v", repo.FullName(), sha, ctx.FormInt("page"), err)) + ctx.Error(http.StatusInternalServerError, "GetCommitStatuses", fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %w", repo.FullName(), sha, ctx.FormInt("page"), err)) return } @@ -255,7 +255,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) { statuses, count, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx)) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetLatestCommitStatus", fmt.Errorf("GetLatestCommitStatus[%s, %s]: %v", repo.FullName(), sha, err)) + ctx.Error(http.StatusInternalServerError, "GetLatestCommitStatus", fmt.Errorf("GetLatestCommitStatus[%s, %s]: %w", repo.FullName(), sha, err)) return } diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go index f0f8503996b..ab318661625 100644 --- a/routers/api/v1/repo/tag.go +++ b/routers/api/v1/repo/tag.go @@ -190,7 +190,7 @@ func CreateTag(ctx *context.APIContext) { commit, err := ctx.Repo.GitRepo.GetCommit(form.Target) if err != nil { - ctx.Error(http.StatusNotFound, "target not found", fmt.Errorf("target not found: %v", err)) + ctx.Error(http.StatusNotFound, "target not found", fmt.Errorf("target not found: %w", err)) return } diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index b48bdb99517..25d70d7c478 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -70,7 +70,7 @@ func AutoSignIn(ctx *context.Context) (bool, error) { u, err := user_model.GetUserByName(ctx, uname) if err != nil { if !user_model.IsErrUserNotExist(err) { - return false, fmt.Errorf("GetUserByName: %v", err) + return false, fmt.Errorf("GetUserByName: %w", err) } return false, nil } diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index 9c929d990ec..4fba8d8e8c3 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -303,7 +303,7 @@ func InfoOAuth(ctx *context.Context) { func getOAuthGroupsForUser(user *user_model.User) ([]string, error) { orgs, err := org_model.GetUserOrgsList(user) if err != nil { - return nil, fmt.Errorf("GetUserOrgList: %v", err) + return nil, fmt.Errorf("GetUserOrgList: %w", err) } var groups []string @@ -311,7 +311,7 @@ func getOAuthGroupsForUser(user *user_model.User) ([]string, error) { groups = append(groups, org.Name) teams, err := org.LoadTeams() if err != nil { - return nil, fmt.Errorf("LoadTeams: %v", err) + return nil, fmt.Errorf("LoadTeams: %w", err) } for _, team := range teams { if team.IsMember(user.ID) { diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go index 41639c4603a..67cb6837a56 100644 --- a/routers/web/repo/lfs.go +++ b/routers/web/repo/lfs.go @@ -122,14 +122,14 @@ func LFSLocks(ctx *context.Context) { Shared: true, }); err != nil { log.Error("Failed to clone repository: %s (%v)", ctx.Repo.Repository.FullName(), err) - ctx.ServerError("LFSLocks", fmt.Errorf("failed to clone repository: %s (%v)", ctx.Repo.Repository.FullName(), err)) + ctx.ServerError("LFSLocks", fmt.Errorf("failed to clone repository: %s (%w)", ctx.Repo.Repository.FullName(), err)) return } gitRepo, err := git.OpenRepository(ctx, tmpBasePath) if err != nil { log.Error("Unable to open temporary repository: %s (%v)", tmpBasePath, err) - ctx.ServerError("LFSLocks", fmt.Errorf("failed to open new temporary repository in: %s %v", tmpBasePath, err)) + ctx.ServerError("LFSLocks", fmt.Errorf("failed to open new temporary repository in: %s %w", tmpBasePath, err)) return } defer gitRepo.Close() @@ -142,7 +142,7 @@ func LFSLocks(ctx *context.Context) { if err := gitRepo.ReadTreeToIndex(ctx.Repo.Repository.DefaultBranch); err != nil { log.Error("Unable to read the default branch to the index: %s (%v)", ctx.Repo.Repository.DefaultBranch, err) - ctx.ServerError("LFSLocks", fmt.Errorf("unable to read the default branch to the index: %s (%v)", ctx.Repo.Repository.DefaultBranch, err)) + ctx.ServerError("LFSLocks", fmt.Errorf("unable to read the default branch to the index: %s (%w)", ctx.Repo.Repository.DefaultBranch, err)) return } @@ -542,7 +542,7 @@ func LFSAutoAssociate(ctx *context.Context) { metas[i] = &git_model.LFSMetaObject{} metas[i].Size, err = strconv.ParseInt(oid[idx+1:], 10, 64) if err != nil { - ctx.ServerError("LFSAutoAssociate", fmt.Errorf("illegal oid input: %s %v", oid, err)) + ctx.ServerError("LFSAutoAssociate", fmt.Errorf("illegal oid input: %s %w", oid, err)) return } metas[i].Oid = oid[:idx] diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index 1e5710fa98b..0cb85f37984 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -46,11 +46,11 @@ func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *repo_model if repoCtx.GitRepo.IsBranchExist(release.Target) { commit, err := repoCtx.GitRepo.GetBranchCommit(release.Target) if err != nil { - return fmt.Errorf("GetBranchCommit: %v", err) + return fmt.Errorf("GetBranchCommit: %w", err) } countCache[release.Target], err = commit.CommitsCount() if err != nil { - return fmt.Errorf("CommitsCount: %v", err) + return fmt.Errorf("CommitsCount: %w", err) } } else { // Use NumCommits of the newest release on that target diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 974f03f9510..3e746d3f058 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -90,7 +90,7 @@ func checkContextUser(ctx *context.Context, uid int64) *user_model.User { } if err != nil { - ctx.ServerError("GetUserByID", fmt.Errorf("[%d]: %v", uid, err)) + ctx.ServerError("GetUserByID", fmt.Errorf("[%d]: %w", uid, err)) return nil } diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index e7abec0d3e8..2b5691ce885 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -1197,7 +1197,7 @@ func UpdateAvatarSetting(ctx *context.Context, form forms.AvatarForm) error { r, err := form.Avatar.Open() if err != nil { - return fmt.Errorf("Avatar.Open: %v", err) + return fmt.Errorf("Avatar.Open: %w", err) } defer r.Close() @@ -1207,14 +1207,14 @@ func UpdateAvatarSetting(ctx *context.Context, form forms.AvatarForm) error { data, err := io.ReadAll(r) if err != nil { - return fmt.Errorf("io.ReadAll: %v", err) + return fmt.Errorf("io.ReadAll: %w", err) } st := typesniffer.DetectContentType(data) if !(st.IsImage() && !st.IsSvgImage()) { return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image")) } if err = repo_service.UploadAvatar(ctxRepo, data); err != nil { - return fmt.Errorf("UploadAvatar: %v", err) + return fmt.Errorf("UploadAvatar: %w", err) } return nil } diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 837caedc846..95ec1aa2fa1 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -697,11 +697,11 @@ func issueIDsFromSearch(ctx *context.Context, ctxUser *user_model.User, keyword searchRepoIDs, err := issues_model.GetRepoIDsForIssuesOptions(opts, ctxUser) if err != nil { - return nil, fmt.Errorf("GetRepoIDsForIssuesOptions: %v", err) + return nil, fmt.Errorf("GetRepoIDsForIssuesOptions: %w", err) } issueIDsFromSearch, err := issue_indexer.SearchIssuesByKeyword(ctx, searchRepoIDs, keyword) if err != nil { - return nil, fmt.Errorf("SearchIssuesByKeyword: %v", err) + return nil, fmt.Errorf("SearchIssuesByKeyword: %w", err) } return issueIDsFromSearch, nil diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index c9a7afe982f..ba3f5b5080d 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -162,7 +162,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser * if form.Avatar != nil && form.Avatar.Filename != "" { fr, err := form.Avatar.Open() if err != nil { - return fmt.Errorf("Avatar.Open: %v", err) + return fmt.Errorf("Avatar.Open: %w", err) } defer fr.Close() @@ -172,7 +172,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser * data, err := io.ReadAll(fr) if err != nil { - return fmt.Errorf("io.ReadAll: %v", err) + return fmt.Errorf("io.ReadAll: %w", err) } st := typesniffer.DetectContentType(data) @@ -180,7 +180,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser * return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image")) } if err = user_service.UploadAvatar(ctxUser, data); err != nil { - return fmt.Errorf("UploadAvatar: %v", err) + return fmt.Errorf("UploadAvatar: %w", err) } } else if ctxUser.UseCustomAvatar && ctxUser.Avatar == "" { // No avatar is uploaded but setting has been changed to enable, @@ -191,7 +191,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser * } if err := user_model.UpdateUserCols(ctx, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil { - return fmt.Errorf("UpdateUser: %v", err) + return fmt.Errorf("UpdateUser: %w", err) } return nil diff --git a/services/agit/agit.go b/services/agit/agit.go index cea2b1f5805..a7e701d6c4f 100644 --- a/services/agit/agit.go +++ b/services/agit/agit.go @@ -99,7 +99,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. pr, err := issues_model.GetUnmergedPullRequest(repo.ID, repo.ID, headBranch, baseBranchName, issues_model.PullRequestFlowAGit) if err != nil { if !issues_model.IsErrPullRequestNotExist(err) { - return nil, fmt.Errorf("Failed to get unmerged agit flow pull request in repository: %s/%s Error: %v", ownerName, repoName, err) + return nil, fmt.Errorf("Failed to get unmerged agit flow pull request in repository: %s/%s Error: %w", ownerName, repoName, err) } // create a new pull request @@ -109,7 +109,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. if !has || len(title) == 0 { commit, err := gitRepo.GetCommit(opts.NewCommitIDs[i]) if err != nil { - return nil, fmt.Errorf("Failed to get commit %s in repository: %s/%s Error: %v", opts.NewCommitIDs[i], ownerName, repoName, err) + return nil, fmt.Errorf("Failed to get commit %s in repository: %s/%s Error: %w", opts.NewCommitIDs[i], ownerName, repoName, err) } title = strings.Split(commit.CommitMessage, "\n")[0] } @@ -118,7 +118,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. pusher, err := user_model.GetUserByID(opts.UserID) if err != nil { - return nil, fmt.Errorf("Failed to get user. Error: %v", err) + return nil, fmt.Errorf("Failed to get user. Error: %w", err) } prIssue := &issues_model.Issue{ @@ -160,12 +160,12 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. // update exist pull request if err := pr.LoadBaseRepoCtx(ctx); err != nil { - return nil, fmt.Errorf("Unable to load base repository for PR[%d] Error: %v", pr.ID, err) + return nil, fmt.Errorf("Unable to load base repository for PR[%d] Error: %w", pr.ID, err) } oldCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName()) if err != nil { - return nil, fmt.Errorf("Unable to get ref commit id in base repository for PR[%d] Error: %v", pr.ID, err) + return nil, fmt.Errorf("Unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err) } if oldCommitID == opts.NewCommitIDs[i] { @@ -181,7 +181,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. if !forcePush { output, _, err := git.NewCommand(ctx, "rev-list", "--max-count=1").AddDynamicArguments(oldCommitID, "^"+opts.NewCommitIDs[i]).RunStdString(&git.RunOpts{Dir: repo.RepoPath(), Env: os.Environ()}) if err != nil { - return nil, fmt.Errorf("Fail to detect force push: %v", err) + return nil, fmt.Errorf("Fail to detect force push: %w", err) } else if len(output) > 0 { results = append(results, private.HookProcReceiveRefResult{ OriginalRef: opts.RefFullNames[i], @@ -195,17 +195,17 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. pr.HeadCommitID = opts.NewCommitIDs[i] if err = pull_service.UpdateRef(ctx, pr); err != nil { - return nil, fmt.Errorf("Failed to update pull ref. Error: %v", err) + return nil, fmt.Errorf("Failed to update pull ref. Error: %w", err) } pull_service.AddToTaskQueue(pr) pusher, err := user_model.GetUserByID(opts.UserID) if err != nil { - return nil, fmt.Errorf("Failed to get user. Error: %v", err) + return nil, fmt.Errorf("Failed to get user. Error: %w", err) } err = pr.LoadIssue() if err != nil { - return nil, fmt.Errorf("Failed to load pull issue. Error: %v", err) + return nil, fmt.Errorf("Failed to load pull issue. Error: %w", err) } comment, err := issues_model.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i]) if err == nil && comment != nil { diff --git a/services/attachment/attachment.go b/services/attachment/attachment.go index cce36206a76..557cc808a3e 100644 --- a/services/attachment/attachment.go +++ b/services/attachment/attachment.go @@ -29,7 +29,7 @@ func NewAttachment(attach *repo_model.Attachment, file io.Reader) (*repo_model.A attach.UUID = uuid.New().String() size, err := storage.Attachments.Save(attach.RelativePath(), file, -1) if err != nil { - return fmt.Errorf("Create: %v", err) + return fmt.Errorf("Create: %w", err) } attach.Size = size diff --git a/services/auth/source/ldap/source_search.go b/services/auth/source/ldap/source_search.go index a97a1179d9b..6ea84ec2884 100644 --- a/services/auth/source/ldap/source_search.go +++ b/services/auth/source/ldap/source_search.go @@ -125,13 +125,13 @@ func dial(source *Source) (*ldap.Conn, error) { conn, err := ldap.Dial("tcp", net.JoinHostPort(source.Host, strconv.Itoa(source.Port))) if err != nil { - return nil, fmt.Errorf("error during Dial: %v", err) + return nil, fmt.Errorf("error during Dial: %w", err) } if source.SecurityProtocol == SecurityProtocolStartTLS { if err = conn.StartTLS(tlsConfig); err != nil { conn.Close() - return nil, fmt.Errorf("error during StartTLS: %v", err) + return nil, fmt.Errorf("error during StartTLS: %w", err) } } diff --git a/services/auth/source/oauth2/jwtsigningkey.go b/services/auth/source/oauth2/jwtsigningkey.go index d9312ee820b..352f932746d 100644 --- a/services/auth/source/oauth2/jwtsigningkey.go +++ b/services/auth/source/oauth2/jwtsigningkey.go @@ -339,7 +339,7 @@ func InitSigningKey() error { } if err != nil { - return fmt.Errorf("Error while loading or creating JWT key: %v", err) + return fmt.Errorf("Error while loading or creating JWT key: %w", err) } signingKey, err := CreateJWTSigningKey(setting.OAuth2.JWTSigningAlgorithm, key) diff --git a/services/auth/source/smtp/auth.go b/services/auth/source/smtp/auth.go index a9e4b0e5f44..487c049722e 100644 --- a/services/auth/source/smtp/auth.go +++ b/services/auth/source/smtp/auth.go @@ -95,7 +95,7 @@ func Authenticate(a smtp.Auth, source *Source) error { hasStartTLS, _ := client.Extension("STARTTLS") if !source.UseTLS() && hasStartTLS { if err = client.StartTLS(tlsConfig); err != nil { - return fmt.Errorf("failed to start StartTLS: %v", err) + return fmt.Errorf("failed to start StartTLS: %w", err) } } diff --git a/services/issue/milestone.go b/services/issue/milestone.go index d7c5fa45516..756a8625de4 100644 --- a/services/issue/milestone.go +++ b/services/issue/milestone.go @@ -19,7 +19,7 @@ func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *is if issue.MilestoneID > 0 { has, err := issues_model.HasMilestoneByRepoID(ctx, issue.RepoID, issue.MilestoneID) if err != nil { - return fmt.Errorf("HasMilestoneByRepoID: %v", err) + return fmt.Errorf("HasMilestoneByRepoID: %w", err) } if !has { return fmt.Errorf("HasMilestoneByRepoID: issue doesn't exist") @@ -76,7 +76,7 @@ func ChangeMilestoneAssign(issue *issues_model.Issue, doer *user_model.User, old } if err = committer.Commit(); err != nil { - return fmt.Errorf("Commit: %v", err) + return fmt.Errorf("Commit: %w", err) } notification.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID) diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go index 15bfa4af416..33a20694e83 100644 --- a/services/mailer/mail_issue.go +++ b/services/mailer/mail_issue.go @@ -44,13 +44,13 @@ const ( func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_model.User) error { // Required by the mail composer; make sure to load these before calling the async function if err := ctx.Issue.LoadRepo(ctx); err != nil { - return fmt.Errorf("LoadRepo(): %v", err) + return fmt.Errorf("LoadRepo(): %w", err) } if err := ctx.Issue.LoadPoster(); err != nil { - return fmt.Errorf("LoadPoster(): %v", err) + return fmt.Errorf("LoadPoster(): %w", err) } if err := ctx.Issue.LoadPullRequest(); err != nil { - return fmt.Errorf("LoadPullRequest(): %v", err) + return fmt.Errorf("LoadPullRequest(): %w", err) } // Enough room to avoid reallocations @@ -62,21 +62,21 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo // =========== Assignees =========== ids, err := issues_model.GetAssigneeIDsByIssue(ctx.Issue.ID) if err != nil { - return fmt.Errorf("GetAssigneeIDsByIssue(%d): %v", ctx.Issue.ID, err) + return fmt.Errorf("GetAssigneeIDsByIssue(%d): %w", ctx.Issue.ID, err) } unfiltered = append(unfiltered, ids...) // =========== Participants (i.e. commenters, reviewers) =========== ids, err = issues_model.GetParticipantsIDsByIssueID(ctx.Issue.ID) if err != nil { - return fmt.Errorf("GetParticipantsIDsByIssueID(%d): %v", ctx.Issue.ID, err) + return fmt.Errorf("GetParticipantsIDsByIssueID(%d): %w", ctx.Issue.ID, err) } unfiltered = append(unfiltered, ids...) // =========== Issue watchers =========== ids, err = issues_model.GetIssueWatchersIDs(ctx, ctx.Issue.ID, true) if err != nil { - return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err) + return fmt.Errorf("GetIssueWatchersIDs(%d): %w", ctx.Issue.ID, err) } unfiltered = append(unfiltered, ids...) @@ -85,7 +85,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo if !(ctx.Issue.IsPull && ctx.Issue.PullRequest.IsWorkInProgress() && ctx.ActionType != activities_model.ActionCreatePullRequest) { ids, err = repo_model.GetRepoWatchersIDs(ctx, ctx.Issue.RepoID) if err != nil { - return fmt.Errorf("GetRepoWatchersIDs(%d): %v", ctx.Issue.RepoID, err) + return fmt.Errorf("GetRepoWatchersIDs(%d): %w", ctx.Issue.RepoID, err) } unfiltered = append(ids, unfiltered...) } @@ -99,13 +99,13 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo // =========== Mentions =========== if err = mailIssueCommentBatch(ctx, mentions, visited, true); err != nil { - return fmt.Errorf("mailIssueCommentBatch() mentions: %v", err) + return fmt.Errorf("mailIssueCommentBatch() mentions: %w", err) } // Avoid mailing explicit unwatched ids, err = issues_model.GetIssueWatchersIDs(ctx, ctx.Issue.ID, false) if err != nil { - return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err) + return fmt.Errorf("GetIssueWatchersIDs(%d): %w", ctx.Issue.ID, err) } visited.AddMultiple(ids...) @@ -114,7 +114,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo return err } if err = mailIssueCommentBatch(ctx, unfilteredUsers, visited, false); err != nil { - return fmt.Errorf("mailIssueCommentBatch(): %v", err) + return fmt.Errorf("mailIssueCommentBatch(): %w", err) } return nil diff --git a/services/mailer/mailer.go b/services/mailer/mailer.go index 1f43c7f8279..46b0c8e2f45 100644 --- a/services/mailer/mailer.go +++ b/services/mailer/mailer.go @@ -161,7 +161,7 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error { conn, err := net.Dial(network, address) if err != nil { - return fmt.Errorf("failed to establish network connection to SMTP server: %v", err) + return fmt.Errorf("failed to establish network connection to SMTP server: %w", err) } defer conn.Close() @@ -175,7 +175,7 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error { if opts.UseClientCert { cert, err := tls.LoadX509KeyPair(opts.ClientCertFile, opts.ClientKeyFile) if err != nil { - return fmt.Errorf("could not load SMTP client certificate: %v", err) + return fmt.Errorf("could not load SMTP client certificate: %w", err) } tlsconfig.Certificates = []tls.Certificate{cert} } @@ -191,7 +191,7 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error { } client, err := smtp.NewClient(conn, host) if err != nil { - return fmt.Errorf("could not initiate SMTP session: %v", err) + return fmt.Errorf("could not initiate SMTP session: %w", err) } if opts.EnableHelo { @@ -199,12 +199,12 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error { if len(hostname) == 0 { hostname, err = os.Hostname() if err != nil { - return fmt.Errorf("could not retrieve system hostname: %v", err) + return fmt.Errorf("could not retrieve system hostname: %w", err) } } if err = client.Hello(hostname); err != nil { - return fmt.Errorf("failed to issue HELO command: %v", err) + return fmt.Errorf("failed to issue HELO command: %w", err) } } @@ -212,7 +212,7 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error { hasStartTLS, _ := client.Extension("STARTTLS") if hasStartTLS { if err = client.StartTLS(tlsconfig); err != nil { - return fmt.Errorf("failed to start TLS connection: %v", err) + return fmt.Errorf("failed to start TLS connection: %w", err) } } else { log.Warn("StartTLS requested, but SMTP server does not support it; falling back to regular SMTP") @@ -238,34 +238,34 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error { if auth != nil { if err = client.Auth(auth); err != nil { - return fmt.Errorf("failed to authenticate SMTP: %v", err) + return fmt.Errorf("failed to authenticate SMTP: %w", err) } } } if opts.OverrideEnvelopeFrom { if err = client.Mail(opts.EnvelopeFrom); err != nil { - return fmt.Errorf("failed to issue MAIL command: %v", err) + return fmt.Errorf("failed to issue MAIL command: %w", err) } } else { if err = client.Mail(from); err != nil { - return fmt.Errorf("failed to issue MAIL command: %v", err) + return fmt.Errorf("failed to issue MAIL command: %w", err) } } for _, rec := range to { if err = client.Rcpt(rec); err != nil { - return fmt.Errorf("failed to issue RCPT command: %v", err) + return fmt.Errorf("failed to issue RCPT command: %w", err) } } w, err := client.Data() if err != nil { - return fmt.Errorf("failed to issue DATA command: %v", err) + return fmt.Errorf("failed to issue DATA command: %w", err) } else if _, err = msg.WriteTo(w); err != nil { - return fmt.Errorf("SMTP write failed: %v", err) + return fmt.Errorf("SMTP write failed: %w", err) } else if err = w.Close(); err != nil { - return fmt.Errorf("SMTP close failed: %v", err) + return fmt.Errorf("SMTP close failed: %w", err) } return client.Quit() diff --git a/services/migrations/dump.go b/services/migrations/dump.go index 31fb1b4cf3b..4ab4539c89a 100644 --- a/services/migrations/dump.go +++ b/services/migrations/dump.go @@ -157,7 +157,7 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp SkipTLSVerify: setting.Migrations.SkipTLSVerify, }) if err != nil { - return fmt.Errorf("Clone: %v", err) + return fmt.Errorf("Clone: %w", err) } if err := git.WriteCommitGraph(g.ctx, repoPath); err != nil { return err @@ -168,7 +168,7 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp wikiRemotePath := repository.WikiRemoteURL(g.ctx, remoteAddr) if len(wikiRemotePath) > 0 { if err := os.MkdirAll(wikiPath, os.ModePerm); err != nil { - return fmt.Errorf("Failed to remove %s: %v", wikiPath, err) + return fmt.Errorf("Failed to remove %s: %w", wikiPath, err) } if err := git.Clone(g.ctx, wikiRemotePath, wikiPath, git.CloneRepoOptions{ @@ -180,7 +180,7 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp }); err != nil { log.Warn("Clone wiki: %v", err) if err := os.RemoveAll(wikiPath); err != nil { - return fmt.Errorf("Failed to remove %s: %v", wikiPath, err) + return fmt.Errorf("Failed to remove %s: %w", wikiPath, err) } } else if err := git.WriteCommitGraph(g.ctx, wikiPath); err != nil { return err diff --git a/services/migrations/gitea_downloader.go b/services/migrations/gitea_downloader.go index c52f3026915..9775af1cdc3 100644 --- a/services/migrations/gitea_downloader.go +++ b/services/migrations/gitea_downloader.go @@ -408,7 +408,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err Type: gitea_sdk.IssueTypeIssue, }) if err != nil { - return nil, false, fmt.Errorf("error while listing issues: %v", err) + return nil, false, fmt.Errorf("error while listing issues: %w", err) } for _, issue := range issues { @@ -476,7 +476,7 @@ func (g *GiteaDownloader) GetComments(commentable base.Commentable) ([]*base.Com Page: i, }}) if err != nil { - return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %v", commentable.GetForeignIndex(), err) + return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %w", commentable.GetForeignIndex(), err) } for _, comment := range comments { @@ -520,7 +520,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques State: gitea_sdk.StateAll, }) if err != nil { - return nil, false, fmt.Errorf("error while listing pull requests (page: %d, pagesize: %d). Error: %v", page, perPage, err) + return nil, false, fmt.Errorf("error while listing pull requests (page: %d, pagesize: %d). Error: %w", page, perPage, err) } for _, pr := range prs { var milestone string diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index c4cb59f5723..8a7533b3d17 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -288,12 +288,12 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error { commit, err := g.gitRepo.GetTagCommit(rel.TagName) if !git.IsErrNotExist(err) { if err != nil { - return fmt.Errorf("GetTagCommit[%v]: %v", rel.TagName, err) + return fmt.Errorf("GetTagCommit[%v]: %w", rel.TagName, err) } rel.Sha1 = commit.ID.String() rel.NumCommits, err = commit.CommitsCount() if err != nil { - return fmt.Errorf("CommitsCount: %v", err) + return fmt.Errorf("CommitsCount: %w", err) } } } diff --git a/services/migrations/github.go b/services/migrations/github.go index 0ffdbb042af..016d0588659 100644 --- a/services/migrations/github.go +++ b/services/migrations/github.go @@ -427,7 +427,7 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool, g.waitAndPickClient() issues, resp, err := g.getClient().Issues.ListByRepo(g.ctx, g.repoOwner, g.repoName, opt) if err != nil { - return nil, false, fmt.Errorf("error while listing repos: %v", err) + return nil, false, fmt.Errorf("error while listing repos: %w", err) } log.Trace("Request get issues %d/%d, but in fact get %d", perPage, page, len(issues)) g.setRate(&resp.Rate) @@ -523,7 +523,7 @@ func (g *GithubDownloaderV3) getComments(commentable base.Commentable) ([]*base. g.waitAndPickClient() comments, resp, err := g.getClient().Issues.ListComments(g.ctx, g.repoOwner, g.repoName, int(commentable.GetForeignIndex()), opt) if err != nil { - return nil, fmt.Errorf("error while listing repos: %v", err) + return nil, fmt.Errorf("error while listing repos: %w", err) } g.setRate(&resp.Rate) for _, comment := range comments { @@ -595,7 +595,7 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment, g.waitAndPickClient() comments, resp, err := g.getClient().Issues.ListComments(g.ctx, g.repoOwner, g.repoName, 0, opt) if err != nil { - return nil, false, fmt.Errorf("error while listing repos: %v", err) + return nil, false, fmt.Errorf("error while listing repos: %w", err) } isEnd := resp.NextPage == 0 @@ -663,7 +663,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq g.waitAndPickClient() prs, resp, err := g.getClient().PullRequests.List(g.ctx, g.repoOwner, g.repoName, opt) if err != nil { - return nil, false, fmt.Errorf("error while listing repos: %v", err) + return nil, false, fmt.Errorf("error while listing repos: %w", err) } log.Trace("Request get pull requests %d/%d, but in fact get %d", perPage, page, len(prs)) g.setRate(&resp.Rate) @@ -813,7 +813,7 @@ func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Rev g.waitAndPickClient() reviews, resp, err := g.getClient().PullRequests.ListReviews(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), opt) if err != nil { - return nil, fmt.Errorf("error while listing repos: %v", err) + return nil, fmt.Errorf("error while listing repos: %w", err) } g.setRate(&resp.Rate) for _, review := range reviews { @@ -827,7 +827,7 @@ func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Rev g.waitAndPickClient() reviewComments, resp, err := g.getClient().PullRequests.ListReviewComments(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), review.GetID(), opt2) if err != nil { - return nil, fmt.Errorf("error while listing repos: %v", err) + return nil, fmt.Errorf("error while listing repos: %w", err) } g.setRate(&resp.Rate) @@ -853,7 +853,7 @@ func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Rev g.waitAndPickClient() reviewers, resp, err := g.getClient().PullRequests.ListReviewers(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), opt) if err != nil { - return nil, fmt.Errorf("error while listing repos: %v", err) + return nil, fmt.Errorf("error while listing repos: %w", err) } g.setRate(&resp.Rate) for _, user := range reviewers.Users { diff --git a/services/migrations/gitlab.go b/services/migrations/gitlab.go index 95bec59e834..b8bb0c77b54 100644 --- a/services/migrations/gitlab.go +++ b/services/migrations/gitlab.go @@ -398,7 +398,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er issues, _, err := g.client.Issues.ListProjectIssues(g.repoID, opt, nil, gitlab.WithContext(g.ctx)) if err != nil { - return nil, false, fmt.Errorf("error while listing issues: %v", err) + return nil, false, fmt.Errorf("error while listing issues: %w", err) } for _, issue := range issues { @@ -419,7 +419,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er for { awards, _, err := g.client.AwardEmoji.ListIssueAwardEmoji(g.repoID, issue.IID, &gitlab.ListAwardEmojiOptions{Page: awardPage, PerPage: perPage}, gitlab.WithContext(g.ctx)) if err != nil { - return nil, false, fmt.Errorf("error while listing issue awards: %v", err) + return nil, false, fmt.Errorf("error while listing issue awards: %w", err) } for i := range awards { @@ -487,7 +487,7 @@ func (g *GitlabDownloader) GetComments(commentable base.Commentable) ([]*base.Co } if err != nil { - return nil, false, fmt.Errorf("error while listing comments: %v %v", g.repoID, err) + return nil, false, fmt.Errorf("error while listing comments: %v %w", g.repoID, err) } for _, comment := range comments { // Flatten comment threads @@ -541,7 +541,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque prs, _, err := g.client.MergeRequests.ListProjectMergeRequests(g.repoID, opt, nil, gitlab.WithContext(g.ctx)) if err != nil { - return nil, false, fmt.Errorf("error while listing merge requests: %v", err) + return nil, false, fmt.Errorf("error while listing merge requests: %w", err) } for _, pr := range prs { @@ -583,7 +583,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque for { awards, _, err := g.client.AwardEmoji.ListMergeRequestAwardEmoji(g.repoID, pr.IID, &gitlab.ListAwardEmojiOptions{Page: awardPage, PerPage: perPage}, gitlab.WithContext(g.ctx)) if err != nil { - return nil, false, fmt.Errorf("error while listing merge requests awards: %v", err) + return nil, false, fmt.Errorf("error while listing merge requests awards: %w", err) } for i := range awards { diff --git a/services/migrations/gogs.go b/services/migrations/gogs.go index 46cc3ca4164..14bc734c4e0 100644 --- a/services/migrations/gogs.go +++ b/services/migrations/gogs.go @@ -223,7 +223,7 @@ func (g *GogsDownloader) getIssues(page int, state string) ([]*base.Issue, bool, State: state, }) if err != nil { - return nil, false, fmt.Errorf("error while listing repos: %v", err) + return nil, false, fmt.Errorf("error while listing repos: %w", err) } for _, issue := range issues { @@ -242,7 +242,7 @@ func (g *GogsDownloader) GetComments(commentable base.Commentable) ([]*base.Comm comments, err := g.client.ListIssueComments(g.repoOwner, g.repoName, commentable.GetForeignIndex()) if err != nil { - return nil, false, fmt.Errorf("error while listing repos: %v", err) + return nil, false, fmt.Errorf("error while listing repos: %w", err) } for _, comment := range comments { if len(comment.Body) == 0 || comment.Poster == nil { diff --git a/services/org/org.go b/services/org/org.go index b24b7e34c48..39845610d24 100644 --- a/services/org/org.go +++ b/services/org/org.go @@ -28,20 +28,20 @@ func DeleteOrganization(org *organization.Organization) error { // Check ownership of repository. count, err := repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{OwnerID: org.ID}) if err != nil { - return fmt.Errorf("GetRepositoryCount: %v", err) + return fmt.Errorf("GetRepositoryCount: %w", err) } else if count > 0 { return models.ErrUserOwnRepos{UID: org.ID} } // Check ownership of packages. if ownsPackages, err := packages_model.HasOwnerPackages(ctx, org.ID); err != nil { - return fmt.Errorf("HasOwnerPackages: %v", err) + return fmt.Errorf("HasOwnerPackages: %w", err) } else if ownsPackages { return models.ErrUserOwnPackages{UID: org.ID} } if err := organization.DeleteOrganization(ctx, org); err != nil { - return fmt.Errorf("DeleteOrganization: %v", err) + return fmt.Errorf("DeleteOrganization: %w", err) } if err := commiter.Commit(); err != nil { @@ -54,13 +54,13 @@ func DeleteOrganization(org *organization.Organization) error { path := user_model.UserPath(org.Name) if err := util.RemoveAll(path); err != nil { - return fmt.Errorf("Failed to RemoveAll %s: %v", path, err) + return fmt.Errorf("Failed to RemoveAll %s: %w", path, err) } if len(org.Avatar) > 0 { avatarPath := org.CustomAvatarRelativePath() if err := storage.Avatars.Delete(avatarPath); err != nil { - return fmt.Errorf("Failed to remove %s: %v", avatarPath, err) + return fmt.Errorf("Failed to remove %s: %w", avatarPath, err) } } diff --git a/services/pull/check.go b/services/pull/check.go index 765672190dc..830ff640b52 100644 --- a/services/pull/check.go +++ b/services/pull/check.go @@ -168,13 +168,13 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com var err error pr.BaseRepo, err = repo_model.GetRepositoryByID(pr.BaseRepoID) if err != nil { - return nil, fmt.Errorf("GetRepositoryByID: %v", err) + return nil, fmt.Errorf("GetRepositoryByID: %w", err) } } indexTmpPath, err := os.MkdirTemp(os.TempDir(), "gitea-"+pr.BaseRepo.Name) if err != nil { - return nil, fmt.Errorf("Failed to create temp dir for repository %s: %v", pr.BaseRepo.RepoPath(), err) + return nil, fmt.Errorf("Failed to create temp dir for repository %s: %w", pr.BaseRepo.RepoPath(), err) } defer func() { if err := util.RemoveAll(indexTmpPath); err != nil { @@ -192,12 +192,12 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com if strings.Contains(err.Error(), "exit status 1") { return nil, nil } - return nil, fmt.Errorf("git merge-base --is-ancestor: %v", err) + return nil, fmt.Errorf("git merge-base --is-ancestor: %w", err) } commitIDBytes, err := os.ReadFile(pr.BaseRepo.RepoPath() + "/" + headFile) if err != nil { - return nil, fmt.Errorf("ReadFile(%s): %v", headFile, err) + return nil, fmt.Errorf("ReadFile(%s): %w", headFile, err) } commitID := string(commitIDBytes) if len(commitID) < 40 { @@ -209,7 +209,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com mergeCommit, _, err := git.NewCommand(ctx, "rev-list", "--ancestry-path", "--merges", "--reverse").AddDynamicArguments(cmd). RunStdString(&git.RunOpts{Dir: "", Env: []string{"GIT_INDEX_FILE=" + indexTmpPath, "GIT_DIR=" + pr.BaseRepo.RepoPath()}}) if err != nil { - return nil, fmt.Errorf("git rev-list --ancestry-path --merges --reverse: %v", err) + return nil, fmt.Errorf("git rev-list --ancestry-path --merges --reverse: %w", err) } else if len(mergeCommit) < 40 { // PR was maybe fast-forwarded, so just use last commit of PR mergeCommit = commitID[:40] @@ -217,13 +217,13 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) if err != nil { - return nil, fmt.Errorf("OpenRepository: %v", err) + return nil, fmt.Errorf("OpenRepository: %w", err) } defer gitRepo.Close() commit, err := gitRepo.GetCommit(mergeCommit[:40]) if err != nil { - return nil, fmt.Errorf("GetMergeCommit[%v]: %v", mergeCommit[:40], err) + return nil, fmt.Errorf("GetMergeCommit[%v]: %w", mergeCommit[:40], err) } return commit, nil diff --git a/services/pull/merge.go b/services/pull/merge.go index f9a4e6705f4..0ca37301833 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -136,10 +136,10 @@ func GetDefaultMergeMessage(baseGitRepo *git.Repository, pr *issues_model.PullRe func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string) error { if err := pr.LoadHeadRepo(); err != nil { log.Error("LoadHeadRepo: %v", err) - return fmt.Errorf("LoadHeadRepo: %v", err) + return fmt.Errorf("LoadHeadRepo: %w", err) } else if err := pr.LoadBaseRepo(); err != nil { log.Error("LoadBaseRepo: %v", err) - return fmt.Errorf("LoadBaseRepo: %v", err) + return fmt.Errorf("LoadBaseRepo: %w", err) } pullWorkingPool.CheckIn(fmt.Sprint(pr.ID)) @@ -247,7 +247,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode trackingCommitID, _, err := git.NewCommand(ctx, "show-ref", "--hash").AddDynamicArguments(git.BranchPrefix + trackingBranch).RunStdString(&git.RunOpts{Dir: tmpBasePath}) if err != nil { log.Error("show-ref[%s] --hash refs/heads/trackingn: %v", tmpBasePath, git.BranchPrefix+trackingBranch, err) - return "", fmt.Errorf("getDiffTree: %v", err) + return "", fmt.Errorf("getDiffTree: %w", err) } if strings.TrimSpace(trackingCommitID) != expectedHeadCommitID { return "", models.ErrSHADoesNotMatch{ @@ -263,19 +263,19 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode sparseCheckoutList, err := getDiffTree(ctx, tmpBasePath, baseBranch, trackingBranch) if err != nil { log.Error("getDiffTree(%s, %s, %s): %v", tmpBasePath, baseBranch, trackingBranch, err) - return "", fmt.Errorf("getDiffTree: %v", err) + return "", fmt.Errorf("getDiffTree: %w", err) } infoPath := filepath.Join(tmpBasePath, ".git", "info") if err := os.MkdirAll(infoPath, 0o700); err != nil { log.Error("Unable to create .git/info in %s: %v", tmpBasePath, err) - return "", fmt.Errorf("Unable to create .git/info in tmpBasePath: %v", err) + return "", fmt.Errorf("Unable to create .git/info in tmpBasePath: %w", err) } sparseCheckoutListPath := filepath.Join(infoPath, "sparse-checkout") if err := os.WriteFile(sparseCheckoutListPath, []byte(sparseCheckoutList), 0o600); err != nil { log.Error("Unable to write .git/info/sparse-checkout file in %s: %v", tmpBasePath, err) - return "", fmt.Errorf("Unable to write .git/info/sparse-checkout file in tmpBasePath: %v", err) + return "", fmt.Errorf("Unable to write .git/info/sparse-checkout file in tmpBasePath: %w", err) } gitConfigCommand := func() *git.Command { @@ -290,7 +290,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode Stderr: &errbuf, }); err != nil { log.Error("git config [filter.lfs.process -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git config [filter.lfs.process -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git config [filter.lfs.process -> <> ]: %w\n%s\n%s", err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -302,7 +302,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode Stderr: &errbuf, }); err != nil { log.Error("git config [filter.lfs.required -> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git config [filter.lfs.required -> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git config [filter.lfs.required -> ]: %w\n%s\n%s", err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -314,7 +314,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode Stderr: &errbuf, }); err != nil { log.Error("git config [filter.lfs.clean -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git config [filter.lfs.clean -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git config [filter.lfs.clean -> <> ]: %w\n%s\n%s", err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -326,7 +326,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode Stderr: &errbuf, }); err != nil { log.Error("git config [filter.lfs.smudge -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git config [filter.lfs.smudge -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git config [filter.lfs.smudge -> <> ]: %w\n%s\n%s", err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -338,7 +338,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode Stderr: &errbuf, }); err != nil { log.Error("git config [core.sparseCheckout -> true ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git config [core.sparsecheckout -> true]: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git config [core.sparsecheckout -> true]: %w\n%s\n%s", err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -351,7 +351,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode Stderr: &errbuf, }); err != nil { log.Error("git read-tree HEAD: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("Unable to read base branch in to the index: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("Unable to read base branch in to the index: %w\n%s\n%s", err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -409,7 +409,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode Stderr: &errbuf, }); err != nil { log.Error("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -435,7 +435,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode if readErr != nil { // Abandon this attempt to handle the error log.Error("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) } commitSha = strings.TrimSpace(string(commitShaBytes)) ok = true @@ -445,7 +445,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode if !ok { log.Error("Unable to determine failing commit sha for this rebase message. Cannot cast as models.ErrRebaseConflicts.") log.Error("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) } log.Debug("RebaseConflict at %s [%s:%s -> %s:%s]: %v\n%s\n%s", commitSha, pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) return "", models.ErrRebaseConflicts{ @@ -457,7 +457,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode } } log.Error("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -475,7 +475,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode Stderr: &errbuf, }); err != nil { log.Error("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -509,7 +509,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode if err = pr.Issue.LoadPoster(); err != nil { log.Error("LoadPoster: %v", err) - return "", fmt.Errorf("LoadPoster: %v", err) + return "", fmt.Errorf("LoadPoster: %w", err) } sig := pr.Issue.Poster.NewGitSig() if signArg == "" { @@ -521,7 +521,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode Stderr: &errbuf, }); err != nil { log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git commit [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) } } else { if setting.Repository.PullRequest.AddCoCommitterTrailers && committer.String() != sig.String() { @@ -539,7 +539,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode Stderr: &errbuf, }); err != nil { log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("git commit [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) } } outbuf.Reset() @@ -551,15 +551,15 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode // OK we should cache our current head and origin/headbranch mergeHeadSHA, err := git.GetFullCommitID(ctx, tmpBasePath, "HEAD") if err != nil { - return "", fmt.Errorf("Failed to get full commit id for HEAD: %v", err) + return "", fmt.Errorf("Failed to get full commit id for HEAD: %w", err) } mergeBaseSHA, err := git.GetFullCommitID(ctx, tmpBasePath, "original_"+baseBranch) if err != nil { - return "", fmt.Errorf("Failed to get full commit id for origin/%s: %v", pr.BaseBranch, err) + return "", fmt.Errorf("Failed to get full commit id for origin/%s: %w", pr.BaseBranch, err) } mergeCommitID, err := git.GetFullCommitID(ctx, tmpBasePath, baseBranch) if err != nil { - return "", fmt.Errorf("Failed to get full commit id for the new merge: %v", err) + return "", fmt.Errorf("Failed to get full commit id for the new merge: %w", err) } // Now it's questionable about where this should go - either after or before the push @@ -643,7 +643,7 @@ func commitAndSignNoAuthor(ctx context.Context, pr *issues_model.PullRequest, me Stderr: &errbuf, }); err != nil { log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) - return fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) + return fmt.Errorf("git commit [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) } } else { if err := git.NewCommand(ctx, "commit").AddArguments(signArg).AddArguments("-m").AddDynamicArguments(message). @@ -654,7 +654,7 @@ func commitAndSignNoAuthor(ctx context.Context, pr *issues_model.PullRequest, me Stderr: &errbuf, }); err != nil { log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) - return fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) + return fmt.Errorf("git commit [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) } } return nil @@ -687,7 +687,7 @@ func runMergeCommand(pr *issues_model.PullRequest, mergeStyle repo_model.MergeSt } } log.Error("git merge [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) - return fmt.Errorf("git merge [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) + return fmt.Errorf("git merge [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) } return nil @@ -764,11 +764,11 @@ func IsUserAllowedToMerge(ctx context.Context, pr *issues_model.PullRequest, p a // CheckPullBranchProtections checks whether the PR is ready to be merged (reviews and status checks) func CheckPullBranchProtections(ctx context.Context, pr *issues_model.PullRequest, skipProtectedFilesCheck bool) (err error) { if err = pr.LoadBaseRepoCtx(ctx); err != nil { - return fmt.Errorf("LoadBaseRepo: %v", err) + return fmt.Errorf("LoadBaseRepo: %w", err) } if err = pr.LoadProtectedBranchCtx(ctx); err != nil { - return fmt.Errorf("LoadProtectedBranch: %v", err) + return fmt.Errorf("LoadProtectedBranch: %w", err) } if pr.ProtectedBranch == nil { return nil diff --git a/services/pull/patch.go b/services/pull/patch.go index b9f190826a4..9b87ac22e29 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -37,13 +37,13 @@ func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath()) if err != nil { - return fmt.Errorf("OpenRepository: %v", err) + return fmt.Errorf("OpenRepository: %w", err) } defer closer.Close() if err := gitRepo.GetDiffOrPatch(pr.MergeBase, pr.GetGitRefName(), w, patch, binary); err != nil { log.Error("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) - return fmt.Errorf("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) + return fmt.Errorf("Unable to get patch file from %s to %s in %s Error: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) } return nil } @@ -74,7 +74,7 @@ func TestPatch(pr *issues_model.PullRequest) error { gitRepo, err := git.OpenRepository(ctx, tmpBasePath) if err != nil { - return fmt.Errorf("OpenRepository: %v", err) + return fmt.Errorf("OpenRepository: %w", err) } defer gitRepo.Close() @@ -84,7 +84,7 @@ func TestPatch(pr *issues_model.PullRequest) error { var err2 error pr.MergeBase, err2 = gitRepo.GetRefCommitID(git.BranchPrefix + "base") if err2 != nil { - return fmt.Errorf("GetMergeBase: %v and can't find commit ID for base: %v", err, err2) + return fmt.Errorf("GetMergeBase: %v and can't find commit ID for base: %w", err, err2) } } pr.MergeBase = strings.TrimSpace(pr.MergeBase) @@ -104,7 +104,7 @@ func TestPatch(pr *issues_model.PullRequest) error { // 3. Check for protected files changes if err = checkPullFilesProtection(pr, gitRepo); err != nil { - return fmt.Errorf("pr.CheckPullFilesProtection(): %v", err) + return fmt.Errorf("pr.CheckPullFilesProtection(): %w", err) } if len(pr.ChangedProtectedFiles) > 0 { @@ -237,7 +237,7 @@ func AttemptThreeWayMerge(ctx context.Context, gitPath string, gitRepo *git.Repo // First we use read-tree to do a simple three-way merge if _, _, err := git.NewCommand(ctx, "read-tree", "-m").AddDynamicArguments(base, ours, theirs).RunStdString(&git.RunOpts{Dir: gitPath}); err != nil { log.Error("Unable to run read-tree -m! Error: %v", err) - return false, nil, fmt.Errorf("unable to run read-tree -m! Error: %v", err) + return false, nil, fmt.Errorf("unable to run read-tree -m! Error: %w", err) } // Then we use git ls-files -u to list the unmerged files and collate the triples in unmergedfiles @@ -319,7 +319,7 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo * tmpPatchFile, err := os.CreateTemp("", "patch") if err != nil { log.Error("Unable to create temporary patch file! Error: %v", err) - return false, fmt.Errorf("unable to create temporary patch file! Error: %v", err) + return false, fmt.Errorf("unable to create temporary patch file! Error: %w", err) } defer func() { _ = util.Remove(tmpPatchFile.Name()) @@ -328,12 +328,12 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo * if err := gitRepo.GetDiffBinary(pr.MergeBase, "tracking", tmpPatchFile); err != nil { tmpPatchFile.Close() log.Error("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) - return false, fmt.Errorf("unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) + return false, fmt.Errorf("unable to get patch file from %s to %s in %s Error: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) } stat, err := tmpPatchFile.Stat() if err != nil { tmpPatchFile.Close() - return false, fmt.Errorf("unable to stat patch file: %v", err) + return false, fmt.Errorf("unable to stat patch file: %w", err) } patchPath := tmpPatchFile.Name() tmpPatchFile.Close() @@ -350,7 +350,7 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo * // 4. Read the base branch in to the index of the temporary repository _, _, err = git.NewCommand(gitRepo.Ctx, "read-tree", "base").RunStdString(&git.RunOpts{Dir: tmpBasePath}) if err != nil { - return false, fmt.Errorf("git read-tree %s: %v", pr.BaseBranch, err) + return false, fmt.Errorf("git read-tree %s: %w", pr.BaseBranch, err) } // 5. Now get the pull request configuration to check if we need to ignore whitespace @@ -383,7 +383,7 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo * stderrReader, stderrWriter, err := os.Pipe() if err != nil { log.Error("Unable to open stderr pipe: %v", err) - return false, fmt.Errorf("unable to open stderr pipe: %v", err) + return false, fmt.Errorf("unable to open stderr pipe: %w", err) } defer func() { _ = stderrReader.Close() @@ -467,7 +467,7 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo * return true, nil } } else if err != nil { - return false, fmt.Errorf("git apply --check: %v", err) + return false, fmt.Errorf("git apply --check: %w", err) } return false, nil } diff --git a/services/pull/patch_unmerged.go b/services/pull/patch_unmerged.go index 465465d0dae..3f1bb7d5234 100644 --- a/services/pull/patch_unmerged.go +++ b/services/pull/patch_unmerged.go @@ -64,7 +64,7 @@ func readUnmergedLsFileLines(ctx context.Context, tmpBasePath string, outputChan lsFilesReader, lsFilesWriter, err := os.Pipe() if err != nil { log.Error("Unable to open stderr pipe: %v", err) - outputChan <- &lsFileLine{err: fmt.Errorf("unable to open stderr pipe: %v", err)} + outputChan <- &lsFileLine{err: fmt.Errorf("unable to open stderr pipe: %w", err)} return } defer func() { @@ -117,7 +117,7 @@ func readUnmergedLsFileLines(ctx context.Context, tmpBasePath string, outputChan }, }) if err != nil { - outputChan <- &lsFileLine{err: fmt.Errorf("git ls-files -u -z: %v", git.ConcatenateError(err, stderr.String()))} + outputChan <- &lsFileLine{err: fmt.Errorf("git ls-files -u -z: %w", git.ConcatenateError(err, stderr.String()))} } } @@ -163,7 +163,7 @@ func unmergedFiles(ctx context.Context, tmpBasePath string, unmerged chan *unmer log.Trace("Got line: %v Current State:\n%v", line, next) if line.err != nil { log.Error("Unable to run ls-files -u -z! Error: %v", line.err) - unmerged <- &unmergedFile{err: fmt.Errorf("unable to run ls-files -u -z! Error: %v", line.err)} + unmerged <- &unmergedFile{err: fmt.Errorf("unable to run ls-files -u -z! Error: %w", line.err)} return } diff --git a/services/pull/pull.go b/services/pull/pull.go index 3b58c675a37..5f8bd6b6712 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -224,7 +224,7 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer NewRef: targetBranch, } if _, err = issues_model.CreateComment(options); err != nil { - return fmt.Errorf("CreateChangeTargetBranchComment: %v", err) + return fmt.Errorf("CreateChangeTargetBranchComment: %w", err) } return nil @@ -233,11 +233,11 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer func checkForInvalidation(ctx context.Context, requests issues_model.PullRequestList, repoID int64, doer *user_model.User, branch string) error { repo, err := repo_model.GetRepositoryByID(repoID) if err != nil { - return fmt.Errorf("GetRepositoryByID: %v", err) + return fmt.Errorf("GetRepositoryByID: %w", err) } gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) if err != nil { - return fmt.Errorf("git.OpenRepository: %v", err) + return fmt.Errorf("git.OpenRepository: %w", err) } go func() { // FIXME: graceful: We need to tell the manager we're doing something... @@ -353,26 +353,26 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, // A commit can be considered to leave the PR untouched if the patch/diff with its merge base is unchanged func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest, oldCommitID, newCommitID string) (hasChanged bool, err error) { if err = pr.LoadHeadRepoCtx(ctx); err != nil { - return false, fmt.Errorf("LoadHeadRepo: %v", err) + return false, fmt.Errorf("LoadHeadRepo: %w", err) } else if pr.HeadRepo == nil { // corrupt data assumed changed return true, nil } if err = pr.LoadBaseRepoCtx(ctx); err != nil { - return false, fmt.Errorf("LoadBaseRepo: %v", err) + return false, fmt.Errorf("LoadBaseRepo: %w", err) } headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath()) if err != nil { - return false, fmt.Errorf("OpenRepository: %v", err) + return false, fmt.Errorf("OpenRepository: %w", err) } defer headGitRepo.Close() // Add a temporary remote. tmpRemote := "checkIfPRContentChanged-" + fmt.Sprint(time.Now().UnixNano()) if err = headGitRepo.AddRemote(tmpRemote, pr.BaseRepo.RepoPath(), true); err != nil { - return false, fmt.Errorf("AddRemote: %s/%s-%s: %v", pr.HeadRepo.OwnerName, pr.HeadRepo.Name, tmpRemote, err) + return false, fmt.Errorf("AddRemote: %s/%s-%s: %w", pr.HeadRepo.OwnerName, pr.HeadRepo.Name, tmpRemote, err) } defer func() { if err := headGitRepo.RemoveRemote(tmpRemote); err != nil { @@ -382,7 +382,7 @@ func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest, // To synchronize repo and get a base ref _, base, err := headGitRepo.GetMergeBase(tmpRemote, pr.BaseBranch, pr.HeadBranch) if err != nil { - return false, fmt.Errorf("GetMergeBase: %v", err) + return false, fmt.Errorf("GetMergeBase: %w", err) } diffBefore := &bytes.Buffer{} @@ -394,7 +394,7 @@ func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest, } if err := headGitRepo.GetDiffFromMergeBase(base, newCommitID, diffAfter); err != nil { // New commit should be found - return false, fmt.Errorf("GetDiffFromMergeBase: %v", err) + return false, fmt.Errorf("GetDiffFromMergeBase: %w", err) } diffBeforeLines := bufio.NewScanner(diffBefore) @@ -443,10 +443,10 @@ func pushToBaseRepoHelper(ctx context.Context, pr *issues_model.PullRequest, pre baseRepoPath := pr.BaseRepo.RepoPath() if err = pr.LoadIssue(); err != nil { - return fmt.Errorf("unable to load issue %d for pr %d: %v", pr.IssueID, pr.ID, err) + return fmt.Errorf("unable to load issue %d for pr %d: %w", pr.IssueID, pr.ID, err) } if err = pr.Issue.LoadPoster(); err != nil { - return fmt.Errorf("unable to load poster %d for pr %d: %v", pr.Issue.PosterID, pr.ID, err) + return fmt.Errorf("unable to load poster %d for pr %d: %w", pr.Issue.PosterID, pr.ID, err) } gitRefName := pr.GetGitRefName() @@ -476,7 +476,7 @@ func pushToBaseRepoHelper(ctx context.Context, pr *issues_model.PullRequest, pre return err } log.Error("Unable to push PR head for %s#%d (%-v:%s) due to Error: %v", pr.BaseRepo.FullName(), pr.Index, pr.BaseRepo, gitRefName, err) - return fmt.Errorf("Push: %s:%s %s:%s %v", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), gitRefName, err) + return fmt.Errorf("Push: %s:%s %s:%s %w", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), gitRefName, err) } return nil diff --git a/services/pull/review.go b/services/pull/review.go index 8d8903c6a95..16c9e108ee7 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -120,15 +120,15 @@ var notEnoughLines = regexp.MustCompile(`exit status 128 - fatal: file .* has on func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, content, treePath string, line, reviewID int64) (*issues_model.Comment, error) { var commitID, patch string if err := issue.LoadPullRequest(); err != nil { - return nil, fmt.Errorf("GetPullRequestByIssueID: %v", err) + return nil, fmt.Errorf("GetPullRequestByIssueID: %w", err) } pr := issue.PullRequest if err := pr.LoadBaseRepoCtx(ctx); err != nil { - return nil, fmt.Errorf("LoadHeadRepo: %v", err) + return nil, fmt.Errorf("LoadHeadRepo: %w", err) } gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath()) if err != nil { - return nil, fmt.Errorf("RepositoryFromContextOrOpen: %v", err) + return nil, fmt.Errorf("RepositoryFromContextOrOpen: %w", err) } defer closer.Close() @@ -151,13 +151,13 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo invalidated = first[0].Invalidated patch = first[0].Patch } else if err != nil && !issues_model.IsErrCommentNotExist(err) { - return nil, fmt.Errorf("Find first comment for %d line %d path %s. Error: %v", reviewID, line, treePath, err) + return nil, fmt.Errorf("Find first comment for %d line %d path %s. Error: %w", reviewID, line, treePath, err) } else { review, err := issues_model.GetReviewByID(ctx, reviewID) if err == nil && len(review.CommitID) > 0 { head = review.CommitID } else if err != nil && !issues_model.IsErrReviewNotExist(err) { - return nil, fmt.Errorf("GetReviewByID %d. Error: %v", reviewID, err) + return nil, fmt.Errorf("GetReviewByID %d. Error: %w", reviewID, err) } } } @@ -170,7 +170,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo if err == nil { commitID = commit.ID.String() } else if !(strings.Contains(err.Error(), "exit status 128 - fatal: no such path") || notEnoughLines.MatchString(err.Error())) { - return nil, fmt.Errorf("LineBlame[%s, %s, %s, %d]: %v", pr.GetGitRefName(), gitRepo.Path, treePath, line, err) + return nil, fmt.Errorf("LineBlame[%s, %s, %s, %d]: %w", pr.GetGitRefName(), gitRepo.Path, treePath, line, err) } } } @@ -179,7 +179,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo if len(patch) == 0 && reviewID != 0 { headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName()) if err != nil { - return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err) + return nil, fmt.Errorf("GetRefCommitID[%s]: %w", pr.GetGitRefName(), err) } if len(commitID) == 0 { commitID = headCommitID @@ -191,7 +191,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo }() go func() { if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, headCommitID, git.RawDiffNormal, treePath, writer); err != nil { - _ = writer.CloseWithError(fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", gitRepo.Path, pr.MergeBase, headCommitID, treePath, err)) + _ = writer.CloseWithError(fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %w", gitRepo.Path, pr.MergeBase, headCommitID, treePath, err)) return } _ = writer.Close() diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go index 6624f5659b6..15e776c4b9c 100644 --- a/services/pull/temp_repo.go +++ b/services/pull/temp_repo.go @@ -25,7 +25,7 @@ import ( func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (string, error) { if err := pr.LoadHeadRepoCtx(ctx); err != nil { log.Error("LoadHeadRepo: %v", err) - return "", fmt.Errorf("LoadHeadRepo: %v", err) + return "", fmt.Errorf("LoadHeadRepo: %w", err) } else if pr.HeadRepo == nil { log.Error("Pr %d HeadRepo %d does not exist", pr.ID, pr.HeadRepoID) return "", &repo_model.ErrRepoNotExist{ @@ -33,7 +33,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str } } else if err := pr.LoadBaseRepoCtx(ctx); err != nil { log.Error("LoadBaseRepo: %v", err) - return "", fmt.Errorf("LoadBaseRepo: %v", err) + return "", fmt.Errorf("LoadBaseRepo: %w", err) } else if pr.BaseRepo == nil { log.Error("Pr %d BaseRepo %d does not exist", pr.ID, pr.BaseRepoID) return "", &repo_model.ErrRepoNotExist{ @@ -41,10 +41,10 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str } } else if err := pr.HeadRepo.GetOwner(ctx); err != nil { log.Error("HeadRepo.GetOwner: %v", err) - return "", fmt.Errorf("HeadRepo.GetOwner: %v", err) + return "", fmt.Errorf("HeadRepo.GetOwner: %w", err) } else if err := pr.BaseRepo.GetOwner(ctx); err != nil { log.Error("BaseRepo.GetOwner: %v", err) - return "", fmt.Errorf("BaseRepo.GetOwner: %v", err) + return "", fmt.Errorf("BaseRepo.GetOwner: %w", err) } // Clone base repo. @@ -90,7 +90,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil { log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err) } - return "", fmt.Errorf("Unable to add base repository to temporary repo [%s -> tmpBasePath]: %v", pr.BaseRepo.FullName(), err) + return "", fmt.Errorf("Unable to add base repository to temporary repo [%s -> tmpBasePath]: %w", pr.BaseRepo.FullName(), err) } var outbuf, errbuf strings.Builder @@ -104,7 +104,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil { log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err) } - return "", fmt.Errorf("Unable to add base repository as origin [%s -> tmpBasePath]: %v\n%s\n%s", pr.BaseRepo.FullName(), err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("Unable to add base repository as origin [%s -> tmpBasePath]: %w\n%s\n%s", pr.BaseRepo.FullName(), err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -119,7 +119,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil { log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err) } - return "", fmt.Errorf("Unable to fetch origin base branch [%s:%s -> base, original_base in tmpBasePath]: %v\n%s\n%s", pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("Unable to fetch origin base branch [%s:%s -> base, original_base in tmpBasePath]: %w\n%s\n%s", pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -134,7 +134,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil { log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err) } - return "", fmt.Errorf("Unable to set HEAD as base branch [tmpBasePath]: %v\n%s\n%s", err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("Unable to set HEAD as base branch [tmpBasePath]: %w\n%s\n%s", err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -144,7 +144,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil { log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err) } - return "", fmt.Errorf("Unable to head base repository to temporary repo [%s -> tmpBasePath]: %v", pr.HeadRepo.FullName(), err) + return "", fmt.Errorf("Unable to head base repository to temporary repo [%s -> tmpBasePath]: %w", pr.HeadRepo.FullName(), err) } if err := git.NewCommand(ctx, "remote", "add").AddDynamicArguments(remoteRepoName, headRepoPath). @@ -157,7 +157,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil { log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err) } - return "", fmt.Errorf("Unable to add head repository as head_repo [%s -> tmpBasePath]: %v\n%s\n%s", pr.HeadRepo.FullName(), err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("Unable to add head repository as head_repo [%s -> tmpBasePath]: %w\n%s\n%s", pr.HeadRepo.FullName(), err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() @@ -187,7 +187,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str } } log.Error("Unable to fetch head_repo head branch [%s:%s -> tracking in %s]: %v:\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, tmpBasePath, err, outbuf.String(), errbuf.String()) - return "", fmt.Errorf("Unable to fetch head_repo head branch [%s:%s -> tracking in tmpBasePath]: %v\n%s\n%s", pr.HeadRepo.FullName(), headBranch, err, outbuf.String(), errbuf.String()) + return "", fmt.Errorf("Unable to fetch head_repo head branch [%s:%s -> tracking in tmpBasePath]: %w\n%s\n%s", pr.HeadRepo.FullName(), headBranch, err, outbuf.String(), errbuf.String()) } outbuf.Reset() errbuf.Reset() diff --git a/services/pull/update.go b/services/pull/update.go index 49258a9862d..bd4880a2fc7 100644 --- a/services/pull/update.go +++ b/services/pull/update.go @@ -50,10 +50,10 @@ func Update(ctx context.Context, pull *issues_model.PullRequest, doer *user_mode if err := pr.LoadHeadRepoCtx(ctx); err != nil { log.Error("LoadHeadRepo: %v", err) - return fmt.Errorf("LoadHeadRepo: %v", err) + return fmt.Errorf("LoadHeadRepo: %w", err) } else if err = pr.LoadBaseRepoCtx(ctx); err != nil { log.Error("LoadBaseRepo: %v", err) - return fmt.Errorf("LoadBaseRepo: %v", err) + return fmt.Errorf("LoadBaseRepo: %w", err) } diffCount, err := GetDiverging(ctx, pull) diff --git a/services/release/release.go b/services/release/release.go index 25b89e1a0b6..346c2abd421 100644 --- a/services/release/release.go +++ b/services/release/release.go @@ -36,7 +36,7 @@ func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bo protectedTags, err := git_model.GetProtectedTags(rel.Repo.ID) if err != nil { - return false, fmt.Errorf("GetProtectedTags: %v", err) + return false, fmt.Errorf("GetProtectedTags: %w", err) } // Trim '--' prefix to prevent command line argument vulnerability. @@ -53,7 +53,7 @@ func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bo commit, err := gitRepo.GetCommit(rel.Target) if err != nil { - return false, fmt.Errorf("createTag::GetCommit[%v]: %v", rel.Target, err) + return false, fmt.Errorf("createTag::GetCommit[%v]: %w", rel.Target, err) } if len(msg) > 0 { @@ -92,13 +92,13 @@ func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bo } commit, err := gitRepo.GetTagCommit(rel.TagName) if err != nil { - return false, fmt.Errorf("GetTagCommit: %v", err) + return false, fmt.Errorf("GetTagCommit: %w", err) } rel.Sha1 = commit.ID.String() rel.NumCommits, err = commit.CommitsCount() if err != nil { - return false, fmt.Errorf("CommitsCount: %v", err) + return false, fmt.Errorf("CommitsCount: %w", err) } if rel.PublisherID <= 0 { @@ -207,7 +207,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod } if err = repo_model.AddReleaseAttachments(ctx, rel.ID, addAttachmentUUIDs); err != nil { - return fmt.Errorf("AddReleaseAttachments: %v", err) + return fmt.Errorf("AddReleaseAttachments: %w", err) } deletedUUIDs := make(container.Set[string]) @@ -215,7 +215,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod // Check attachments attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, delAttachmentUUIDs) if err != nil { - return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", delAttachmentUUIDs, err) + return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %w", delAttachmentUUIDs, err) } for _, attach := range attachments { if attach.ReleaseID != rel.ID { @@ -225,7 +225,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod } if _, err := repo_model.DeleteAttachments(ctx, attachments, false); err != nil { - return fmt.Errorf("DeleteAttachments [uuids: %v]: %v", delAttachmentUUIDs, err) + return fmt.Errorf("DeleteAttachments [uuids: %v]: %w", delAttachmentUUIDs, err) } } @@ -237,7 +237,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod // Check attachments attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, updateAttachmentsList) if err != nil { - return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", updateAttachmentsList, err) + return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %w", updateAttachmentsList, err) } for _, attach := range attachments { if attach.ReleaseID != rel.ID { @@ -286,18 +286,18 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, delTag bool) error { rel, err := repo_model.GetReleaseByID(ctx, id) if err != nil { - return fmt.Errorf("GetReleaseByID: %v", err) + return fmt.Errorf("GetReleaseByID: %w", err) } repo, err := repo_model.GetRepositoryByIDCtx(ctx, rel.RepoID) if err != nil { - return fmt.Errorf("GetRepositoryByID: %v", err) + return fmt.Errorf("GetRepositoryByID: %w", err) } if delTag { protectedTags, err := git_model.GetProtectedTags(rel.RepoID) if err != nil { - return fmt.Errorf("GetProtectedTags: %v", err) + return fmt.Errorf("GetProtectedTags: %w", err) } isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, rel.TagName, rel.PublisherID) if err != nil { @@ -313,7 +313,7 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del SetDescription(fmt.Sprintf("DeleteReleaseByID (git tag -d): %d", rel.ID)). RunStdString(&git.RunOpts{Dir: repo.RepoPath()}); err != nil && !strings.Contains(err.Error(), "not found") { log.Error("DeleteReleaseByID (git tag -d): %d in %v Failed:\nStdout: %s\nError: %v", rel.ID, repo, stdout, err) - return fmt.Errorf("git tag -d: %v", err) + return fmt.Errorf("git tag -d: %w", err) } notification.NotifyPushCommits( @@ -326,23 +326,23 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del notification.NotifyDeleteRef(doer, repo, "tag", git.TagPrefix+rel.TagName) if err := repo_model.DeleteReleaseByID(id); err != nil { - return fmt.Errorf("DeleteReleaseByID: %v", err) + return fmt.Errorf("DeleteReleaseByID: %w", err) } } else { rel.IsTag = true if err = repo_model.UpdateRelease(ctx, rel); err != nil { - return fmt.Errorf("Update: %v", err) + return fmt.Errorf("Update: %w", err) } } rel.Repo = repo if err = rel.LoadAttributes(); err != nil { - return fmt.Errorf("LoadAttributes: %v", err) + return fmt.Errorf("LoadAttributes: %w", err) } if err := repo_model.DeleteAttachmentsByRelease(rel.ID); err != nil { - return fmt.Errorf("DeleteAttachments: %v", err) + return fmt.Errorf("DeleteAttachments: %w", err) } for i := range rel.Attachments { diff --git a/services/repository/adopt.go b/services/repository/adopt.go index 9e04c159776..3b986c66c61 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 ae43503bae1..79537ea0516 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 b9bd36ab665..b80a8fb7758 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 6c9a5d76caf..13284225829 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 1b2da4cc082..5529a61b396 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 0107d99e665..a30d4f6025e 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 ecd981b5ffd..bc5a4c8ed3a 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 781a762d0ff..f098052ad8a 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 437890c488c..2be01f25be5 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 9513f2341e1..b96d9e7b3df 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 87c622a9be3..1721b00b01e 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 b2dadb6497c..37287809910 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 af0ade99a94..136d7ccab65 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 45a031f38e6..d326cd26b16 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 d645928c43b..3a7205d18b6 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 47687d9a739..763ef74927c 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() diff --git a/services/task/migrate.go b/services/task/migrate.go index 775cbf61281..faca6908a27 100644 --- a/services/task/migrate.go +++ b/services/task/migrate.go @@ -133,9 +133,9 @@ func runMigrateTask(t *admin_model.Task) (err error) { err = util.SanitizeErrorCredentialURLs(err) if strings.Contains(err.Error(), "Authentication failed") || strings.Contains(err.Error(), "could not read Username") { - return fmt.Errorf("Authentication failed: %v", err.Error()) + return fmt.Errorf("Authentication failed: %w", err) } else if strings.Contains(err.Error(), "fatal:") { - return fmt.Errorf("Migration failed: %v", err.Error()) + return fmt.Errorf("Migration failed: %w", err) } // do not be tempted to coalesce this line with the return diff --git a/services/user/user.go b/services/user/user.go index dab9ac61a46..c8b497a5c46 100644 --- a/services/user/user.go +++ b/services/user/user.go @@ -78,14 +78,14 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error { Actor: u, }) if err != nil { - return fmt.Errorf("SearchRepositoryByName: %v", err) + return fmt.Errorf("SearchRepositoryByName: %w", err) } if len(repos) == 0 { break } for _, repo := range repos { if err := models.DeleteRepository(u, u.ID, repo.ID); err != nil { - return fmt.Errorf("unable to delete repository %s for %s[%d]. Error: %v", repo.Name, u.Name, u.ID, err) + return fmt.Errorf("unable to delete repository %s for %s[%d]. Error: %w", repo.Name, u.Name, u.ID, err) } } } @@ -107,7 +107,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error { IncludePrivate: true, }) if err != nil { - return fmt.Errorf("unable to find org list for %s[%d]. Error: %v", u.Name, u.ID, err) + return fmt.Errorf("unable to find org list for %s[%d]. Error: %w", u.Name, u.ID, err) } if len(orgs) == 0 { break @@ -118,7 +118,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error { err = organization.DeleteOrganization(ctx, org) } if err != nil { - return fmt.Errorf("unable to remove user %s[%d] from org %s[%d]. Error: %v", u.Name, u.ID, org.Name, org.ID, err) + return fmt.Errorf("unable to remove user %s[%d] from org %s[%d]. Error: %w", u.Name, u.ID, org.Name, org.ID, err) } } } @@ -145,7 +145,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error { // Check ownership of repository. count, err := repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{OwnerID: u.ID}) if err != nil { - return fmt.Errorf("GetRepositoryCount: %v", err) + return fmt.Errorf("GetRepositoryCount: %w", err) } else if count > 0 { return models.ErrUserOwnRepos{UID: u.ID} } @@ -153,20 +153,20 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error { // Check membership of organization. count, err = organization.GetOrganizationCount(ctx, u) if err != nil { - return fmt.Errorf("GetOrganizationCount: %v", err) + return fmt.Errorf("GetOrganizationCount: %w", err) } else if count > 0 { return models.ErrUserHasOrgs{UID: u.ID} } // Check ownership of packages. if ownsPackages, err := packages_model.HasOwnerPackages(ctx, u.ID); err != nil { - return fmt.Errorf("HasOwnerPackages: %v", err) + return fmt.Errorf("HasOwnerPackages: %w", err) } else if ownsPackages { return models.ErrUserOwnPackages{UID: u.ID} } if err := models.DeleteUser(ctx, u, purge); err != nil { - return fmt.Errorf("DeleteUser: %v", err) + return fmt.Errorf("DeleteUser: %w", err) } if err := committer.Commit(); err != nil { @@ -185,7 +185,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error { // so just keep error logs of those operations. path := user_model.UserPath(u.Name) if err := util.RemoveAll(path); err != nil { - err = fmt.Errorf("Failed to RemoveAll %s: %v", path, err) + err = fmt.Errorf("Failed to RemoveAll %s: %w", path, err) _ = system_model.CreateNotice(ctx, system_model.NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err)) return err } @@ -193,7 +193,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error { if u.Avatar != "" { avatarPath := u.CustomAvatarRelativePath() if err := storage.Avatars.Delete(avatarPath); err != nil { - err = fmt.Errorf("Failed to remove %s: %v", avatarPath, err) + err = fmt.Errorf("Failed to remove %s: %w", avatarPath, err) _ = system_model.CreateNotice(ctx, system_model.NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err)) return err } @@ -248,7 +248,7 @@ func UploadAvatar(u *user_model.User, data []byte) error { // Other users will lose their avatars too. u.Avatar = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data))))) if err = user_model.UpdateUserCols(ctx, u, "use_custom_avatar", "avatar"); err != nil { - return fmt.Errorf("updateUser: %v", err) + return fmt.Errorf("updateUser: %w", err) } if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error { @@ -257,7 +257,7 @@ func UploadAvatar(u *user_model.User, data []byte) error { } return err }); err != nil { - return fmt.Errorf("Failed to create dir %s: %v", u.CustomAvatarRelativePath(), err) + return fmt.Errorf("Failed to create dir %s: %w", u.CustomAvatarRelativePath(), err) } return committer.Commit() @@ -269,14 +269,14 @@ func DeleteAvatar(u *user_model.User) error { log.Trace("DeleteAvatar[%d]: %s", u.ID, aPath) if len(u.Avatar) > 0 { if err := storage.Avatars.Delete(aPath); err != nil { - return fmt.Errorf("Failed to remove %s: %v", aPath, err) + return fmt.Errorf("Failed to remove %s: %w", aPath, err) } } u.UseCustomAvatar = false u.Avatar = "" if _, err := db.GetEngine(db.DefaultContext).ID(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil { - return fmt.Errorf("UpdateUser: %v", err) + return fmt.Errorf("UpdateUser: %w", err) } return nil } diff --git a/services/webhook/webhook.go b/services/webhook/webhook.go index e877e16edaa..342e764f4da 100644 --- a/services/webhook/webhook.go +++ b/services/webhook/webhook.go @@ -190,7 +190,7 @@ func PrepareWebhook(ctx context.Context, w *webhook_model.Webhook, event webhook if ok { payloader, err = webhook.payloadCreator(p, event, w.Meta) if err != nil { - return fmt.Errorf("create payload for %s[%s]: %v", w.Type, event, err) + return fmt.Errorf("create payload for %s[%s]: %w", w.Type, event, err) } } else { payloader = p @@ -202,7 +202,7 @@ func PrepareWebhook(ctx context.Context, w *webhook_model.Webhook, event webhook EventType: event, }) if err != nil { - return fmt.Errorf("CreateHookTask: %v", err) + return fmt.Errorf("CreateHookTask: %w", err) } return enqueueHookTask(task) @@ -220,7 +220,7 @@ func PrepareWebhooks(ctx context.Context, source EventSource, event webhook_mode IsActive: util.OptionalBoolTrue, }) if err != nil { - return fmt.Errorf("ListWebhooksByOpts: %v", err) + return fmt.Errorf("ListWebhooksByOpts: %w", err) } ws = append(ws, repoHooks...) @@ -234,7 +234,7 @@ func PrepareWebhooks(ctx context.Context, source EventSource, event webhook_mode IsActive: util.OptionalBoolTrue, }) if err != nil { - return fmt.Errorf("ListWebhooksByOpts: %v", err) + return fmt.Errorf("ListWebhooksByOpts: %w", err) } ws = append(ws, orgHooks...) } @@ -242,7 +242,7 @@ func PrepareWebhooks(ctx context.Context, source EventSource, event webhook_mode // Add any admin-defined system webhooks systemHooks, err := webhook_model.GetSystemWebhooks(ctx, util.OptionalBoolTrue) if err != nil { - return fmt.Errorf("GetSystemWebhooks: %v", err) + return fmt.Errorf("GetSystemWebhooks: %w", err) } ws = append(ws, systemHooks...) diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go index 8faada4d59a..f6986cff860 100644 --- a/services/wiki/wiki.go +++ b/services/wiki/wiki.go @@ -83,11 +83,11 @@ func InitWiki(ctx context.Context, repo *repo_model.Repository) error { } if err := git.InitRepository(ctx, repo.WikiPath(), true); err != nil { - return fmt.Errorf("InitRepository: %v", err) + return fmt.Errorf("InitRepository: %w", err) } else if err = repo_module.CreateDelegateHooks(repo.WikiPath()); err != nil { - return fmt.Errorf("createDelegateHooks: %v", err) + return fmt.Errorf("createDelegateHooks: %w", err) } else if _, _, err = git.NewCommand(ctx, "symbolic-ref", "HEAD", git.BranchPrefix+DefaultBranch).RunStdString(&git.RunOpts{Dir: repo.WikiPath()}); err != nil { - return fmt.Errorf("unable to set default wiki branch to master: %v", err) + return fmt.Errorf("unable to set default wiki branch to master: %w", err) } return nil } @@ -132,7 +132,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model defer wikiWorkingPool.CheckOut(fmt.Sprint(repo.ID)) if err = InitWiki(ctx, repo); err != nil { - return fmt.Errorf("InitWiki: %v", err) + return fmt.Errorf("InitWiki: %w", err) } hasMasterBranch := git.IsBranchExist(ctx, repo.WikiPath(), DefaultBranch) @@ -158,20 +158,20 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model if err := git.Clone(ctx, repo.WikiPath(), basePath, cloneOpts); err != nil { log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err) - return fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err) + return fmt.Errorf("Failed to clone repository: %s (%w)", repo.FullName(), err) } gitRepo, err := git.OpenRepository(ctx, basePath) if err != nil { log.Error("Unable to open temporary repository: %s (%v)", basePath, err) - return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err) + return fmt.Errorf("Failed to open new temporary repository in: %s %w", basePath, err) } defer gitRepo.Close() if hasMasterBranch { if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil { log.Error("Unable to read HEAD tree to index in: %s %v", basePath, err) - return fmt.Errorf("Unable to read HEAD tree to index in: %s %v", basePath, err) + return fmt.Errorf("Unable to read HEAD tree to index in: %s %w", basePath, err) } } @@ -265,7 +265,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) { return err } - return fmt.Errorf("Push: %v", err) + return fmt.Errorf("Push: %w", err) } return nil @@ -288,7 +288,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model defer wikiWorkingPool.CheckOut(fmt.Sprint(repo.ID)) if err = InitWiki(ctx, repo); err != nil { - return fmt.Errorf("InitWiki: %v", err) + return fmt.Errorf("InitWiki: %w", err) } basePath, err := repo_module.CreateTemporaryPath("update-wiki") @@ -307,19 +307,19 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model Branch: DefaultBranch, }); err != nil { log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err) - return fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err) + return fmt.Errorf("Failed to clone repository: %s (%w)", repo.FullName(), err) } gitRepo, err := git.OpenRepository(ctx, basePath) if err != nil { log.Error("Unable to open temporary repository: %s (%v)", basePath, err) - return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err) + return fmt.Errorf("Failed to open new temporary repository in: %s %w", basePath, err) } defer gitRepo.Close() if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil { log.Error("Unable to read HEAD tree to index in: %s %v", basePath, err) - return fmt.Errorf("Unable to read HEAD tree to index in: %s %v", basePath, err) + return fmt.Errorf("Unable to read HEAD tree to index in: %s %w", basePath, err) } found, wikiPath, err := prepareWikiFileName(gitRepo, wikiName) @@ -372,7 +372,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model 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/tests/integration/gpg_git_test.go b/tests/integration/gpg_git_test.go index 80f484926d3..4dcf6276c27 100644 --- a/tests/integration/gpg_git_test.go +++ b/tests/integration/gpg_git_test.go @@ -358,7 +358,7 @@ func importTestingKey(tmpDir, name, email string) (*openpgp.Entity, error) { keyring, err := openpgp.ReadKeyRing(block.Body) if err != nil { - return nil, fmt.Errorf("Keyring access failed: '%v'", err) + return nil, fmt.Errorf("Keyring access failed: '%w'", err) } // There should only be one entity in this file.