Skip to content

Commit 7f024d7

Browse files
committed
chore!: deprecate ErrNotFound and alias to github.com/ipld/go-ipld-prime/storage.ErrNotFound
1 parent 07b3870 commit 7f024d7

File tree

6 files changed

+22
-46
lines changed

6 files changed

+22
-46
lines changed

batch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (d *testDag) Get(ctx context.Context, cid cid.Cid) (Node, error) {
2626
if n, ok := d.nodes[cid.KeyString()]; ok {
2727
return n, nil
2828
}
29-
return nil, ErrNotFound{cid}
29+
return nil, ErrNotFound{Key: cid.KeyString()}
3030
}
3131

3232
func (d *testDag) GetMany(ctx context.Context, cids []cid.Cid) <-chan *NodeOption {
@@ -37,7 +37,7 @@ func (d *testDag) GetMany(ctx context.Context, cids []cid.Cid) <-chan *NodeOptio
3737
if n, ok := d.nodes[c.KeyString()]; ok {
3838
out <- &NodeOption{Node: n}
3939
} else {
40-
out <- &NodeOption{Err: ErrNotFound{c}}
40+
out <- &NodeOption{Err: ErrNotFound{Key: c.KeyString()}}
4141
}
4242
}
4343
close(out)

coding_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestDecode(t *testing.T) {
2121
id, err := cid.Prefix{
2222
Version: 1,
2323
Codec: cid.Raw,
24-
MhType: mh.ID,
24+
MhType: mh.IDENTITY,
2525
MhLength: 0,
2626
}.Sum(nil)
2727

format_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (n *EmptyNode) Cid() cid.Cid {
3232
id, err := cid.Prefix{
3333
Version: 1,
3434
Codec: cid.Raw,
35-
MhType: mh.ID,
35+
MhType: mh.IDENTITY,
3636
MhLength: 0,
3737
}.Sum(nil)
3838

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ require (
1515
github.com/mr-tron/base58 v1.1.0 // indirect
1616
github.com/multiformats/go-base32 v0.0.3 // indirect
1717
github.com/multiformats/go-multibase v0.0.1 // indirect
18-
golang.org/x/crypto v0.1.0 // indirect
19-
golang.org/x/sys v0.1.0 // indirect
18+
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 // indirect
19+
golang.org/x/sys v0.0.0-20190219092855-153ac476189d // indirect
2020
)
2121

2222
go 1.19

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmr
2121
github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs=
2222
github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ=
2323
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
24+
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
2425
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
25-
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
26-
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
26+
golang.org/x/sys v0.0.0-20190219092855-153ac476189d h1:Z0Ahzd7HltpJtjAHHxX8QFP3j1yYgiuvjbjRzDj/KH0=
2727
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
28-
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
29-
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

merkledag.go

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,31 @@ import (
44
"context"
55

66
cid "github.com/ipfs/go-cid"
7+
"github.com/ipld/go-ipld-prime/storage"
78
)
89

910
// ErrNotFound is used to signal when a Node could not be found. The specific
1011
// meaning will depend on the DAGService implementation, which may be trying
1112
// to read nodes locally but also, trying to find them remotely.
1213
//
13-
// The Cid field can be filled in to provide additional context.
14-
type ErrNotFound struct {
15-
Cid cid.Cid
16-
}
17-
18-
// Error implements the error interface and returns a human-readable
19-
// message for this error.
20-
func (e ErrNotFound) Error() string {
21-
if e.Cid == cid.Undef {
22-
return "ipld: could not find node"
23-
}
24-
25-
return "ipld: could not find " + e.Cid.String()
26-
}
27-
28-
// Is allows to check whether any error is of this ErrNotFound type.
29-
// Do not use this directly, but rather errors.Is(yourError, ErrNotFound).
30-
// For maximum compatibility you should prefer IsNotFound() instead as it will
31-
// also match other compatible NotFound error types.
32-
func (e ErrNotFound) Is(err error) bool {
33-
switch err.(type) {
34-
case ErrNotFound:
35-
return true
36-
default:
37-
return false
38-
}
39-
}
40-
41-
// NotFound returns true.
42-
func (e ErrNotFound) NotFound() bool {
43-
return true
44-
}
14+
// Deprecated: use github.com/ipld/go-ipld-prime/storage#ErrNotFound instead.
15+
type ErrNotFound = storage.ErrNotFound
4516

4617
// IsNotFound returns true if the error is a ErrNotFound. As it uses a
4718
// feature-test, it is also compatible with other NotFound error types,
4819
// including github.com/ipld/go-ipld-prime/storage#ErrNotFound.
20+
//
21+
// errors.Is() should be preferred as the standard Go way to test for errors;
22+
// however due to the move of the legacy ErrNotFound to
23+
// github.com/ipld/go-ipld-prime/storage, it may not report correctly where
24+
// older block storage packages emit the legacy ErrNotFound. The IsNotFound()
25+
// function provides a maximally compatible matching function that should be
26+
// able to determine whether an ErrNotFound, either new or legacy, exists within
27+
// a wrapped error chain.
28+
//
29+
// Deprecated: use github.com/ipld/go-ipld-prime/storage#IsNotFound instead.
4930
func IsNotFound(err error) bool {
50-
if nf, ok := err.(interface{ NotFound() bool }); ok {
51-
return nf.NotFound()
52-
}
53-
return false
31+
return storage.IsNotFound(err)
5432
}
5533

5634
// Either a node or an error.

0 commit comments

Comments
 (0)