Skip to content

Commit 9de443c

Browse files
authored
chore: use errors.New to replace fmt.Errorf with no parameters will much better (#30621)
use errors.New to replace fmt.Errorf with no parameters will much better
1 parent f95622c commit 9de443c

10 files changed

+21
-15
lines changed

cmd/admin_auth.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"errors"
78
"fmt"
89
"os"
910
"text/tabwriter"
@@ -91,7 +92,7 @@ func runListAuth(c *cli.Context) error {
9192

9293
func runDeleteAuth(c *cli.Context) error {
9394
if !c.IsSet("id") {
94-
return fmt.Errorf("--id flag is missing")
95+
return errors.New("--id flag is missing")
9596
}
9697

9798
ctx, cancel := installSignals()

cmd/admin_auth_oauth.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"errors"
78
"fmt"
89
"net/url"
910

@@ -193,7 +194,7 @@ func runAddOauth(c *cli.Context) error {
193194

194195
func runUpdateOauth(c *cli.Context) error {
195196
if !c.IsSet("id") {
196-
return fmt.Errorf("--id flag is missing")
197+
return errors.New("--id flag is missing")
197198
}
198199

199200
ctx, cancel := installSignals()

cmd/admin_auth_stmp.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package cmd
55

66
import (
77
"errors"
8-
"fmt"
98
"strings"
109

1110
auth_model "code.gitea.io/gitea/models/auth"
@@ -166,7 +165,7 @@ func runAddSMTP(c *cli.Context) error {
166165

167166
func runUpdateSMTP(c *cli.Context) error {
168167
if !c.IsSet("id") {
169-
return fmt.Errorf("--id flag is missing")
168+
return errors.New("--id flag is missing")
170169
}
171170

172171
ctx, cancel := installSignals()

cmd/admin_user_delete.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"errors"
78
"fmt"
89
"strings"
910

@@ -42,7 +43,7 @@ var microcmdUserDelete = &cli.Command{
4243

4344
func runDeleteUser(c *cli.Context) error {
4445
if !c.IsSet("id") && !c.IsSet("username") && !c.IsSet("email") {
45-
return fmt.Errorf("You must provide the id, username or email of a user to delete")
46+
return errors.New("You must provide the id, username or email of a user to delete")
4647
}
4748

4849
ctx, cancel := installSignals()

cmd/admin_user_generate_access_token.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"errors"
78
"fmt"
89

910
auth_model "code.gitea.io/gitea/models/auth"
@@ -42,7 +43,7 @@ var microcmdUserGenerateAccessToken = &cli.Command{
4243

4344
func runGenerateAccessToken(c *cli.Context) error {
4445
if !c.IsSet("username") {
45-
return fmt.Errorf("You must provide a username to generate a token for")
46+
return errors.New("You must provide a username to generate a token for")
4647
}
4748

4849
ctx, cancel := installSignals()
@@ -68,7 +69,7 @@ func runGenerateAccessToken(c *cli.Context) error {
6869
return err
6970
}
7071
if exist {
71-
return fmt.Errorf("access token name has been used already")
72+
return errors.New("access token name has been used already")
7273
}
7374

7475
// make sure the scopes are valid

cmd/embedded.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ func runViewDo(c *cli.Context) error {
157157
}
158158

159159
if len(matchedAssetFiles) == 0 {
160-
return fmt.Errorf("no files matched the given pattern")
160+
return errors.New("no files matched the given pattern")
161161
} else if len(matchedAssetFiles) > 1 {
162-
return fmt.Errorf("too many files matched the given pattern, try to be more specific")
162+
return errors.New("too many files matched the given pattern, try to be more specific")
163163
}
164164

165165
data, err := matchedAssetFiles[0].fs.ReadFile(matchedAssetFiles[0].name)
@@ -180,7 +180,7 @@ func runExtractDo(c *cli.Context) error {
180180
}
181181

182182
if c.NArg() == 0 {
183-
return fmt.Errorf("a list of pattern of files to extract is mandatory (e.g. '**' for all)")
183+
return errors.New("a list of pattern of files to extract is mandatory (e.g. '**' for all)")
184184
}
185185

186186
destdir := "."

cmd/manager_logging.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"errors"
78
"fmt"
89
"os"
910

@@ -249,7 +250,7 @@ func runAddFileLogger(c *cli.Context) error {
249250
if c.IsSet("filename") {
250251
vals["filename"] = c.String("filename")
251252
} else {
252-
return fmt.Errorf("filename must be set when creating a file logger")
253+
return errors.New("filename must be set when creating a file logger")
253254
}
254255
if c.IsSet("rotate") {
255256
vals["rotate"] = c.Bool("rotate")

models/auth/oauth2.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"crypto/sha256"
99
"encoding/base32"
1010
"encoding/base64"
11+
"errors"
1112
"fmt"
1213
"net"
1314
"net/url"
@@ -294,7 +295,7 @@ func UpdateOAuth2Application(ctx context.Context, opts UpdateOAuth2ApplicationOp
294295
return nil, err
295296
}
296297
if app.UID != opts.UserID {
297-
return nil, fmt.Errorf("UID mismatch")
298+
return nil, errors.New("UID mismatch")
298299
}
299300
builtinApps := BuiltinApplications()
300301
if _, builtin := builtinApps[app.ClientID]; builtin {

models/git/lfs_lock.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package git
55

66
import (
77
"context"
8-
"fmt"
8+
"errors"
99
"strings"
1010
"time"
1111

@@ -148,7 +148,7 @@ func DeleteLFSLockByID(ctx context.Context, id int64, repo *repo_model.Repositor
148148
}
149149

150150
if !force && u.ID != lock.OwnerID {
151-
return nil, fmt.Errorf("user doesn't own lock and force flag is not set")
151+
return nil, errors.New("user doesn't own lock and force flag is not set")
152152
}
153153

154154
if _, err := db.GetEngine(dbCtx).ID(id).Delete(new(LFSLock)); err != nil {

models/repo_transfer.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package models
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910

1011
"code.gitea.io/gitea/models/db"
@@ -147,7 +148,7 @@ func DeleteRepositoryTransfer(ctx context.Context, repoID int64) error {
147148
func TestRepositoryReadyForTransfer(status repo_model.RepositoryStatus) error {
148149
switch status {
149150
case repo_model.RepositoryBeingMigrated:
150-
return fmt.Errorf("repo is not ready, currently migrating")
151+
return errors.New("repo is not ready, currently migrating")
151152
case repo_model.RepositoryPendingTransfer:
152153
return ErrRepoTransferInProgress{}
153154
}

0 commit comments

Comments
 (0)