mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 12:17:53 +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
This commit is contained in:
parent
f95622cddc
commit
9de443ced2
@ -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()
|
||||||
|
@ -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()
|
||||||
|
@ -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()
|
||||||
|
@ -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()
|
||||||
|
@ -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
|
||||||
|
@ -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 := "."
|
||||||
|
@ -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")
|
||||||
|
@ -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"
|
||||||
@ -294,7 +295,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 {
|
||||||
|
@ -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 {
|
||||||
|
@ -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"
|
||||||
@ -147,7 +148,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{}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user