Revert "cmd: use errrors.New instead of empty fmt.Errorf (#27329)"

This reverts commit 13b2b9f14a.
This commit is contained in:
devopsbo3 2023-11-10 12:27:53 -06:00 committed by GitHub
parent b99261b751
commit a8c67d066d
20 changed files with 38 additions and 50 deletions

View file

@ -326,7 +326,7 @@ func initializeSecrets(c *cli.Context) error {
return err return err
} }
if num != len(masterSeed) { if num != len(masterSeed) {
return errors.New("failed to read enough random") return fmt.Errorf("failed to read enough random")
} }
n, p := keystore.StandardScryptN, keystore.StandardScryptP n, p := keystore.StandardScryptN, keystore.StandardScryptP
if c.Bool(utils.LightKDFFlag.Name) { if c.Bool(utils.LightKDFFlag.Name) {
@ -482,7 +482,7 @@ func initialize(c *cli.Context) error {
} }
} else if !c.Bool(acceptFlag.Name) { } else if !c.Bool(acceptFlag.Name) {
if !confirm(legalWarning) { if !confirm(legalWarning) {
return errors.New("aborted by user") return fmt.Errorf("aborted by user")
} }
fmt.Println() fmt.Println()
} }
@ -590,7 +590,7 @@ func accountImport(c *cli.Context) error {
Address %v Address %v
Keystore file: %v Keystore file: %v
The key is now encrypted; losing the password will result in permanently losing The key is now encrypted; losing the password will result in permanently losing
access to the key and all associated funds! access to the key and all associated funds!
Make sure to backup keystore and passwords in a safe location.`, 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) {
} }
masterSeed, err := decryptSeed(cipherKey, password) masterSeed, err := decryptSeed(cipherKey, password)
if err != nil { if err != nil {
return nil, errors.New("failed to decrypt the master seed of clef") return nil, fmt.Errorf("failed to decrypt the master seed of clef")
} }
if len(masterSeed) < 256 { if len(masterSeed) < 256 {
return nil, fmt.Errorf("master seed of insufficient length, expected >255 bytes, got %d", len(masterSeed)) return nil, fmt.Errorf("master seed of insufficient length, expected >255 bytes, got %d", len(masterSeed))

View file

@ -17,7 +17,6 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
"net" "net"
"strconv" "strconv"
@ -178,7 +177,7 @@ func discv4Resolve(ctx *cli.Context) error {
func discv4ResolveJSON(ctx *cli.Context) error { func discv4ResolveJSON(ctx *cli.Context) error {
if ctx.NArg() < 1 { if ctx.NArg() < 1 {
return errors.New("need nodes file as argument") return fmt.Errorf("need nodes file as argument")
} }
nodesFile := ctx.Args().Get(0) nodesFile := ctx.Args().Get(0)
inputSet := make(nodeSet) inputSet := make(nodeSet)
@ -208,7 +207,7 @@ func discv4ResolveJSON(ctx *cli.Context) error {
func discv4Crawl(ctx *cli.Context) error { func discv4Crawl(ctx *cli.Context) error {
if ctx.NArg() < 1 { if ctx.NArg() < 1 {
return errors.New("need nodes file as argument") return fmt.Errorf("need nodes file as argument")
} }
nodesFile := ctx.Args().First() nodesFile := ctx.Args().First()
var inputSet nodeSet var inputSet nodeSet

View file

@ -17,7 +17,6 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
"time" "time"
@ -99,7 +98,7 @@ func discv5Resolve(ctx *cli.Context) error {
func discv5Crawl(ctx *cli.Context) error { func discv5Crawl(ctx *cli.Context) error {
if ctx.NArg() < 1 { if ctx.NArg() < 1 {
return errors.New("need nodes file as argument") return fmt.Errorf("need nodes file as argument")
} }
nodesFile := ctx.Args().First() nodesFile := ctx.Args().First()
var inputSet nodeSet var inputSet nodeSet

View file

@ -18,7 +18,6 @@ package main
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
@ -49,7 +48,7 @@ type cloudflareClient struct {
func newCloudflareClient(ctx *cli.Context) *cloudflareClient { func newCloudflareClient(ctx *cli.Context) *cloudflareClient {
token := ctx.String(cloudflareTokenFlag.Name) token := ctx.String(cloudflareTokenFlag.Name)
if token == "" { if token == "" {
exit(errors.New("need cloudflare API token to proceed")) exit(fmt.Errorf("need cloudflare API token to proceed"))
} }
api, err := cloudflare.NewWithAPIToken(token) api, err := cloudflare.NewWithAPIToken(token)
if err != nil { if err != nil {

View file

@ -81,7 +81,7 @@ func newRoute53Client(ctx *cli.Context) *route53Client {
akey := ctx.String(route53AccessKeyFlag.Name) akey := ctx.String(route53AccessKeyFlag.Name)
asec := ctx.String(route53AccessSecretFlag.Name) asec := ctx.String(route53AccessSecretFlag.Name)
if akey == "" || asec == "" { if akey == "" || asec == "" {
exit(errors.New("need Route53 Access Key ID and secret to proceed")) exit(fmt.Errorf("need Route53 Access Key ID and secret to proceed"))
} }
creds := aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(akey, asec, "")) creds := aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(akey, asec, ""))
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithCredentialsProvider(creds)) cfg, err := config.LoadDefaultConfig(context.Background(), config.WithCredentialsProvider(creds))

View file

@ -19,7 +19,6 @@ package main
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -148,7 +147,7 @@ func dnsSync(ctx *cli.Context) error {
func dnsSign(ctx *cli.Context) error { func dnsSign(ctx *cli.Context) error {
if ctx.NArg() < 2 { if ctx.NArg() < 2 {
return errors.New("need tree definition directory and key file as arguments") return fmt.Errorf("need tree definition directory and key file as arguments")
} }
var ( var (
defdir = ctx.Args().Get(0) defdir = ctx.Args().Get(0)
@ -202,7 +201,7 @@ func directoryName(dir string) string {
// dnsToTXT performs dnsTXTCommand. // dnsToTXT performs dnsTXTCommand.
func dnsToTXT(ctx *cli.Context) error { func dnsToTXT(ctx *cli.Context) error {
if ctx.NArg() < 1 { if ctx.NArg() < 1 {
return errors.New("need tree definition directory as argument") return fmt.Errorf("need tree definition directory as argument")
} }
output := ctx.Args().Get(1) output := ctx.Args().Get(1)
if output == "" { if output == "" {
@ -219,7 +218,7 @@ func dnsToTXT(ctx *cli.Context) error {
// dnsToCloudflare performs dnsCloudflareCommand. // dnsToCloudflare performs dnsCloudflareCommand.
func dnsToCloudflare(ctx *cli.Context) error { func dnsToCloudflare(ctx *cli.Context) error {
if ctx.NArg() != 1 { if ctx.NArg() != 1 {
return errors.New("need tree definition directory as argument") return fmt.Errorf("need tree definition directory as argument")
} }
domain, t, err := loadTreeDefinitionForExport(ctx.Args().Get(0)) domain, t, err := loadTreeDefinitionForExport(ctx.Args().Get(0))
if err != nil { if err != nil {
@ -232,7 +231,7 @@ func dnsToCloudflare(ctx *cli.Context) error {
// dnsToRoute53 performs dnsRoute53Command. // dnsToRoute53 performs dnsRoute53Command.
func dnsToRoute53(ctx *cli.Context) error { func dnsToRoute53(ctx *cli.Context) error {
if ctx.NArg() != 1 { if ctx.NArg() != 1 {
return errors.New("need tree definition directory as argument") return fmt.Errorf("need tree definition directory as argument")
} }
domain, t, err := loadTreeDefinitionForExport(ctx.Args().Get(0)) domain, t, err := loadTreeDefinitionForExport(ctx.Args().Get(0))
if err != nil { if err != nil {
@ -245,7 +244,7 @@ func dnsToRoute53(ctx *cli.Context) error {
// dnsNukeRoute53 performs dnsRoute53NukeCommand. // dnsNukeRoute53 performs dnsRoute53NukeCommand.
func dnsNukeRoute53(ctx *cli.Context) error { func dnsNukeRoute53(ctx *cli.Context) error {
if ctx.NArg() != 1 { if ctx.NArg() != 1 {
return errors.New("need domain name as argument") return fmt.Errorf("need domain name as argument")
} }
client := newRoute53Client(ctx) client := newRoute53Client(ctx)
return client.deleteDomain(ctx.Args().First()) return client.deleteDomain(ctx.Args().First())
@ -364,10 +363,10 @@ func loadTreeDefinitionForExport(dir string) (domain string, t *dnsdisc.Tree, er
// tree's signature if valid. // tree's signature if valid.
func ensureValidTreeSignature(t *dnsdisc.Tree, pubkey *ecdsa.PublicKey, sig string) error { func ensureValidTreeSignature(t *dnsdisc.Tree, pubkey *ecdsa.PublicKey, sig string) error {
if sig == "" { if sig == "" {
return errors.New("missing signature, run 'devp2p dns sign' first") return fmt.Errorf("missing signature, run 'devp2p dns sign' first")
} }
if err := t.SetSignature(pubkey, sig); err != nil { if err := t.SetSignature(pubkey, sig); err != nil {
return errors.New("invalid signature on tree, run 'devp2p dns sign' to update it") return fmt.Errorf("invalid signature on tree, run 'devp2p dns sign' to update it")
} }
return nil return nil
} }

View file

@ -20,7 +20,6 @@ import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"encoding/hex" "encoding/hex"
"errors"
"fmt" "fmt"
"io" "io"
"net" "net"
@ -49,7 +48,7 @@ func enrdump(ctx *cli.Context) error {
var source string var source string
if file := ctx.String(fileFlag.Name); file != "" { if file := ctx.String(fileFlag.Name); file != "" {
if ctx.NArg() != 0 { if ctx.NArg() != 0 {
return errors.New("can't dump record from command-line argument in -file mode") return fmt.Errorf("can't dump record from command-line argument in -file mode")
} }
var b []byte var b []byte
var err error var err error
@ -65,7 +64,7 @@ func enrdump(ctx *cli.Context) error {
} else if ctx.NArg() == 1 { } else if ctx.NArg() == 1 {
source = ctx.Args().First() source = ctx.Args().First()
} else { } else {
return errors.New("need record as argument") return fmt.Errorf("need record as argument")
} }
r, err := parseRecord(source) r, err := parseRecord(source)

View file

@ -19,7 +19,6 @@ package ethtest
import ( import (
"compress/gzip" "compress/gzip"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"math/big" "math/big"
@ -99,7 +98,7 @@ func (c *Chain) Head() *types.Block {
func (c *Chain) GetHeaders(req *GetBlockHeaders) ([]*types.Header, error) { func (c *Chain) GetHeaders(req *GetBlockHeaders) ([]*types.Header, error) {
if req.Amount < 1 { if req.Amount < 1 {
return nil, errors.New("no block headers requested") return nil, fmt.Errorf("no block headers requested")
} }
headers := make([]*types.Header, req.Amount) headers := make([]*types.Header, req.Amount)

View file

@ -17,7 +17,6 @@
package ethtest package ethtest
import ( import (
"errors"
"fmt" "fmt"
"net" "net"
"reflect" "reflect"
@ -186,7 +185,7 @@ loop:
} }
// make sure eth protocol version is set for negotiation // make sure eth protocol version is set for negotiation
if c.negotiatedProtoVersion == 0 { if c.negotiatedProtoVersion == 0 {
return nil, errors.New("eth protocol version must be set in Conn") return nil, fmt.Errorf("eth protocol version must be set in Conn")
} }
if status == nil { if status == nil {
// default status message // default status message

View file

@ -17,7 +17,6 @@
package ethtest package ethtest
import ( import (
"errors"
"fmt" "fmt"
"math/big" "math/big"
"strings" "strings"
@ -40,7 +39,7 @@ func (s *Suite) sendSuccessfulTxs(t *utesting.T) error {
} }
for i, tx := range tests { for i, tx := range tests {
if tx == nil { if tx == nil {
return errors.New("could not find tx to send") return fmt.Errorf("could not find tx to send")
} }
t.Logf("Testing tx propagation %d: sending tx %v %v %v\n", i, tx.Hash().String(), tx.GasPrice(), tx.Gas()) t.Logf("Testing tx propagation %d: sending tx %v %v %v\n", i, tx.Hash().String(), tx.GasPrice(), tx.Gas())
// get previous tx if exists for reference in case of old tx propagation // get previous tx if exists for reference in case of old tx propagation
@ -349,7 +348,7 @@ func generateTxs(s *Suite, numTxs int) (map[common.Hash]common.Hash, []*types.Tr
nextTx := getNextTxFromChain(s) nextTx := getNextTxFromChain(s)
if nextTx == nil { if nextTx == nil {
return nil, nil, errors.New("failed to get the next transaction") return nil, nil, fmt.Errorf("failed to get the next transaction")
} }
gas := nextTx.Gas() gas := nextTx.Gas()
@ -358,7 +357,7 @@ func generateTxs(s *Suite, numTxs int) (map[common.Hash]common.Hash, []*types.Tr
for i := 0; i < numTxs; i++ { for i := 0; i < numTxs; i++ {
tx := generateTx(s.chain.chainConfig, nonce, gas) tx := generateTx(s.chain.chainConfig, nonce, gas)
if tx == nil { if tx == nil {
return nil, nil, errors.New("failed to get the next transaction") return nil, nil, fmt.Errorf("failed to get the next transaction")
} }
txHashMap[tx.Hash()] = tx.Hash() txHashMap[tx.Hash()] = tx.Hash()
txs[i] = tx txs[i] = tx

View file

@ -18,7 +18,6 @@ package ethtest
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"errors"
"fmt" "fmt"
"time" "time"
@ -287,5 +286,5 @@ func (c *Conn) ReadSnap(id uint64) (Message, error) {
} }
return snpMsg.(Message), nil return snpMsg.(Message), nil
} }
return nil, errors.New("request timed out") return nil, fmt.Errorf("request timed out")
} }

View file

@ -19,7 +19,6 @@ package v4test
import ( import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"errors"
"fmt" "fmt"
"net" "net"
"time" "time"
@ -120,7 +119,7 @@ func (te *testenv) checkPingPong(pingHash []byte) error {
// and a PING. The two packets do not have to be in any particular order. // and a PING. The two packets do not have to be in any particular order.
func (te *testenv) checkPong(reply v4wire.Packet, pingHash []byte) error { func (te *testenv) checkPong(reply v4wire.Packet, pingHash []byte) error {
if reply == nil { if reply == nil {
return errors.New("expected PONG reply, got nil") return fmt.Errorf("expected PONG reply, got nil")
} }
if reply.Kind() != v4wire.PongPacket { if reply.Kind() != v4wire.PongPacket {
return fmt.Errorf("expected PONG reply, got %v %v", reply.Name(), reply) return fmt.Errorf("expected PONG reply, got %v %v", reply.Name(), reply)

View file

@ -17,7 +17,6 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
"net" "net"
@ -87,7 +86,7 @@ var (
func genkey(ctx *cli.Context) error { func genkey(ctx *cli.Context) error {
if ctx.NArg() != 1 { if ctx.NArg() != 1 {
return errors.New("need key file as argument") return fmt.Errorf("need key file as argument")
} }
file := ctx.Args().Get(0) file := ctx.Args().Get(0)
@ -127,7 +126,7 @@ func keyToRecord(ctx *cli.Context) error {
func makeRecord(ctx *cli.Context) (*enode.Node, error) { func makeRecord(ctx *cli.Context) (*enode.Node, error) {
if ctx.NArg() != 1 { if ctx.NArg() != 1 {
return nil, errors.New("need key file as argument") return nil, fmt.Errorf("need key file as argument")
} }
var ( var (

View file

@ -59,7 +59,7 @@ var (
func nodesetInfo(ctx *cli.Context) error { func nodesetInfo(ctx *cli.Context) error {
if ctx.NArg() < 1 { if ctx.NArg() < 1 {
return errors.New("need nodes file as argument") return fmt.Errorf("need nodes file as argument")
} }
ns := loadNodesJSON(ctx.Args().First()) ns := loadNodesJSON(ctx.Args().First())
@ -98,7 +98,7 @@ func showAttributeCounts(ns nodeSet) {
func nodesetFilter(ctx *cli.Context) error { func nodesetFilter(ctx *cli.Context) error {
if ctx.NArg() < 1 { if ctx.NArg() < 1 {
return errors.New("need nodes file as argument") return fmt.Errorf("need nodes file as argument")
} }
// Parse -limit. // Parse -limit.
limit, err := parseFilterLimit(ctx.Args().Tail()) limit, err := parseFilterLimit(ctx.Args().Tail())

View file

@ -17,7 +17,6 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
"net" "net"
@ -92,7 +91,7 @@ func rlpxPing(ctx *cli.Context) error {
case 1: case 1:
var msg []p2p.DiscReason var msg []p2p.DiscReason
if rlp.DecodeBytes(data, &msg); len(msg) == 0 { if rlp.DecodeBytes(data, &msg); len(msg) == 0 {
return errors.New("invalid disconnect message") return fmt.Errorf("invalid disconnect message")
} }
return fmt.Errorf("received disconnect message: %v", msg[0]) return fmt.Errorf("received disconnect message: %v", msg[0])
default: default:

View file

@ -171,18 +171,18 @@ func (i *bbInput) sealClique(block *types.Block) (*types.Block, error) {
// If any clique value overwrites an explicit header value, fail // If any clique value overwrites an explicit header value, fail
// to avoid silently building a block with unexpected values. // to avoid silently building a block with unexpected values.
if i.Header.Extra != nil { if i.Header.Extra != nil {
return nil, NewError(ErrorConfig, errors.New("sealing with clique will overwrite provided extra data")) return nil, NewError(ErrorConfig, fmt.Errorf("sealing with clique will overwrite provided extra data"))
} }
header := block.Header() header := block.Header()
if i.Clique.Voted != nil { if i.Clique.Voted != nil {
if i.Header.Coinbase != nil { if i.Header.Coinbase != nil {
return nil, NewError(ErrorConfig, errors.New("sealing with clique and voting will overwrite provided coinbase")) return nil, NewError(ErrorConfig, fmt.Errorf("sealing with clique and voting will overwrite provided coinbase"))
} }
header.Coinbase = *i.Clique.Voted header.Coinbase = *i.Clique.Voted
} }
if i.Clique.Authorize != nil { if i.Clique.Authorize != nil {
if i.Header.Nonce != nil { if i.Header.Nonce != nil {
return nil, NewError(ErrorConfig, errors.New("sealing with clique and voting will overwrite provided nonce")) return nil, NewError(ErrorConfig, fmt.Errorf("sealing with clique and voting will overwrite provided nonce"))
} }
if *i.Clique.Authorize { if *i.Clique.Authorize {
header.Nonce = [8]byte{} header.Nonce = [8]byte{}

View file

@ -893,6 +893,6 @@ func getGenesis(genesisFlag string, goerliFlag bool, rinkebyFlag bool, sepoliaFl
case sepoliaFlag: case sepoliaFlag:
return core.DefaultSepoliaGenesisBlock(), nil return core.DefaultSepoliaGenesisBlock(), nil
default: default:
return nil, errors.New("no genesis flag provided") return nil, fmt.Errorf("no genesis flag provided")
} }
} }

View file

@ -478,7 +478,7 @@ func dump(ctx *cli.Context) error {
if conf.OnlyWithAddresses { if conf.OnlyWithAddresses {
fmt.Fprintf(os.Stderr, "If you want to include accounts with missing preimages, you need iterative output, since"+ 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.") " otherwise the accounts will overwrite each other in the resulting mapping.")
return errors.New("incompatible options") return fmt.Errorf("incompatible options")
} }
fmt.Println(string(state.Dump(conf))) fmt.Println(string(state.Dump(conf)))
} }

View file

@ -100,7 +100,7 @@ func checkChildren(root verkle.VerkleNode, resolver verkle.NodeResolverFn) error
return nil return nil
} }
} }
return errors.New("Both balance and nonce are 0") return fmt.Errorf("Both balance and nonce are 0")
case verkle.Empty: case verkle.Empty:
// nothing to do // nothing to do
default: default:

View file

@ -184,7 +184,7 @@ func ImportChain(chain *core.BlockChain, fn string) error {
for batch := 0; ; batch++ { for batch := 0; ; batch++ {
// Load a batch of RLP blocks. // Load a batch of RLP blocks.
if checkInterrupt() { if checkInterrupt() {
return errors.New("interrupted") return fmt.Errorf("interrupted")
} }
i := 0 i := 0
for ; i < importBatchSize; i++ { for ; i < importBatchSize; i++ {
@ -207,7 +207,7 @@ func ImportChain(chain *core.BlockChain, fn string) error {
} }
// Import the batch. // Import the batch.
if checkInterrupt() { if checkInterrupt() {
return errors.New("interrupted") return fmt.Errorf("interrupted")
} }
missing := missingBlocks(chain, blocks[:i]) missing := missingBlocks(chain, blocks[:i])
if len(missing) == 0 { if len(missing) == 0 {