Skip to content

Commit e9c3183

Browse files
authored
cmd: use errrors.New instead of empty fmt.Errorf (#27329)
Signed-off-by: jsvisa <[email protected]>
1 parent 9231770 commit e9c3183

File tree

20 files changed

+50
-38
lines changed

20 files changed

+50
-38
lines changed

cmd/clef/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func initializeSecrets(c *cli.Context) error {
326326
return err
327327
}
328328
if num != len(masterSeed) {
329-
return fmt.Errorf("failed to read enough random")
329+
return errors.New("failed to read enough random")
330330
}
331331
n, p := keystore.StandardScryptN, keystore.StandardScryptP
332332
if c.Bool(utils.LightKDFFlag.Name) {
@@ -482,7 +482,7 @@ func initialize(c *cli.Context) error {
482482
}
483483
} else if !c.Bool(acceptFlag.Name) {
484484
if !confirm(legalWarning) {
485-
return fmt.Errorf("aborted by user")
485+
return errors.New("aborted by user")
486486
}
487487
fmt.Println()
488488
}
@@ -590,7 +590,7 @@ func accountImport(c *cli.Context) error {
590590
Address %v
591591
Keystore file: %v
592592
593-
The key is now encrypted; losing the password will result in permanently losing
593+
The key is now encrypted; losing the password will result in permanently losing
594594
access to the key and all associated funds!
595595
596596
Make sure to backup keystore and passwords in a safe location.`,
@@ -844,7 +844,7 @@ func readMasterKey(ctx *cli.Context, ui core.UIClientAPI) ([]byte, error) {
844844
}
845845
masterSeed, err := decryptSeed(cipherKey, password)
846846
if err != nil {
847-
return nil, fmt.Errorf("failed to decrypt the master seed of clef")
847+
return nil, errors.New("failed to decrypt the master seed of clef")
848848
}
849849
if len(masterSeed) < 256 {
850850
return nil, fmt.Errorf("master seed of insufficient length, expected >255 bytes, got %d", len(masterSeed))

cmd/devp2p/discv4cmd.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package main
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"net"
2223
"strconv"
@@ -177,7 +178,7 @@ func discv4Resolve(ctx *cli.Context) error {
177178

178179
func discv4ResolveJSON(ctx *cli.Context) error {
179180
if ctx.NArg() < 1 {
180-
return fmt.Errorf("need nodes file as argument")
181+
return errors.New("need nodes file as argument")
181182
}
182183
nodesFile := ctx.Args().Get(0)
183184
inputSet := make(nodeSet)
@@ -207,7 +208,7 @@ func discv4ResolveJSON(ctx *cli.Context) error {
207208

208209
func discv4Crawl(ctx *cli.Context) error {
209210
if ctx.NArg() < 1 {
210-
return fmt.Errorf("need nodes file as argument")
211+
return errors.New("need nodes file as argument")
211212
}
212213
nodesFile := ctx.Args().First()
213214
var inputSet nodeSet

cmd/devp2p/discv5cmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package main
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"time"
2223

@@ -98,7 +99,7 @@ func discv5Resolve(ctx *cli.Context) error {
9899

99100
func discv5Crawl(ctx *cli.Context) error {
100101
if ctx.NArg() < 1 {
101-
return fmt.Errorf("need nodes file as argument")
102+
return errors.New("need nodes file as argument")
102103
}
103104
nodesFile := ctx.Args().First()
104105
var inputSet nodeSet

cmd/devp2p/dns_cloudflare.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"strings"
2324

@@ -48,7 +49,7 @@ type cloudflareClient struct {
4849
func newCloudflareClient(ctx *cli.Context) *cloudflareClient {
4950
token := ctx.String(cloudflareTokenFlag.Name)
5051
if token == "" {
51-
exit(fmt.Errorf("need cloudflare API token to proceed"))
52+
exit(errors.New("need cloudflare API token to proceed"))
5253
}
5354
api, err := cloudflare.NewWithAPIToken(token)
5455
if err != nil {

cmd/devp2p/dns_route53.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func newRoute53Client(ctx *cli.Context) *route53Client {
8181
akey := ctx.String(route53AccessKeyFlag.Name)
8282
asec := ctx.String(route53AccessSecretFlag.Name)
8383
if akey == "" || asec == "" {
84-
exit(fmt.Errorf("need Route53 Access Key ID and secret to proceed"))
84+
exit(errors.New("need Route53 Access Key ID and secret to proceed"))
8585
}
8686
creds := aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(akey, asec, ""))
8787
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithCredentialsProvider(creds))

cmd/devp2p/dnscmd.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"crypto/ecdsa"
2121
"encoding/json"
22+
"errors"
2223
"fmt"
2324
"os"
2425
"path/filepath"
@@ -147,7 +148,7 @@ func dnsSync(ctx *cli.Context) error {
147148

148149
func dnsSign(ctx *cli.Context) error {
149150
if ctx.NArg() < 2 {
150-
return fmt.Errorf("need tree definition directory and key file as arguments")
151+
return errors.New("need tree definition directory and key file as arguments")
151152
}
152153
var (
153154
defdir = ctx.Args().Get(0)
@@ -201,7 +202,7 @@ func directoryName(dir string) string {
201202
// dnsToTXT performs dnsTXTCommand.
202203
func dnsToTXT(ctx *cli.Context) error {
203204
if ctx.NArg() < 1 {
204-
return fmt.Errorf("need tree definition directory as argument")
205+
return errors.New("need tree definition directory as argument")
205206
}
206207
output := ctx.Args().Get(1)
207208
if output == "" {
@@ -218,7 +219,7 @@ func dnsToTXT(ctx *cli.Context) error {
218219
// dnsToCloudflare performs dnsCloudflareCommand.
219220
func dnsToCloudflare(ctx *cli.Context) error {
220221
if ctx.NArg() != 1 {
221-
return fmt.Errorf("need tree definition directory as argument")
222+
return errors.New("need tree definition directory as argument")
222223
}
223224
domain, t, err := loadTreeDefinitionForExport(ctx.Args().Get(0))
224225
if err != nil {
@@ -231,7 +232,7 @@ func dnsToCloudflare(ctx *cli.Context) error {
231232
// dnsToRoute53 performs dnsRoute53Command.
232233
func dnsToRoute53(ctx *cli.Context) error {
233234
if ctx.NArg() != 1 {
234-
return fmt.Errorf("need tree definition directory as argument")
235+
return errors.New("need tree definition directory as argument")
235236
}
236237
domain, t, err := loadTreeDefinitionForExport(ctx.Args().Get(0))
237238
if err != nil {
@@ -244,7 +245,7 @@ func dnsToRoute53(ctx *cli.Context) error {
244245
// dnsNukeRoute53 performs dnsRoute53NukeCommand.
245246
func dnsNukeRoute53(ctx *cli.Context) error {
246247
if ctx.NArg() != 1 {
247-
return fmt.Errorf("need domain name as argument")
248+
return errors.New("need domain name as argument")
248249
}
249250
client := newRoute53Client(ctx)
250251
return client.deleteDomain(ctx.Args().First())
@@ -363,10 +364,10 @@ func loadTreeDefinitionForExport(dir string) (domain string, t *dnsdisc.Tree, er
363364
// tree's signature if valid.
364365
func ensureValidTreeSignature(t *dnsdisc.Tree, pubkey *ecdsa.PublicKey, sig string) error {
365366
if sig == "" {
366-
return fmt.Errorf("missing signature, run 'devp2p dns sign' first")
367+
return errors.New("missing signature, run 'devp2p dns sign' first")
367368
}
368369
if err := t.SetSignature(pubkey, sig); err != nil {
369-
return fmt.Errorf("invalid signature on tree, run 'devp2p dns sign' to update it")
370+
return errors.New("invalid signature on tree, run 'devp2p dns sign' to update it")
370371
}
371372
return nil
372373
}

cmd/devp2p/enrcmd.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bytes"
2121
"encoding/base64"
2222
"encoding/hex"
23+
"errors"
2324
"fmt"
2425
"io"
2526
"net"
@@ -48,7 +49,7 @@ func enrdump(ctx *cli.Context) error {
4849
var source string
4950
if file := ctx.String(fileFlag.Name); file != "" {
5051
if ctx.NArg() != 0 {
51-
return fmt.Errorf("can't dump record from command-line argument in -file mode")
52+
return errors.New("can't dump record from command-line argument in -file mode")
5253
}
5354
var b []byte
5455
var err error
@@ -64,7 +65,7 @@ func enrdump(ctx *cli.Context) error {
6465
} else if ctx.NArg() == 1 {
6566
source = ctx.Args().First()
6667
} else {
67-
return fmt.Errorf("need record as argument")
68+
return errors.New("need record as argument")
6869
}
6970

7071
r, err := parseRecord(source)

cmd/devp2p/internal/ethtest/chain.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ethtest
1919
import (
2020
"compress/gzip"
2121
"encoding/json"
22+
"errors"
2223
"fmt"
2324
"io"
2425
"math/big"
@@ -98,7 +99,7 @@ func (c *Chain) Head() *types.Block {
9899

99100
func (c *Chain) GetHeaders(req *GetBlockHeaders) ([]*types.Header, error) {
100101
if req.Amount < 1 {
101-
return nil, fmt.Errorf("no block headers requested")
102+
return nil, errors.New("no block headers requested")
102103
}
103104

104105
headers := make([]*types.Header, req.Amount)

cmd/devp2p/internal/ethtest/helpers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package ethtest
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"net"
2223
"reflect"
@@ -185,7 +186,7 @@ loop:
185186
}
186187
// make sure eth protocol version is set for negotiation
187188
if c.negotiatedProtoVersion == 0 {
188-
return nil, fmt.Errorf("eth protocol version must be set in Conn")
189+
return nil, errors.New("eth protocol version must be set in Conn")
189190
}
190191
if status == nil {
191192
// default status message

cmd/devp2p/internal/ethtest/transaction.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package ethtest
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"math/big"
2223
"strings"
@@ -39,7 +40,7 @@ func (s *Suite) sendSuccessfulTxs(t *utesting.T) error {
3940
}
4041
for i, tx := range tests {
4142
if tx == nil {
42-
return fmt.Errorf("could not find tx to send")
43+
return errors.New("could not find tx to send")
4344
}
4445
t.Logf("Testing tx propagation %d: sending tx %v %v %v\n", i, tx.Hash().String(), tx.GasPrice(), tx.Gas())
4546
// get previous tx if exists for reference in case of old tx propagation
@@ -348,7 +349,7 @@ func generateTxs(s *Suite, numTxs int) (map[common.Hash]common.Hash, []*types.Tr
348349

349350
nextTx := getNextTxFromChain(s)
350351
if nextTx == nil {
351-
return nil, nil, fmt.Errorf("failed to get the next transaction")
352+
return nil, nil, errors.New("failed to get the next transaction")
352353
}
353354
gas := nextTx.Gas()
354355

@@ -357,7 +358,7 @@ func generateTxs(s *Suite, numTxs int) (map[common.Hash]common.Hash, []*types.Tr
357358
for i := 0; i < numTxs; i++ {
358359
tx := generateTx(s.chain.chainConfig, nonce, gas)
359360
if tx == nil {
360-
return nil, nil, fmt.Errorf("failed to get the next transaction")
361+
return nil, nil, errors.New("failed to get the next transaction")
361362
}
362363
txHashMap[tx.Hash()] = tx.Hash()
363364
txs[i] = tx

0 commit comments

Comments
 (0)