mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
Fix additional errcheck and type errors
- Fix error handling in rpc, log, customtypes, customrawdb packages - Fix rlp.Split return value count (4 not 3) - Fix client.EthSubscribe return value count (2 not 1) - Update test files to properly handle errors
This commit is contained in:
@@ -96,7 +96,7 @@ func (tt *TestCmd) Run(name string, args ...string) {
|
||||
//
|
||||
// geth.expect(`Passphrase: {{.InputLine "password"}}`)
|
||||
func (tt *TestCmd) InputLine(s string) string {
|
||||
io.WriteString(tt.stdin, s+"\n")
|
||||
_, _ = io.WriteString(tt.stdin, s+"\n")
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -199,7 +199,7 @@ func (l *logger) Write(level slog.Level, msg string, attrs ...any) {
|
||||
}
|
||||
r := slog.NewRecord(time.Now(), level, msg, pcs[0])
|
||||
r.Add(attrs...)
|
||||
l.inner.Handler().Handle(context.Background(), r)
|
||||
_ = l.inner.Handler().Handle(context.Background(), r)
|
||||
}
|
||||
|
||||
func (l *logger) Log(level slog.Level, msg string, attrs ...any) {
|
||||
|
||||
@@ -51,7 +51,7 @@ func DeleteBloombits(db ethdb.Database, start, end uint64) {
|
||||
binary.BigEndian.PutUint64(key[4:12], section)
|
||||
copy(key[12:], head[:])
|
||||
|
||||
db.Delete(key)
|
||||
_ = db.Delete(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func WriteBlockGasCost(db ethdb.KeyValueWriter, hash common.Hash, number uint64,
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
db.Put(key, data)
|
||||
_ = db.Put(key, data)
|
||||
}
|
||||
|
||||
// ReadBlockGasCost reads the BlockGasCost for a header from its separate key.
|
||||
|
||||
@@ -55,8 +55,8 @@ func TestEIP2718DeriveSha(t *testing.T) {
|
||||
} {
|
||||
d := &hashToHumanReadable{}
|
||||
var t1, t2 types.Transaction
|
||||
rlp.DecodeBytes(common.FromHex(tc.rlpData), &t1)
|
||||
rlp.DecodeBytes(common.FromHex(tc.rlpData), &t2)
|
||||
_ = rlp.DecodeBytes(common.FromHex(tc.rlpData), &t1)
|
||||
_ = rlp.DecodeBytes(common.FromHex(tc.rlpData), &t2)
|
||||
txs := types.Transactions{&t1, &t2}
|
||||
types.DeriveSha(txs, d)
|
||||
if tc.exp != string(d.data) {
|
||||
|
||||
@@ -259,7 +259,7 @@ func (h *HeaderSerializable) Hash() common.Hash {
|
||||
// rlpHash encodes x and hashes the encoded bytes.
|
||||
func rlpHash(x interface{}) (h common.Hash) {
|
||||
hw := crypto.NewKeccakState()
|
||||
rlp.Encode(hw, x)
|
||||
_ = rlp.Encode(hw, x)
|
||||
hw.Sum(h[:0])
|
||||
return h
|
||||
}
|
||||
|
||||
@@ -65,11 +65,11 @@ func fuzzRlp(t *testing.T, input []byte) {
|
||||
if len(input) == 0 || len(input) > 500*1024 {
|
||||
return
|
||||
}
|
||||
rlp.Split(input)
|
||||
_, _, _, _ = rlp.Split(input)
|
||||
if elems, _, err := rlp.SplitList(input); err == nil {
|
||||
rlp.CountValues(elems)
|
||||
_, _ = rlp.CountValues(elems)
|
||||
}
|
||||
rlp.NewStream(bytes.NewReader(input), 0).Decode(new(interface{}))
|
||||
_ = rlp.NewStream(bytes.NewReader(input), 0).Decode(new(interface{}))
|
||||
if err := decodeEncode(input, new(interface{})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func benchRLP(b *testing.B, encode bool) {
|
||||
b.ReportAllocs()
|
||||
var null = &devnull{}
|
||||
for i := 0; i < b.N; i++ {
|
||||
rlp.Encode(null, tc.obj)
|
||||
_ = rlp.Encode(null, tc.obj)
|
||||
}
|
||||
b.SetBytes(int64(null.len / b.N))
|
||||
})
|
||||
|
||||
@@ -45,7 +45,8 @@ func TestState(t *testing.T) {
|
||||
IsActive: true,
|
||||
IsL1Validator: true,
|
||||
}
|
||||
state.AddValidator(vdr)
|
||||
err = state.AddValidator(vdr)
|
||||
require.NoError(err)
|
||||
|
||||
// adding the same validator should fail
|
||||
err = state.AddValidator(vdr)
|
||||
|
||||
+5
-5
@@ -422,7 +422,7 @@ func TestClientSubscribeInvalidArg(t *testing.T) {
|
||||
t.Error(string(buf))
|
||||
}
|
||||
}()
|
||||
client.EthSubscribe(context.Background(), arg, "foo_bar")
|
||||
_, _ = client.EthSubscribe(context.Background(), arg, "foo_bar")
|
||||
}
|
||||
check(true, nil)
|
||||
check(true, 1)
|
||||
@@ -560,7 +560,7 @@ func TestClientSubscriptionUnsubscribeServer(t *testing.T) {
|
||||
|
||||
// Create the server.
|
||||
srv := NewServer(0)
|
||||
srv.RegisterName("nftest", new(notificationTestService))
|
||||
_ = srv.RegisterName("nftest", new(notificationTestService))
|
||||
p1, p2 := net.Pipe()
|
||||
recorder := &unsubscribeRecorder{ServerCodec: NewCodec(p1)}
|
||||
go srv.ServeCodec(recorder, OptionMethodInvocation|OptionSubscriptions, 0, 0, 0)
|
||||
@@ -603,7 +603,7 @@ func TestClientSubscriptionChannelClose(t *testing.T) {
|
||||
defer srv.Stop()
|
||||
defer httpsrv.Close()
|
||||
|
||||
srv.RegisterName("nftest", new(notificationTestService))
|
||||
_ = srv.RegisterName("nftest", new(notificationTestService))
|
||||
client, _ := Dial(wsURL)
|
||||
defer client.Close()
|
||||
|
||||
@@ -758,7 +758,7 @@ func TestClientReconnect(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal("can't listen:", err)
|
||||
}
|
||||
go http.Serve(l, srv.WebsocketHandler([]string{"*"}))
|
||||
go func() { _ = http.Serve(l, srv.WebsocketHandler([]string{"*"})) }()
|
||||
return srv, l
|
||||
}
|
||||
|
||||
@@ -794,7 +794,7 @@ func TestClientReconnect(t *testing.T) {
|
||||
// Start it up again and call again. The connection should be reestablished.
|
||||
// We spawn multiple calls here to check whether this hangs somehow.
|
||||
s2, l2 := startServer(l1.Addr().String())
|
||||
defer l2.Close()
|
||||
defer func() { _ = l2.Close() }()
|
||||
defer s2.Stop()
|
||||
|
||||
start := make(chan struct{})
|
||||
|
||||
+7
-7
@@ -180,7 +180,7 @@ func (b *batchCallBuffer) doWrite(ctx context.Context, conn jsonWriter, isErrorR
|
||||
}
|
||||
b.wrote = true // can only write once
|
||||
if len(b.resp) > 0 {
|
||||
conn.writeJSONSkipDeadline(ctx, b.resp, isErrorResponse, true)
|
||||
_ = conn.writeJSONSkipDeadline(ctx, b.resp, isErrorResponse, true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ func (h *handler) handleBatch(msgs []*jsonrpcMessage) {
|
||||
if len(msgs) == 0 {
|
||||
h.startCallProc(func(cp *callProc) {
|
||||
resp := errorMessage(&invalidRequestError{"empty batch"})
|
||||
h.conn.writeJSONSkipDeadline(cp.ctx, resp, true, h.deadlineContext > 0)
|
||||
_ = h.conn.writeJSONSkipDeadline(cp.ctx, resp, true, h.deadlineContext > 0)
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -272,7 +272,7 @@ func (h *handler) handleBatch(msgs []*jsonrpcMessage) {
|
||||
h.addSubscriptions(cp.notifiers)
|
||||
callBuffer.write(cp.ctx, h.conn)
|
||||
for _, n := range cp.notifiers {
|
||||
n.activate()
|
||||
_ = n.activate()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -288,7 +288,7 @@ func (h *handler) respondWithBatchTooLarge(cp *callProc, batch []*jsonrpcMessage
|
||||
break
|
||||
}
|
||||
}
|
||||
h.conn.writeJSONSkipDeadline(cp.ctx, []*jsonrpcMessage{resp}, true, h.deadlineContext > 0)
|
||||
_ = h.conn.writeJSONSkipDeadline(cp.ctx, []*jsonrpcMessage{resp}, true, h.deadlineContext > 0)
|
||||
}
|
||||
|
||||
// handleMsg handles a single non-batch message.
|
||||
@@ -318,7 +318,7 @@ func (h *handler) handleNonBatchCall(cp *callProc, msg *jsonrpcMessage) {
|
||||
cancel()
|
||||
responded.Do(func() {
|
||||
resp := msg.errorResponse(&internalServerError{errcodeTimeout, errMsgTimeout})
|
||||
h.conn.writeJSONSkipDeadline(cp.ctx, resp, true, h.deadlineContext > 0)
|
||||
_ = h.conn.writeJSONSkipDeadline(cp.ctx, resp, true, h.deadlineContext > 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -330,11 +330,11 @@ func (h *handler) handleNonBatchCall(cp *callProc, msg *jsonrpcMessage) {
|
||||
h.addSubscriptions(cp.notifiers)
|
||||
if answer != nil {
|
||||
responded.Do(func() {
|
||||
h.conn.writeJSONSkipDeadline(cp.ctx, answer, false, h.deadlineContext > 0)
|
||||
_ = h.conn.writeJSONSkipDeadline(cp.ctx, answer, false, h.deadlineContext > 0)
|
||||
})
|
||||
}
|
||||
for _, n := range cp.notifiers {
|
||||
n.activate()
|
||||
_ = n.activate()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ func TestHTTPRespBodyUnlimited(t *testing.T) {
|
||||
|
||||
s := NewServer(0)
|
||||
defer s.Stop()
|
||||
s.RegisterName("test", largeRespService{respLength})
|
||||
_ = s.RegisterName("test", largeRespService{respLength})
|
||||
ts := httptest.NewServer(s)
|
||||
defer ts.Close()
|
||||
|
||||
|
||||
+3
-3
@@ -273,7 +273,7 @@ func (c *jsonCodec) writeJSONSkipDeadline(ctx context.Context, v interface{}, is
|
||||
deadline = deadlineCtx
|
||||
}
|
||||
}
|
||||
c.conn.SetWriteDeadline(deadline)
|
||||
_ = c.conn.SetWriteDeadline(deadline)
|
||||
return c.encode(v, isErrorResponse)
|
||||
}
|
||||
|
||||
@@ -300,11 +300,11 @@ func parseMessage(raw json.RawMessage) ([]*jsonrpcMessage, bool) {
|
||||
return msgs, false
|
||||
}
|
||||
dec := json.NewDecoder(bytes.NewReader(raw))
|
||||
dec.Token() // skip '['
|
||||
_, _ = dec.Token() // skip '['
|
||||
var msgs []*jsonrpcMessage
|
||||
for dec.More() {
|
||||
msgs = append(msgs, new(jsonrpcMessage))
|
||||
dec.Decode(&msgs[len(msgs)-1])
|
||||
_ = dec.Decode(&msgs[len(msgs)-1])
|
||||
}
|
||||
return msgs, true
|
||||
}
|
||||
|
||||
+2
-2
@@ -82,7 +82,7 @@ func NewServer(maximumDuration time.Duration) *Server {
|
||||
// Register the default service providing meta information about the RPC service such
|
||||
// as the services and methods it offers.
|
||||
rpcService := &RPCService{server}
|
||||
server.RegisterName(MetadataApi, rpcService)
|
||||
_ = server.RegisterName(MetadataApi, rpcService)
|
||||
return server
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func (s *Server) serveSingleRequest(ctx context.Context, codec ServerCodec) {
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
resp := errorMessage(&invalidMessageError{"parse error"})
|
||||
codec.writeJSON(ctx, resp, true)
|
||||
_ = codec.writeJSON(ctx, resp, true)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
+3
-3
@@ -88,7 +88,7 @@ func runTestScript(t *testing.T, file string) {
|
||||
}
|
||||
|
||||
clientConn, serverConn := net.Pipe()
|
||||
defer clientConn.Close()
|
||||
defer func() { _ = clientConn.Close() }()
|
||||
go server.ServeCodec(NewCodec(serverConn), 0, 0, 0, 0)
|
||||
readbuf := bufio.NewReader(clientConn)
|
||||
for _, line := range strings.Split(string(content), "\n") {
|
||||
@@ -100,7 +100,7 @@ func runTestScript(t *testing.T, file string) {
|
||||
case strings.HasPrefix(line, "--> "):
|
||||
t.Log(line)
|
||||
// write to connection
|
||||
clientConn.SetWriteDeadline(time.Now().Add(5 * time.Second))
|
||||
_ = clientConn.SetWriteDeadline(time.Now().Add(5 * time.Second))
|
||||
if _, err := io.WriteString(clientConn, line[4:]+"\n"); err != nil {
|
||||
t.Fatalf("write error: %v", err)
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func runTestScript(t *testing.T, file string) {
|
||||
t.Log(line)
|
||||
want := line[4:]
|
||||
// read line from connection and compare text
|
||||
clientConn.SetReadDeadline(time.Now().Add(5 * time.Second))
|
||||
_ = clientConn.SetReadDeadline(time.Now().Add(5 * time.Second))
|
||||
sent, err := readbuf.ReadString('\n')
|
||||
if err != nil {
|
||||
t.Fatalf("read error: %v", err)
|
||||
|
||||
+1
-1
@@ -316,7 +316,7 @@ func (sub *ClientSubscription) run() {
|
||||
|
||||
// Call the unsubscribe method on the server.
|
||||
if unsubscribe {
|
||||
sub.requestUnsubscribe()
|
||||
_ = sub.requestUnsubscribe()
|
||||
}
|
||||
|
||||
// Send the error.
|
||||
|
||||
@@ -147,7 +147,7 @@ func TestSubscriptions(t *testing.T) {
|
||||
// This test checks that unsubscribing works.
|
||||
func TestServerUnsubscribe(t *testing.T) {
|
||||
p1, p2 := net.Pipe()
|
||||
defer p2.Close()
|
||||
defer func() { _ = p2.Close() }()
|
||||
|
||||
// Start the server.
|
||||
server := newTestServer()
|
||||
|
||||
Reference in New Issue
Block a user