Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use errors.New to replace fmt.Errorf with no parameters will much better #30621

Merged
merged 2 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/admin_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cmd

import (
"errors"
"fmt"
"os"
"text/tabwriter"
Expand Down Expand Up @@ -91,7 +92,7 @@ func runListAuth(c *cli.Context) error {

func runDeleteAuth(c *cli.Context) error {
if !c.IsSet("id") {
return fmt.Errorf("--id flag is missing")
return errors.New("--id flag is missing")
}

ctx, cancel := installSignals()
Expand Down
3 changes: 2 additions & 1 deletion cmd/admin_auth_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cmd

import (
"errors"
"fmt"
"net/url"

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

func runUpdateOauth(c *cli.Context) error {
if !c.IsSet("id") {
return fmt.Errorf("--id flag is missing")
return errors.New("--id flag is missing")
}

ctx, cancel := installSignals()
Expand Down
3 changes: 1 addition & 2 deletions cmd/admin_auth_stmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

import (
"errors"
"fmt"
"strings"

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

func runUpdateSMTP(c *cli.Context) error {
if !c.IsSet("id") {
return fmt.Errorf("--id flag is missing")
return errors.New("--id flag is missing")
}

ctx, cancel := installSignals()
Expand Down
3 changes: 2 additions & 1 deletion cmd/admin_user_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cmd

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -42,7 +43,7 @@ var microcmdUserDelete = &cli.Command{

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

ctx, cancel := installSignals()
Expand Down
5 changes: 3 additions & 2 deletions cmd/admin_user_generate_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cmd

import (
"errors"
"fmt"

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

func runGenerateAccessToken(c *cli.Context) error {
if !c.IsSet("username") {
return fmt.Errorf("You must provide a username to generate a token for")
return errors.New("You must provide a username to generate a token for")
}

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

// make sure the scopes are valid
Expand Down
6 changes: 3 additions & 3 deletions cmd/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ func runViewDo(c *cli.Context) error {
}

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

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

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

destdir := "."
Expand Down
3 changes: 2 additions & 1 deletion cmd/manager_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cmd

import (
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -249,7 +250,7 @@ func runAddFileLogger(c *cli.Context) error {
if c.IsSet("filename") {
vals["filename"] = c.String("filename")
} else {
return fmt.Errorf("filename must be set when creating a file logger")
return errors.New("filename must be set when creating a file logger")
}
if c.IsSet("rotate") {
vals["rotate"] = c.Bool("rotate")
Expand Down
3 changes: 2 additions & 1 deletion models/auth/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"crypto/sha256"
"encoding/base32"
"encoding/base64"
"errors"
"fmt"
"net"
"net/url"
Expand Down Expand Up @@ -294,7 +295,7 @@ func UpdateOAuth2Application(ctx context.Context, opts UpdateOAuth2ApplicationOp
return nil, err
}
if app.UID != opts.UserID {
return nil, fmt.Errorf("UID mismatch")
return nil, errors.New("UID mismatch")
}
builtinApps := BuiltinApplications()
if _, builtin := builtinApps[app.ClientID]; builtin {
Expand Down
4 changes: 2 additions & 2 deletions models/git/lfs_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package git

import (
"context"
"fmt"
"errors"
"strings"
"time"

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

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

if _, err := db.GetEngine(dbCtx).ID(id).Delete(new(LFSLock)); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion models/repo_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package models

import (
"context"
"errors"
"fmt"

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