Skip to content

Commit b2c774a

Browse files
committed
make errors more easily checkable
1 parent 2612fdd commit b2c774a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

ipld.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func (se SerializationError) Unwrap() error {
6666
return se.err
6767
}
6868

69+
func (se SerializationError) Is(o error) bool {
70+
_, ok := o.(*SerializationError)
71+
return ok
72+
}
73+
6974
type blocks interface {
7075
GetBlock(context.Context, cid.Cid) (block.Block, error)
7176
AddBlock(block.Block) error

ipld_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package hamt
33
import (
44
"bytes"
55
"context"
6+
"fmt"
67
"testing"
78

89
cbg "github.com/whyrusleeping/cbor-gen"
10+
xerrors "golang.org/x/xerrors"
911

1012
cbor "github.com/ipfs/go-ipld-cbor"
1113
)
@@ -58,3 +60,11 @@ func TestBasicBytesLoading(t *testing.T) {
5860
t.Fatal("bytes round trip failed")
5961
}
6062
}
63+
64+
func TestIsSerializationError(t *testing.T) {
65+
serr := NewSerializationError(fmt.Errorf("i am a cat"))
66+
67+
if !xerrors.Is(serr, &SerializationError{}) {
68+
t.Fatal("its not a serialization error?")
69+
}
70+
}

0 commit comments

Comments
 (0)