Skip to content

Commit 3414003

Browse files
authored
fix: use errors method to check equivalence (#925)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent e0b5bab commit 3414003

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

protocol/chainsync/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error {
722722
}
723723
}
724724
if callbackErr != nil {
725-
if callbackErr == StopSyncProcessError {
725+
if errors.Is(callbackErr, StopSyncProcessError) {
726726
// Signal that we're cancelling the sync
727727
c.readyForNextBlockChan <- false
728728
return nil
@@ -751,7 +751,7 @@ func (c *Client) handleRollBackward(msg protocol.Message) error {
751751
}
752752
// Call the user callback function
753753
if callbackErr := c.config.RollBackwardFunc(c.callbackContext, msgRollBackward.Point, msgRollBackward.Tip); callbackErr != nil {
754-
if callbackErr == StopSyncProcessError {
754+
if errors.Is(callbackErr, StopSyncProcessError) {
755755
// Signal that we're cancelling the sync
756756
c.readyForNextBlockChan <- false
757757
return nil

protocol/chainsync/client_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
package chainsync_test
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
"reflect"
2021
"testing"
@@ -127,7 +128,7 @@ func TestIntersectNotFound(t *testing.T) {
127128
if err == nil {
128129
t.Fatalf("did not receive expected error")
129130
}
130-
if err != chainsync.IntersectNotFoundError {
131+
if !errors.Is(err, chainsync.IntersectNotFoundError) {
131132
t.Fatalf(
132133
"did not receive expected error\n got: %s\n wanted: %s",
133134
err,

protocol/chainsync/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func (s *Server) handleFindIntersect(msg protocol.Message) error {
203203
msgFindIntersect.Points,
204204
)
205205
if err != nil {
206-
if err == IntersectNotFoundError {
206+
if errors.Is(err, IntersectNotFoundError) {
207207
msgResp := NewMsgIntersectNotFound(tip)
208208
if err := s.SendMessage(msgResp); err != nil {
209209
return err

protocol/protocol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func (p *Protocol) recvLoop() {
363363
tmpMsg := []cbor.RawMessage{}
364364
numBytesRead, err := cbor.Decode(recvBuffer.Bytes(), &tmpMsg)
365365
if err != nil {
366-
if err == io.ErrUnexpectedEOF && recvBuffer.Len() > 0 {
366+
if errors.Is(err, io.ErrUnexpectedEOF) && recvBuffer.Len() > 0 {
367367
// This is probably a multi-part message, so we wait until we get more of the message
368368
// before trying to process it
369369
p.recvReadyChan <- true

0 commit comments

Comments
 (0)