accounts,cmd,console,les,metrics: refactor some errors checked by (ST1005) go-staticcheck (#28532)

fix: fix some (ST1005)go-staticcheck
pull/28539/head
Zoro 1 year ago committed by GitHub
parent 984f82629c
commit 2814ee0547
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      accounts/abi/bind/backends/simulated.go
  2. 4
      accounts/abi/pack.go
  3. 6
      accounts/abi/reflect.go
  4. 1
      cmd/clef/main.go
  5. 2
      cmd/devp2p/discv4cmd.go
  6. 2
      cmd/devp2p/internal/ethtest/snap.go
  7. 2
      cmd/faucet/faucet.go
  8. 2
      cmd/utils/cmd.go
  9. 2
      console/bridge.go
  10. 2
      les/benchmark.go
  11. 2
      les/peer.go
  12. 2
      les/peer_test.go
  13. 4
      les/vflux/client/valuetracker.go
  14. 2
      metrics/disk_nop.go
  15. 4
      metrics/gauge_float64_test.go

@ -846,7 +846,7 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
defer b.mu.Unlock() defer b.mu.Unlock()
if len(b.pendingBlock.Transactions()) != 0 { if len(b.pendingBlock.Transactions()) != 0 {
return errors.New("Could not adjust time on non-empty block") return errors.New("could not adjust time on non-empty block")
} }
// Get the last block // Get the last block
block := b.blockchain.GetBlockByHash(b.pendingBlock.ParentHash()) block := b.blockchain.GetBlockByHash(b.pendingBlock.ParentHash())

@ -57,7 +57,7 @@ func packElement(t Type, reflectValue reflect.Value) ([]byte, error) {
reflectValue = mustArrayToByteSlice(reflectValue) reflectValue = mustArrayToByteSlice(reflectValue)
} }
if reflectValue.Type() != reflect.TypeOf([]byte{}) { if reflectValue.Type() != reflect.TypeOf([]byte{}) {
return []byte{}, errors.New("Bytes type is neither slice nor array") return []byte{}, errors.New("bytes type is neither slice nor array")
} }
return packBytesSlice(reflectValue.Bytes(), reflectValue.Len()), nil return packBytesSlice(reflectValue.Bytes(), reflectValue.Len()), nil
case FixedBytesTy, FunctionTy: case FixedBytesTy, FunctionTy:
@ -66,7 +66,7 @@ func packElement(t Type, reflectValue reflect.Value) ([]byte, error) {
} }
return common.RightPadBytes(reflectValue.Bytes(), 32), nil return common.RightPadBytes(reflectValue.Bytes(), 32), nil
default: default:
return []byte{}, fmt.Errorf("Could not pack element, unknown type: %v", t.T) return []byte{}, fmt.Errorf("could not pack element, unknown type: %v", t.T)
} }
} }

@ -134,7 +134,7 @@ func setSlice(dst, src reflect.Value) error {
dst.Set(slice) dst.Set(slice)
return nil return nil
} }
return errors.New("Cannot set slice, destination not settable") return errors.New("cannot set slice, destination not settable")
} }
func setArray(dst, src reflect.Value) error { func setArray(dst, src reflect.Value) error {
@ -155,7 +155,7 @@ func setArray(dst, src reflect.Value) error {
dst.Set(array) dst.Set(array)
return nil return nil
} }
return errors.New("Cannot set array, destination not settable") return errors.New("cannot set array, destination not settable")
} }
func setStruct(dst, src reflect.Value) error { func setStruct(dst, src reflect.Value) error {
@ -163,7 +163,7 @@ func setStruct(dst, src reflect.Value) error {
srcField := src.Field(i) srcField := src.Field(i)
dstField := dst.Field(i) dstField := dst.Field(i)
if !dstField.IsValid() || !srcField.IsValid() { if !dstField.IsValid() || !srcField.IsValid() {
return fmt.Errorf("Could not find src field: %v value: %v in destination", srcField.Type().Name(), srcField) return fmt.Errorf("could not find src field: %v value: %v in destination", srcField.Type().Name(), srcField)
} }
if err := set(dstField, srcField); err != nil { if err := set(dstField, srcField); err != nil {
return err return err

@ -581,6 +581,7 @@ func accountImport(c *cli.Context) error {
return err return err
} }
if first != second { if first != second {
//lint:ignore ST1005 This is a message for the user
return errors.New("Passwords do not match") return errors.New("Passwords do not match")
} }
acc, err := internalApi.ImportRawKey(hex.EncodeToString(crypto.FromECDSA(pKey)), first) acc, err := internalApi.ImportRawKey(hex.EncodeToString(crypto.FromECDSA(pKey)), first)

@ -236,7 +236,7 @@ func discv4Crawl(ctx *cli.Context) error {
func discv4Test(ctx *cli.Context) error { func discv4Test(ctx *cli.Context) error {
// Configure test package globals. // Configure test package globals.
if !ctx.IsSet(remoteEnodeFlag.Name) { if !ctx.IsSet(remoteEnodeFlag.Name) {
return fmt.Errorf("Missing -%v", remoteEnodeFlag.Name) return fmt.Errorf("missing -%v", remoteEnodeFlag.Name)
} }
v4test.Remote = ctx.String(remoteEnodeFlag.Name) v4test.Remote = ctx.String(remoteEnodeFlag.Name)
v4test.Listen1 = ctx.String(testListen1Flag.Name) v4test.Listen1 = ctx.String(testListen1Flag.Name)

@ -683,7 +683,7 @@ func (s *Suite) snapGetTrieNodes(t *utesting.T, tc *trieNodesTest) error {
hash := make([]byte, 32) hash := make([]byte, 32)
trienodes := res.Nodes trienodes := res.Nodes
if got, want := len(trienodes), len(tc.expHashes); got != want { if got, want := len(trienodes), len(tc.expHashes); got != want {
return fmt.Errorf("wrong trienode count, got %d, want %d\n", got, want) return fmt.Errorf("wrong trienode count, got %d, want %d", got, want)
} }
for i, trienode := range trienodes { for i, trienode := range trienodes {
hasher.Reset() hasher.Reset()

@ -248,7 +248,7 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*enode.Node, network ui
lesBackend, err := les.New(stack, &cfg) lesBackend, err := les.New(stack, &cfg)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to register the Ethereum service: %w", err) return nil, fmt.Errorf("failed to register the Ethereum service: %w", err)
} }
// Assemble the ethstats monitoring and reporting service' // Assemble the ethstats monitoring and reporting service'

@ -460,7 +460,7 @@ func ImportLDBData(db ethdb.Database, f string, startIndex int64, interrupt chan
case OpBatchAdd: case OpBatchAdd:
batch.Put(key, val) batch.Put(key, val)
default: default:
return fmt.Errorf("unknown op %d\n", op) return fmt.Errorf("unknown op %d", op)
} }
if batch.ValueSize() > ethdb.IdealBatchSize { if batch.ValueSize() > ethdb.IdealBatchSize {
if err := batch.Write(); err != nil { if err := batch.Write(); err != nil {

@ -78,7 +78,7 @@ func (b *bridge) NewAccount(call jsre.Call) (goja.Value, error) {
return nil, err return nil, err
} }
if password != confirm { if password != confirm {
return nil, errors.New("passwords don't match!") return nil, errors.New("passwords don't match")
} }
// A single string password was specified, use that // A single string password was specified, use that
case len(call.Arguments) == 1 && call.Argument(0).ToString() != nil: case len(call.Arguments) == 1 && call.Argument(0).ToString() != nil:

@ -338,7 +338,7 @@ func (h *serverHandler) measure(setup *benchmarkSetup, count int) error {
case <-h.closeCh: case <-h.closeCh:
clientPipe.Close() clientPipe.Close()
serverPipe.Close() serverPipe.Close()
return errors.New("Benchmark cancelled") return errors.New("benchmark cancelled")
} }
setup.totalTime += time.Duration(mclock.Now() - start) setup.totalTime += time.Duration(mclock.Now() - start)

@ -1000,7 +1000,7 @@ func (p *clientPeer) Handshake(td *big.Int, head common.Hash, headNum uint64, ge
} }
} }
if recentTx != txIndexUnlimited && p.version < lpv4 { if recentTx != txIndexUnlimited && p.version < lpv4 {
return errors.New("Cannot serve old clients without a complete tx index") return errors.New("cannot serve old clients without a complete tx index")
} }
// Note: clientPeer.headInfo should contain the last head announced to the client by us. // Note: clientPeer.headInfo should contain the last head announced to the client by us.
// The values announced in the handshake are dummy values for compatibility reasons and should be ignored. // The values announced in the handshake are dummy values for compatibility reasons and should be ignored.

@ -143,7 +143,7 @@ func TestHandshake(t *testing.T) {
return err return err
} }
if reqType != announceTypeSigned { if reqType != announceTypeSigned {
return errors.New("Expected announceTypeSigned") return errors.New("expected announceTypeSigned")
} }
return nil return nil
}) })

@ -257,7 +257,7 @@ func (vt *ValueTracker) loadFromDb(mapping []string) error {
} }
if version != vtVersion { if version != vtVersion {
log.Error("Unknown ValueTracker version", "stored", version, "current", nvtVersion) log.Error("Unknown ValueTracker version", "stored", version, "current", nvtVersion)
return fmt.Errorf("Unknown ValueTracker version %d (current version is %d)", version, vtVersion) return fmt.Errorf("unknown ValueTracker version %d (current version is %d)", version, vtVersion)
} }
var vte valueTrackerEncV1 var vte valueTrackerEncV1
if err := rlp.Decode(r, &vte); err != nil { if err := rlp.Decode(r, &vte); err != nil {
@ -295,7 +295,7 @@ loop:
} else { } else {
if vte.RefBasketMapping >= uint(len(vt.mappings)) { if vte.RefBasketMapping >= uint(len(vt.mappings)) {
log.Error("Unknown request basket mapping", "stored", vte.RefBasketMapping, "current", vt.currentMapping) log.Error("Unknown request basket mapping", "stored", vte.RefBasketMapping, "current", vt.currentMapping)
return fmt.Errorf("Unknown request basket mapping %d (current version is %d)", vte.RefBasketMapping, vt.currentMapping) return fmt.Errorf("unknown request basket mapping %d (current version is %d)", vte.RefBasketMapping, vt.currentMapping)
} }
vt.refBasket.basket = vte.RefBasket.convertMapping(vt.mappings[vte.RefBasketMapping], mapping, vt.initRefBasket) vt.refBasket.basket = vte.RefBasket.convertMapping(vt.mappings[vte.RefBasketMapping], mapping, vt.initRefBasket)
} }

@ -23,5 +23,5 @@ import "errors"
// ReadDiskStats retrieves the disk IO stats belonging to the current process. // ReadDiskStats retrieves the disk IO stats belonging to the current process.
func ReadDiskStats(stats *DiskStats) error { func ReadDiskStats(stats *DiskStats) error {
return errors.New("Not implemented") return errors.New("not implemented")
} }

@ -36,7 +36,7 @@ func TestGaugeFloat64Snapshot(t *testing.T) {
g.Update(47.0) g.Update(47.0)
snapshot := g.Snapshot() snapshot := g.Snapshot()
g.Update(float64(0)) g.Update(float64(0))
if v := snapshot.Value(); 47.0 != v { if v := snapshot.Value(); v != 47.0 {
t.Errorf("g.Value(): 47.0 != %v\n", v) t.Errorf("g.Value(): 47.0 != %v\n", v)
} }
} }
@ -45,7 +45,7 @@ func TestGetOrRegisterGaugeFloat64(t *testing.T) {
r := NewRegistry() r := NewRegistry()
NewRegisteredGaugeFloat64("foo", r).Update(47.0) NewRegisteredGaugeFloat64("foo", r).Update(47.0)
t.Logf("registry: %v", r) t.Logf("registry: %v", r)
if g := GetOrRegisterGaugeFloat64("foo", r).Snapshot(); 47.0 != g.Value() { if g := GetOrRegisterGaugeFloat64("foo", r).Snapshot(); g.Value() != 47.0 {
t.Fatal(g) t.Fatal(g)
} }
} }

Loading…
Cancel
Save