mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
dev: fix: errorcheck lint issues
This commit is contained in:
parent
218917076c
commit
d9a82cd3cd
15 changed files with 47 additions and 37 deletions
|
|
@ -27,7 +27,10 @@ import (
|
||||||
// Some of these test cases were adapted
|
// Some of these test cases were adapted
|
||||||
// from https://github.com/hashicorp/golang-lru/blob/master/simplelru/lru_test.go
|
// from https://github.com/hashicorp/golang-lru/blob/master/simplelru/lru_test.go
|
||||||
|
|
||||||
|
// nolint:gocognit
|
||||||
func TestBasicLRU(t *testing.T) {
|
func TestBasicLRU(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
cache := NewBasicLRU[int, int](128)
|
cache := NewBasicLRU[int, int](128)
|
||||||
|
|
||||||
for i := 0; i < 256; i++ {
|
for i := 0; i < 256; i++ {
|
||||||
|
|
@ -210,9 +213,9 @@ func BenchmarkLRU(b *testing.B) {
|
||||||
|
|
||||||
for i := range keys {
|
for i := range keys {
|
||||||
b := make([]byte, 32)
|
b := make([]byte, 32)
|
||||||
crand.Read(b)
|
_, _ = crand.Read(b)
|
||||||
keys[i] = string(b)
|
keys[i] = string(b)
|
||||||
crand.Read(b)
|
_, _ = crand.Read(b)
|
||||||
values[i] = b
|
values[i] = b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ func TestMixedcaseAddressMarshal(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
json.Unmarshal(blob, &output)
|
_ = json.Unmarshal(blob, &output)
|
||||||
|
|
||||||
if output != input {
|
if output != input {
|
||||||
t.Fatal("Failed to marshal/unmarshal MixedcaseAddress object")
|
t.Fatal("Failed to marshal/unmarshal MixedcaseAddress object")
|
||||||
|
|
|
||||||
|
|
@ -96,5 +96,6 @@ func SignFile(input string, output string, key string, untrustedComment string,
|
||||||
fmt.Fprintln(out, base64.StdEncoding.EncodeToString(dataSig))
|
fmt.Fprintln(out, base64.StdEncoding.EncodeToString(dataSig))
|
||||||
fmt.Fprintln(out, "trusted comment:", trustedComment)
|
fmt.Fprintln(out, "trusted comment:", trustedComment)
|
||||||
fmt.Fprintln(out, base64.StdEncoding.EncodeToString(commentSig))
|
fmt.Fprintln(out, base64.StdEncoding.EncodeToString(commentSig))
|
||||||
|
// nolint:gosec
|
||||||
return os.WriteFile(output, out.Bytes(), 0644)
|
return os.WriteFile(output, out.Bytes(), 0644)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -399,7 +399,7 @@ func BenchDatabaseSuite(b *testing.B, New func() ethdb.KeyValueStore) {
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
for i := 0; i < len(keys); i++ {
|
for i := 0; i < len(keys); i++ {
|
||||||
db.Put(keys[i], vals[i])
|
_ = db.Put(keys[i], vals[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.Run("WriteSorted", func(b *testing.B) {
|
b.Run("WriteSorted", func(b *testing.B) {
|
||||||
|
|
@ -417,13 +417,13 @@ func BenchDatabaseSuite(b *testing.B, New func() ethdb.KeyValueStore) {
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
for i := 0; i < len(keys); i++ {
|
for i := 0; i < len(keys); i++ {
|
||||||
db.Put(keys[i], vals[i])
|
_ = db.Put(keys[i], vals[i])
|
||||||
}
|
}
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|
||||||
for i := 0; i < len(keys); i++ {
|
for i := 0; i < len(keys); i++ {
|
||||||
db.Get(keys[i])
|
_, _ = db.Get(keys[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.Run("ReadSorted", func(b *testing.B) {
|
b.Run("ReadSorted", func(b *testing.B) {
|
||||||
|
|
@ -441,7 +441,7 @@ func BenchDatabaseSuite(b *testing.B, New func() ethdb.KeyValueStore) {
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
for i := 0; i < len(keys); i++ {
|
for i := 0; i < len(keys); i++ {
|
||||||
db.Put(keys[i], vals[i])
|
_ = db.Put(keys[i], vals[i])
|
||||||
}
|
}
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|
@ -470,9 +470,9 @@ func BenchDatabaseSuite(b *testing.B, New func() ethdb.KeyValueStore) {
|
||||||
|
|
||||||
batch := db.NewBatch()
|
batch := db.NewBatch()
|
||||||
for i := 0; i < len(keys); i++ {
|
for i := 0; i < len(keys); i++ {
|
||||||
batch.Put(keys[i], vals[i])
|
_ = batch.Put(keys[i], vals[i])
|
||||||
}
|
}
|
||||||
batch.Write()
|
_ = batch.Write()
|
||||||
}
|
}
|
||||||
b.Run("BenchWriteSorted", func(b *testing.B) {
|
b.Run("BenchWriteSorted", func(b *testing.B) {
|
||||||
benchBatchWrite(b, sKeys, sVals)
|
benchBatchWrite(b, sKeys, sVals)
|
||||||
|
|
@ -504,8 +504,8 @@ func randBytes(length int) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeDataset(size, ksize, vsize int, order bool) ([][]byte, [][]byte) {
|
func makeDataset(size, ksize, vsize int, order bool) ([][]byte, [][]byte) {
|
||||||
var keys [][]byte
|
keys := make([][]byte, 0, ksize)
|
||||||
var vals [][]byte
|
vals := make([][]byte, 0, vsize)
|
||||||
|
|
||||||
for i := 0; i < size; i += 1 {
|
for i := 0; i < size; i += 1 {
|
||||||
keys = append(keys, randBytes(ksize))
|
keys = append(keys, randBytes(ksize))
|
||||||
|
|
|
||||||
|
|
@ -517,15 +517,15 @@ type batch struct {
|
||||||
|
|
||||||
// Put inserts the given value into the batch for later committing.
|
// Put inserts the given value into the batch for later committing.
|
||||||
func (b *batch) Put(key, value []byte) error {
|
func (b *batch) Put(key, value []byte) error {
|
||||||
b.b.Set(key, value, nil)
|
_ = b.b.Set(key, value, nil)
|
||||||
b.size += len(key) + len(value)
|
b.size += len(key) + len(value)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete inserts the a key removal into the batch for later committing.
|
// Delete inserts the key removal into the batch for later committing.
|
||||||
func (b *batch) Delete(key []byte) error {
|
func (b *batch) Delete(key []byte) error {
|
||||||
b.b.Delete(key, nil)
|
_ = b.b.Delete(key, nil)
|
||||||
b.size += len(key)
|
b.size += len(key)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -559,9 +559,9 @@ func (b *batch) Replay(w ethdb.KeyValueWriter) error {
|
||||||
// The (k,v) slices might be overwritten if the batch is reset/reused,
|
// The (k,v) slices might be overwritten if the batch is reset/reused,
|
||||||
// and the receiver should copy them if they are to be retained long-term.
|
// and the receiver should copy them if they are to be retained long-term.
|
||||||
if kind == pebble.InternalKeyKindSet {
|
if kind == pebble.InternalKeyKindSet {
|
||||||
w.Put(k, v)
|
_ = w.Put(k, v)
|
||||||
} else if kind == pebble.InternalKeyKindDelete {
|
} else if kind == pebble.InternalKeyKindDelete {
|
||||||
w.Delete(k)
|
_ = w.Delete(k)
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("unhandled operation, keytype: %v", kind)
|
return fmt.Errorf("unhandled operation, keytype: %v", kind)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func TestPrettyUint256(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
v := new(uint256.Int)
|
v := new(uint256.Int)
|
||||||
v.SetFromDecimal(tt.int)
|
_ = v.SetFromDecimal(tt.int)
|
||||||
|
|
||||||
if have := formatLogfmtUint256(v); have != tt.s {
|
if have := formatLogfmtUint256(v); have != tt.s {
|
||||||
t.Errorf("invalid output %s, want %s", have, tt.s)
|
t.Errorf("invalid output %s, want %s", have, tt.s)
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ func NewRegisteredCounterFloat64(name string, r Registry) CounterFloat64 {
|
||||||
if nil == r {
|
if nil == r {
|
||||||
r = DefaultRegistry
|
r = DefaultRegistry
|
||||||
}
|
}
|
||||||
r.Register(name, c)
|
_ = r.Register(name, c)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +73,7 @@ func NewRegisteredCounterFloat64Forced(name string, r Registry) CounterFloat64 {
|
||||||
if nil == r {
|
if nil == r {
|
||||||
r = DefaultRegistry
|
r = DefaultRegistry
|
||||||
}
|
}
|
||||||
r.Register(name, c)
|
_ = r.Register(name, c)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
@ -109,6 +109,7 @@ type NilCounterFloat64 struct{}
|
||||||
func (NilCounterFloat64) Clear() {}
|
func (NilCounterFloat64) Clear() {}
|
||||||
|
|
||||||
// Count is a no-op.
|
// Count is a no-op.
|
||||||
|
// nolint:goconst
|
||||||
func (NilCounterFloat64) Count() float64 { return 0.0 }
|
func (NilCounterFloat64) Count() float64 { return 0.0 }
|
||||||
|
|
||||||
// Dec is a no-op.
|
// Dec is a no-op.
|
||||||
|
|
|
||||||
|
|
@ -73,11 +73,13 @@ func TestCounterFloat64Dec2(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:goconst
|
||||||
func TestCounterFloat64Inc1(t *testing.T) {
|
func TestCounterFloat64Inc1(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
c := NewCounterFloat64()
|
c := NewCounterFloat64()
|
||||||
c.Inc(1.0)
|
c.Inc(1.0)
|
||||||
|
|
||||||
if count := c.Count(); count != 1.0 {
|
if count := c.Count(); count != 1.0 {
|
||||||
t.Errorf("c.Count(): 1.0 != %v\n", count)
|
t.Errorf("c.Count(): 1.0 != %v\n", count)
|
||||||
}
|
}
|
||||||
|
|
@ -117,11 +119,13 @@ func TestCounterFloat64Zero(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:goconst
|
||||||
func TestGetOrRegisterCounterFloat64(t *testing.T) {
|
func TestGetOrRegisterCounterFloat64(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
r := NewRegistry()
|
r := NewRegistry()
|
||||||
NewRegisteredCounterFloat64("foo", r).Inc(47.0)
|
NewRegisteredCounterFloat64("foo", r).Inc(47.0)
|
||||||
|
|
||||||
if c := GetOrRegisterCounterFloat64("foo", r); c.Count() != 47.0 {
|
if c := GetOrRegisterCounterFloat64("foo", r); c.Count() != 47.0 {
|
||||||
t.Fatal(c)
|
t.Fatal(c)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,20 +16,20 @@ func Syslog(r Registry, d time.Duration, w *syslog.Writer) {
|
||||||
r.Each(func(name string, i interface{}) {
|
r.Each(func(name string, i interface{}) {
|
||||||
switch metric := i.(type) {
|
switch metric := i.(type) {
|
||||||
case Counter:
|
case Counter:
|
||||||
w.Info(fmt.Sprintf("counter %s: count: %d", name, metric.Count()))
|
_ = w.Info(fmt.Sprintf("counter %s: count: %d", name, metric.Count()))
|
||||||
case CounterFloat64:
|
case CounterFloat64:
|
||||||
w.Info(fmt.Sprintf("counter %s: count: %f", name, metric.Count()))
|
_ = w.Info(fmt.Sprintf("counter %s: count: %f", name, metric.Count()))
|
||||||
case Gauge:
|
case Gauge:
|
||||||
w.Info(fmt.Sprintf("gauge %s: value: %d", name, metric.Value()))
|
_ = w.Info(fmt.Sprintf("gauge %s: value: %d", name, metric.Value()))
|
||||||
case GaugeFloat64:
|
case GaugeFloat64:
|
||||||
w.Info(fmt.Sprintf("gauge %s: value: %f", name, metric.Value()))
|
_ = w.Info(fmt.Sprintf("gauge %s: value: %f", name, metric.Value()))
|
||||||
case Healthcheck:
|
case Healthcheck:
|
||||||
metric.Check()
|
metric.Check()
|
||||||
w.Info(fmt.Sprintf("healthcheck %s: error: %v", name, metric.Error()))
|
_ = w.Info(fmt.Sprintf("healthcheck %s: error: %v", name, metric.Error()))
|
||||||
case Histogram:
|
case Histogram:
|
||||||
h := metric.Snapshot()
|
h := metric.Snapshot()
|
||||||
ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
|
ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
|
||||||
w.Info(fmt.Sprintf(
|
_ = w.Info(fmt.Sprintf(
|
||||||
"histogram %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f",
|
"histogram %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f",
|
||||||
name,
|
name,
|
||||||
h.Count(),
|
h.Count(),
|
||||||
|
|
@ -45,7 +45,7 @@ func Syslog(r Registry, d time.Duration, w *syslog.Writer) {
|
||||||
))
|
))
|
||||||
case Meter:
|
case Meter:
|
||||||
m := metric.Snapshot()
|
m := metric.Snapshot()
|
||||||
w.Info(fmt.Sprintf(
|
_ = w.Info(fmt.Sprintf(
|
||||||
"meter %s: count: %d 1-min: %.2f 5-min: %.2f 15-min: %.2f mean: %.2f",
|
"meter %s: count: %d 1-min: %.2f 5-min: %.2f 15-min: %.2f mean: %.2f",
|
||||||
name,
|
name,
|
||||||
m.Count(),
|
m.Count(),
|
||||||
|
|
@ -57,7 +57,7 @@ func Syslog(r Registry, d time.Duration, w *syslog.Writer) {
|
||||||
case Timer:
|
case Timer:
|
||||||
t := metric.Snapshot()
|
t := metric.Snapshot()
|
||||||
ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
|
ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
|
||||||
w.Info(fmt.Sprintf(
|
_ = w.Info(fmt.Sprintf(
|
||||||
"timer %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f 1-min: %.2f 5-min: %.2f 15-min: %.2f mean-rate: %.2f",
|
"timer %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f 1-min: %.2f 5-min: %.2f 15-min: %.2f mean-rate: %.2f",
|
||||||
name,
|
name,
|
||||||
t.Count(),
|
t.Count(),
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ func (n *pmp) AddMapping(protocol string, extport, intport int, name string, lif
|
||||||
// to the caller.
|
// to the caller.
|
||||||
if uint16(extport) != res.MappedExternalPort {
|
if uint16(extport) != res.MappedExternalPort {
|
||||||
// Destroy the mapping in NAT device.
|
// Destroy the mapping in NAT device.
|
||||||
n.c.AddPortMapping(strings.ToLower(protocol), intport, 0, 0)
|
_, _ = n.c.AddPortMapping(strings.ToLower(protocol), intport, 0, 0)
|
||||||
return fmt.Errorf("port %d already mapped to another address (%s)", extport, protocol)
|
return fmt.Errorf("port %d already mapped to another address (%s)", extport, protocol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -123,8 +123,8 @@ func TestIPTrackerForceGC(t *testing.T) {
|
||||||
for i := 0; i < 5*max; i++ {
|
for i := 0; i < 5*max; i++ {
|
||||||
e1 := make([]byte, 4)
|
e1 := make([]byte, 4)
|
||||||
e2 := make([]byte, 4)
|
e2 := make([]byte, 4)
|
||||||
crand.Read(e1)
|
_, _ = crand.Read(e1)
|
||||||
crand.Read(e2)
|
_, _ = crand.Read(e2)
|
||||||
it.AddStatement(string(e1), string(e2))
|
it.AddStatement(string(e1), string(e2))
|
||||||
it.AddContact(string(e1))
|
it.AddContact(string(e1))
|
||||||
clock.Run(rate)
|
clock.Run(rate)
|
||||||
|
|
|
||||||
|
|
@ -667,7 +667,7 @@ func (c *Client) read(codec ServerCodec) {
|
||||||
msgs, batch, err := codec.readBatch()
|
msgs, batch, err := codec.readBatch()
|
||||||
if _, ok := err.(*json.SyntaxError); ok {
|
if _, ok := err.(*json.SyntaxError); ok {
|
||||||
msg := errorMessage(&parseError{err.Error()})
|
msg := errorMessage(&parseError{err.Error()})
|
||||||
codec.writeJSON(context.Background(), msg, true)
|
_ = codec.writeJSON(context.Background(), msg, true)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.readErr <- err
|
c.readErr <- err
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ func (b *batchCallBuffer) doWrite(ctx context.Context, conn jsonWriter, isErrorR
|
||||||
b.wrote = true // can only write once
|
b.wrote = true // can only write once
|
||||||
|
|
||||||
if len(b.resp) > 0 {
|
if len(b.resp) > 0 {
|
||||||
conn.writeJSON(ctx, b.resp, isErrorResponse)
|
_ = conn.writeJSON(ctx, b.resp, isErrorResponse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,7 +177,7 @@ func (h *handler) handleBatch(msgs []*jsonrpcMessage) {
|
||||||
if len(msgs) == 0 {
|
if len(msgs) == 0 {
|
||||||
h.startCallProc(func(cp *callProc) {
|
h.startCallProc(func(cp *callProc) {
|
||||||
resp := errorMessage(&invalidRequestError{"empty batch"})
|
resp := errorMessage(&invalidRequestError{"empty batch"})
|
||||||
h.conn.writeJSON(cp.ctx, resp, true)
|
_ = h.conn.writeJSON(cp.ctx, resp, true)
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -258,7 +258,7 @@ func (h *handler) handleMsg(msg *jsonrpcMessage) {
|
||||||
cancel()
|
cancel()
|
||||||
responded.Do(func() {
|
responded.Do(func() {
|
||||||
resp := msg.errorResponse(&internalServerError{errcodeTimeout, errMsgTimeout})
|
resp := msg.errorResponse(&internalServerError{errcodeTimeout, errMsgTimeout})
|
||||||
h.conn.writeJSON(cp.ctx, resp, true)
|
_ = h.conn.writeJSON(cp.ctx, resp, true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -270,11 +270,11 @@ func (h *handler) handleMsg(msg *jsonrpcMessage) {
|
||||||
h.addSubscriptions(cp.notifiers)
|
h.addSubscriptions(cp.notifiers)
|
||||||
if answer != nil {
|
if answer != nil {
|
||||||
responded.Do(func() {
|
responded.Do(func() {
|
||||||
h.conn.writeJSON(cp.ctx, answer, false)
|
_ = h.conn.writeJSON(cp.ctx, answer, false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for _, n := range cp.notifiers {
|
for _, n := range cp.notifiers {
|
||||||
n.activate()
|
_ = n.activate()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ func (s *Server) serveSingleRequest(ctx context.Context, codec ServerCodec) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
resp := errorMessage(&invalidMessageError{"parse error"})
|
resp := errorMessage(&invalidMessageError{"parse error"})
|
||||||
codec.writeJSON(ctx, resp, true)
|
_ = codec.writeJSON(ctx, resp, true)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ const (
|
||||||
// Returned errors:
|
// Returned errors:
|
||||||
// - an invalid block number error when the given argument isn't a known strings
|
// - an invalid block number error when the given argument isn't a known strings
|
||||||
// - an out of range error when the given block number is either too little or too large
|
// - an out of range error when the given block number is either too little or too large
|
||||||
|
// nolint:goconst
|
||||||
func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
|
func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
|
||||||
input := strings.TrimSpace(string(data))
|
input := strings.TrimSpace(string(data))
|
||||||
if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' {
|
if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue