Skip to content

Commit 0183256

Browse files
gballetfjl
andauthored
all: fix warning flagging the use of DeepEqual on error (ethereum#23624)
* core: fix warning flagging the use of DeepEqual on error * apply the same change everywhere possible * revert change that was committed by mistake * fix build error * Update config.go * revert changes to ConfigCompatError * review feedback Co-authored-by: Felix Lange <[email protected]>
1 parent 84d8eb2 commit 0183256

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

Diff for: p2p/discover/v5wire/encoding_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import (
2020
"bytes"
2121
"crypto/ecdsa"
2222
"encoding/hex"
23+
"errors"
2324
"flag"
2425
"fmt"
2526
"io/ioutil"
2627
"net"
2728
"os"
2829
"path/filepath"
29-
"reflect"
3030
"strings"
3131
"testing"
3232

@@ -555,7 +555,7 @@ func (n *handshakeTestNode) expectDecode(t *testing.T, ptype byte, p []byte) Pac
555555

556556
func (n *handshakeTestNode) expectDecodeErr(t *testing.T, wantErr error, p []byte) {
557557
t.Helper()
558-
if _, err := n.decode(p); !reflect.DeepEqual(err, wantErr) {
558+
if _, err := n.decode(p); !errors.Is(err, wantErr) {
559559
t.Fatal(fmt.Errorf("(%s) got err %q, want %q", n.ln.ID().TerminalString(), err, wantErr))
560560
}
561561
}

Diff for: p2p/server_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ func TestServerSetupConn(t *testing.T) {
370370
clientkey, srvkey = newkey(), newkey()
371371
clientpub = &clientkey.PublicKey
372372
srvpub = &srvkey.PublicKey
373+
fooErr = errors.New("foo")
374+
readErr = errors.New("read error")
373375
)
374376
tests := []struct {
375377
dontstart bool
@@ -387,10 +389,10 @@ func TestServerSetupConn(t *testing.T) {
387389
wantCloseErr: errServerStopped,
388390
},
389391
{
390-
tt: &setupTransport{pubkey: clientpub, encHandshakeErr: errors.New("read error")},
392+
tt: &setupTransport{pubkey: clientpub, encHandshakeErr: readErr},
391393
flags: inboundConn,
392394
wantCalls: "doEncHandshake,close,",
393-
wantCloseErr: errors.New("read error"),
395+
wantCloseErr: readErr,
394396
},
395397
{
396398
tt: &setupTransport{pubkey: clientpub, phs: protoHandshake{ID: randomID().Bytes()}},
@@ -400,11 +402,11 @@ func TestServerSetupConn(t *testing.T) {
400402
wantCloseErr: DiscUnexpectedIdentity,
401403
},
402404
{
403-
tt: &setupTransport{pubkey: clientpub, protoHandshakeErr: errors.New("foo")},
405+
tt: &setupTransport{pubkey: clientpub, protoHandshakeErr: fooErr},
404406
dialDest: enode.NewV4(clientpub, nil, 0, 0),
405407
flags: dynDialedConn,
406408
wantCalls: "doEncHandshake,doProtoHandshake,close,",
407-
wantCloseErr: errors.New("foo"),
409+
wantCloseErr: fooErr,
408410
},
409411
{
410412
tt: &setupTransport{pubkey: srvpub, phs: protoHandshake{ID: crypto.FromECDSAPub(srvpub)[1:]}},
@@ -443,7 +445,7 @@ func TestServerSetupConn(t *testing.T) {
443445
}
444446
p1, _ := net.Pipe()
445447
srv.SetupConn(p1, test.flags, test.dialDest)
446-
if !reflect.DeepEqual(test.tt.closeErr, test.wantCloseErr) {
448+
if !errors.Is(test.tt.closeErr, test.wantCloseErr) {
447449
t.Errorf("test %d: close error mismatch: got %q, want %q", i, test.tt.closeErr, test.wantCloseErr)
448450
}
449451
if test.tt.calls != test.wantCalls {

Diff for: rlp/raw_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package rlp
1818

1919
import (
2020
"bytes"
21+
"errors"
2122
"io"
22-
"reflect"
2323
"testing"
2424
"testing/quick"
2525
)
@@ -54,7 +54,7 @@ func TestCountValues(t *testing.T) {
5454
if count != test.count {
5555
t.Errorf("test %d: count mismatch, got %d want %d\ninput: %s", i, count, test.count, test.input)
5656
}
57-
if !reflect.DeepEqual(err, test.err) {
57+
if !errors.Is(err, test.err) {
5858
t.Errorf("test %d: err mismatch, got %q want %q\ninput: %s", i, err, test.err, test.input)
5959
}
6060
}

Diff for: rpc/websocket_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ package rpc
1818

1919
import (
2020
"context"
21+
"errors"
2122
"io"
2223
"net"
2324
"net/http"
2425
"net/http/httptest"
2526
"net/http/httputil"
2627
"net/url"
27-
"reflect"
2828
"strings"
2929
"sync/atomic"
3030
"testing"
@@ -69,7 +69,7 @@ func TestWebsocketOriginCheck(t *testing.T) {
6969
t.Fatal("no error for wrong origin")
7070
}
7171
wantErr := wsHandshakeError{websocket.ErrBadHandshake, "403 Forbidden"}
72-
if !reflect.DeepEqual(err, wantErr) {
72+
if !errors.Is(err, wantErr) {
7373
t.Fatalf("wrong error for wrong origin: %q", err)
7474
}
7575

0 commit comments

Comments
 (0)