Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use errors method to check equivalence #925

Merged
merged 1 commit into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions protocol/chainsync/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error {
}
}
if callbackErr != nil {
if callbackErr == StopSyncProcessError {
if errors.Is(callbackErr, StopSyncProcessError) {
// Signal that we're cancelling the sync
c.readyForNextBlockChan <- false
return nil
Expand Down Expand Up @@ -751,7 +751,7 @@ func (c *Client) handleRollBackward(msg protocol.Message) error {
}
// Call the user callback function
if callbackErr := c.config.RollBackwardFunc(c.callbackContext, msgRollBackward.Point, msgRollBackward.Tip); callbackErr != nil {
if callbackErr == StopSyncProcessError {
if errors.Is(callbackErr, StopSyncProcessError) {
// Signal that we're cancelling the sync
c.readyForNextBlockChan <- false
return nil
Expand Down
5 changes: 3 additions & 2 deletions protocol/chainsync/client_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
package chainsync_test

import (
"errors"
"fmt"
"reflect"
"testing"
Expand Down Expand Up @@ -127,7 +128,7 @@ func TestIntersectNotFound(t *testing.T) {
if err == nil {
t.Fatalf("did not receive expected error")
}
if err != chainsync.IntersectNotFoundError {
if !errors.Is(err, chainsync.IntersectNotFoundError) {
t.Fatalf(
"did not receive expected error\n got: %s\n wanted: %s",
err,
Expand Down
2 changes: 1 addition & 1 deletion protocol/chainsync/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (s *Server) handleFindIntersect(msg protocol.Message) error {
msgFindIntersect.Points,
)
if err != nil {
if err == IntersectNotFoundError {
if errors.Is(err, IntersectNotFoundError) {
msgResp := NewMsgIntersectNotFound(tip)
if err := s.SendMessage(msgResp); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (p *Protocol) recvLoop() {
tmpMsg := []cbor.RawMessage{}
numBytesRead, err := cbor.Decode(recvBuffer.Bytes(), &tmpMsg)
if err != nil {
if err == io.ErrUnexpectedEOF && recvBuffer.Len() > 0 {
if errors.Is(err, io.ErrUnexpectedEOF) && recvBuffer.Len() > 0 {
// This is probably a multi-part message, so we wait until we get more of the message
// before trying to process it
p.recvReadyChan <- true
Expand Down