Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-24 02:36:10 +01:00

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

(cherry picked from commit 9de443ced2c328d9b58a5e144a765f402aab859d)
This commit is contained in:
Cheng 2024-04-22 03:44:03 +08:00 committed by Earl Warren
parent de9d498109
commit 2ec0c5e284
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
10 changed files with 21 additions and 15 deletions

View file

@ -4,6 +4,7 @@
package cmd package cmd
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"text/tabwriter" "text/tabwriter"
@ -91,7 +92,7 @@ func runListAuth(c *cli.Context) error {
func runDeleteAuth(c *cli.Context) error { func runDeleteAuth(c *cli.Context) error {
if !c.IsSet("id") { if !c.IsSet("id") {
return fmt.Errorf("--id flag is missing") return errors.New("--id flag is missing")
} }
ctx, cancel := installSignals() ctx, cancel := installSignals()

View file

@ -4,6 +4,7 @@
package cmd package cmd
import ( import (
"errors"
"fmt" "fmt"
"net/url" "net/url"
@ -193,7 +194,7 @@ func runAddOauth(c *cli.Context) error {
func runUpdateOauth(c *cli.Context) error { func runUpdateOauth(c *cli.Context) error {
if !c.IsSet("id") { if !c.IsSet("id") {
return fmt.Errorf("--id flag is missing") return errors.New("--id flag is missing")
} }
ctx, cancel := installSignals() ctx, cancel := installSignals()

View file

@ -5,7 +5,6 @@ package cmd
import ( import (
"errors" "errors"
"fmt"
"strings" "strings"
auth_model "code.gitea.io/gitea/models/auth" auth_model "code.gitea.io/gitea/models/auth"
@ -166,7 +165,7 @@ func runAddSMTP(c *cli.Context) error {
func runUpdateSMTP(c *cli.Context) error { func runUpdateSMTP(c *cli.Context) error {
if !c.IsSet("id") { if !c.IsSet("id") {
return fmt.Errorf("--id flag is missing") return errors.New("--id flag is missing")
} }
ctx, cancel := installSignals() ctx, cancel := installSignals()

View file

@ -4,6 +4,7 @@
package cmd package cmd
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
@ -42,7 +43,7 @@ var microcmdUserDelete = &cli.Command{
func runDeleteUser(c *cli.Context) error { func runDeleteUser(c *cli.Context) error {
if !c.IsSet("id") && !c.IsSet("username") && !c.IsSet("email") { 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() ctx, cancel := installSignals()

View file

@ -4,6 +4,7 @@
package cmd package cmd
import ( import (
"errors"
"fmt" "fmt"
auth_model "code.gitea.io/gitea/models/auth" auth_model "code.gitea.io/gitea/models/auth"
@ -42,7 +43,7 @@ var microcmdUserGenerateAccessToken = &cli.Command{
func runGenerateAccessToken(c *cli.Context) error { func runGenerateAccessToken(c *cli.Context) error {
if !c.IsSet("username") { 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() ctx, cancel := installSignals()
@ -68,7 +69,7 @@ func runGenerateAccessToken(c *cli.Context) error {
return err return err
} }
if exist { 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 // make sure the scopes are valid

View file

@ -157,9 +157,9 @@ func runViewDo(c *cli.Context) error {
} }
if len(matchedAssetFiles) == 0 { 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 { } 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) data, err := matchedAssetFiles[0].fs.ReadFile(matchedAssetFiles[0].name)
@ -180,7 +180,7 @@ func runExtractDo(c *cli.Context) error {
} }
if c.NArg() == 0 { 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 := "." destdir := "."

View file

@ -4,6 +4,7 @@
package cmd package cmd
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
@ -249,7 +250,7 @@ func runAddFileLogger(c *cli.Context) error {
if c.IsSet("filename") { if c.IsSet("filename") {
vals["filename"] = c.String("filename") vals["filename"] = c.String("filename")
} else { } 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") { if c.IsSet("rotate") {
vals["rotate"] = c.Bool("rotate") vals["rotate"] = c.Bool("rotate")

View file

@ -8,6 +8,7 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/base32" "encoding/base32"
"encoding/base64" "encoding/base64"
"errors"
"fmt" "fmt"
"net" "net"
"net/url" "net/url"
@ -301,7 +302,7 @@ func UpdateOAuth2Application(ctx context.Context, opts UpdateOAuth2ApplicationOp
return nil, err return nil, err
} }
if app.UID != opts.UserID { if app.UID != opts.UserID {
return nil, fmt.Errorf("UID mismatch") return nil, errors.New("UID mismatch")
} }
builtinApps := BuiltinApplications() builtinApps := BuiltinApplications()
if _, builtin := builtinApps[app.ClientID]; builtin { if _, builtin := builtinApps[app.ClientID]; builtin {

View file

@ -5,7 +5,7 @@ package git
import ( import (
"context" "context"
"fmt" "errors"
"strings" "strings"
"time" "time"
@ -148,7 +148,7 @@ func DeleteLFSLockByID(ctx context.Context, id int64, repo *repo_model.Repositor
} }
if !force && u.ID != lock.OwnerID { 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 { if _, err := db.GetEngine(dbCtx).ID(id).Delete(new(LFSLock)); err != nil {

View file

@ -5,6 +5,7 @@ package models
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
@ -120,7 +121,7 @@ func DeleteRepositoryTransfer(ctx context.Context, repoID int64) error {
func TestRepositoryReadyForTransfer(status repo_model.RepositoryStatus) error { func TestRepositoryReadyForTransfer(status repo_model.RepositoryStatus) error {
switch status { switch status {
case repo_model.RepositoryBeingMigrated: 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: case repo_model.RepositoryPendingTransfer:
return ErrRepoTransferInProgress{} return ErrRepoTransferInProgress{}
} }