From ea48373cade3438c44f0d9ef177dd744857c0669 Mon Sep 17 00:00:00 2001 From: RiceChuan Date: Thu, 12 Dec 2024 12:07:06 +0800 Subject: [PATCH] chore: use errors.New to replace fmt.Errorf with no parameters Signed-off-by: RiceChuan --- cmd/devp2p/discv4cmd.go | 5 +++-- cmd/devp2p/discv5cmd.go | 3 ++- cmd/devp2p/dns_cloudflare.go | 3 ++- cmd/devp2p/dns_route53.go | 2 +- cmd/devp2p/dnscmd.go | 15 ++++++++------- cmd/devp2p/internal/ethtest/chain.go | 3 ++- cmd/devp2p/keycmd.go | 3 ++- cmd/geth/chaincmd.go | 2 +- cmd/utils/cmd.go | 3 ++- 9 files changed, 23 insertions(+), 16 deletions(-) diff --git a/cmd/devp2p/discv4cmd.go b/cmd/devp2p/discv4cmd.go index 0ea12e6150..499551bcb5 100644 --- a/cmd/devp2p/discv4cmd.go +++ b/cmd/devp2p/discv4cmd.go @@ -17,6 +17,7 @@ package main import ( + "errors" "fmt" "net" "strings" @@ -165,7 +166,7 @@ func discv4Resolve(ctx *cli.Context) error { func discv4ResolveJSON(ctx *cli.Context) error { if ctx.NArg() < 1 { - return fmt.Errorf("need nodes file as argument") + return errors.New("need nodes file as argument") } nodesFile := ctx.Args().Get(0) inputSet := make(nodeSet) @@ -195,7 +196,7 @@ func discv4ResolveJSON(ctx *cli.Context) error { func discv4Crawl(ctx *cli.Context) error { if ctx.NArg() < 1 { - return fmt.Errorf("need nodes file as argument") + return errors.New("need nodes file as argument") } nodesFile := ctx.Args().First() var inputSet nodeSet diff --git a/cmd/devp2p/discv5cmd.go b/cmd/devp2p/discv5cmd.go index 8833b66802..029c3da736 100644 --- a/cmd/devp2p/discv5cmd.go +++ b/cmd/devp2p/discv5cmd.go @@ -17,6 +17,7 @@ package main import ( + "errors" "fmt" "time" @@ -100,7 +101,7 @@ func discv5Resolve(ctx *cli.Context) error { func discv5Crawl(ctx *cli.Context) error { if ctx.NArg() < 1 { - return fmt.Errorf("need nodes file as argument") + return errors.New("need nodes file as argument") } nodesFile := ctx.Args().First() var inputSet nodeSet diff --git a/cmd/devp2p/dns_cloudflare.go b/cmd/devp2p/dns_cloudflare.go index 6e184c0a4c..b2e27fc8e0 100644 --- a/cmd/devp2p/dns_cloudflare.go +++ b/cmd/devp2p/dns_cloudflare.go @@ -18,6 +18,7 @@ package main import ( "context" + "errors" "fmt" "strings" @@ -48,7 +49,7 @@ type cloudflareClient struct { func newCloudflareClient(ctx *cli.Context) *cloudflareClient { token := ctx.String(cloudflareTokenFlag.Name) if token == "" { - exit(fmt.Errorf("need cloudflare API token to proceed")) + exit(errors.New("need cloudflare API token to proceed")) } api, err := cloudflare.NewWithAPIToken(token) if err != nil { diff --git a/cmd/devp2p/dns_route53.go b/cmd/devp2p/dns_route53.go index 8272c97bba..99830e3c16 100644 --- a/cmd/devp2p/dns_route53.go +++ b/cmd/devp2p/dns_route53.go @@ -81,7 +81,7 @@ func newRoute53Client(ctx *cli.Context) *route53Client { akey := ctx.String(route53AccessKeyFlag.Name) asec := ctx.String(route53AccessSecretFlag.Name) if akey == "" || asec == "" { - exit(fmt.Errorf("need Route53 Access Key ID and secret to proceed")) + exit(errors.New("need Route53 Access Key ID and secret to proceed")) } creds := aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(akey, asec, "")) cfg, err := config.LoadDefaultConfig(context.Background(), config.WithCredentialsProvider(creds)) diff --git a/cmd/devp2p/dnscmd.go b/cmd/devp2p/dnscmd.go index 6fb6d1e73f..e20828a126 100644 --- a/cmd/devp2p/dnscmd.go +++ b/cmd/devp2p/dnscmd.go @@ -19,6 +19,7 @@ package main import ( "crypto/ecdsa" "encoding/json" + "errors" "fmt" "io/ioutil" "os" @@ -147,7 +148,7 @@ func dnsSync(ctx *cli.Context) error { func dnsSign(ctx *cli.Context) error { if ctx.NArg() < 2 { - return fmt.Errorf("need tree definition directory and key file as arguments") + return errors.New("need tree definition directory and key file as arguments") } var ( defdir = ctx.Args().Get(0) @@ -201,7 +202,7 @@ func directoryName(dir string) string { // dnsToTXT performs dnsTXTCommand. func dnsToTXT(ctx *cli.Context) error { if ctx.NArg() < 1 { - return fmt.Errorf("need tree definition directory as argument") + return errors.New("need tree definition directory as argument") } output := ctx.Args().Get(1) if output == "" { @@ -218,7 +219,7 @@ func dnsToTXT(ctx *cli.Context) error { // dnsToCloudflare performs dnsCloudflareCommand. func dnsToCloudflare(ctx *cli.Context) error { if ctx.NArg() != 1 { - return fmt.Errorf("need tree definition directory as argument") + return errors.New("need tree definition directory as argument") } domain, t, err := loadTreeDefinitionForExport(ctx.Args().Get(0)) if err != nil { @@ -231,7 +232,7 @@ func dnsToCloudflare(ctx *cli.Context) error { // dnsToRoute53 performs dnsRoute53Command. func dnsToRoute53(ctx *cli.Context) error { if ctx.NArg() != 1 { - return fmt.Errorf("need tree definition directory as argument") + return errors.New("need tree definition directory as argument") } domain, t, err := loadTreeDefinitionForExport(ctx.Args().Get(0)) if err != nil { @@ -244,7 +245,7 @@ func dnsToRoute53(ctx *cli.Context) error { // dnsNukeRoute53 performs dnsRoute53NukeCommand. func dnsNukeRoute53(ctx *cli.Context) error { if ctx.NArg() != 1 { - return fmt.Errorf("need domain name as argument") + return errors.New("need domain name as argument") } client := newRoute53Client(ctx) return client.deleteDomain(ctx.Args().First()) @@ -363,10 +364,10 @@ func loadTreeDefinitionForExport(dir string) (domain string, t *dnsdisc.Tree, er // tree's signature if valid. func ensureValidTreeSignature(t *dnsdisc.Tree, pubkey *ecdsa.PublicKey, sig string) error { if sig == "" { - return fmt.Errorf("missing signature, run 'devp2p dns sign' first") + return errors.New("missing signature, run 'devp2p dns sign' first") } if err := t.SetSignature(pubkey, sig); err != nil { - return fmt.Errorf("invalid signature on tree, run 'devp2p dns sign' to update it") + return errors.New("invalid signature on tree, run 'devp2p dns sign' to update it") } return nil } diff --git a/cmd/devp2p/internal/ethtest/chain.go b/cmd/devp2p/internal/ethtest/chain.go index 4e2b3ae135..e6d19653c1 100644 --- a/cmd/devp2p/internal/ethtest/chain.go +++ b/cmd/devp2p/internal/ethtest/chain.go @@ -19,6 +19,7 @@ package ethtest import ( "compress/gzip" "encoding/json" + "errors" "fmt" "io" "io/ioutil" @@ -80,7 +81,7 @@ func (c *Chain) Head() *types.Block { func (c *Chain) GetHeaders(req GetBlockHeaders) (BlockHeaders, error) { if req.Amount < 1 { - return nil, fmt.Errorf("no block headers requested") + return nil, errors.New("no block headers requested") } headers := make(BlockHeaders, req.Amount) diff --git a/cmd/devp2p/keycmd.go b/cmd/devp2p/keycmd.go index edc2c6b4a3..e609dcbd8f 100644 --- a/cmd/devp2p/keycmd.go +++ b/cmd/devp2p/keycmd.go @@ -17,6 +17,7 @@ package main import ( + "errors" "fmt" "net" @@ -82,7 +83,7 @@ func genkey(ctx *cli.Context) error { func keyToURL(ctx *cli.Context) error { if ctx.NArg() != 1 { - return fmt.Errorf("need key file as argument") + return errors.New("need key file as argument") } var ( diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 201263b013..bbee4b8251 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -460,7 +460,7 @@ func dump(ctx *cli.Context) error { if conf.OnlyWithAddresses { fmt.Fprintf(os.Stderr, "If you want to include accounts with missing preimages, you need iterative output, since"+ " otherwise the accounts will overwrite each other in the resulting mapping.") - return fmt.Errorf("incompatible options") + return errors.New("incompatible options") } fmt.Println(string(state.Dump(conf))) } diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 06d296801a..5f6c50b12c 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -19,6 +19,7 @@ package utils import ( "compress/gzip" + "errors" "fmt" "io" "os" @@ -186,7 +187,7 @@ func ImportChain(chain *core.BlockChain, fn string) error { } // Import the batch. if checkInterrupt() { - return fmt.Errorf("interrupted") + return errors.New("interrupted") } missing := missingBlocks(chain, blocks[:i]) if len(missing) == 0 {