Skip to content

Commit 2937ff8

Browse files
committed
chore!: deprecate ErrNotFound and alias to github.com/ipld/go-ipld-prime/storage.ErrNotFound
1 parent cd97e05 commit 2937ff8

File tree

6 files changed

+58
-61
lines changed

6 files changed

+58
-61
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
@@ -23,7 +23,7 @@ func TestDecode(t *testing.T) {
2323
id, err := cid.Prefix{
2424
Version: 1,
2525
Codec: cid.Raw,
26-
MhType: mh.ID,
26+
MhType: mh.IDENTITY,
2727
MhLength: 0,
2828
}.Sum(nil)
2929

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: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@ module github.com/ipfs/go-ipld-format
22

33
require (
44
github.com/ipfs/go-block-format v0.0.2
5-
github.com/ipfs/go-cid v0.0.2
6-
github.com/multiformats/go-multihash v0.0.1
5+
github.com/ipfs/go-cid v0.4.0
6+
github.com/ipld/go-ipld-prime v0.20.1-0.20230328042852-d5ef532e7f32
7+
github.com/multiformats/go-multihash v0.2.1
78
)
89

910
require (
10-
github.com/gxed/hashland/keccakpg v0.0.1 // indirect
11-
github.com/gxed/hashland/murmur3 v0.0.1 // indirect
1211
github.com/ipfs/go-ipfs-util v0.0.1 // indirect
13-
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
14-
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 // indirect
15-
github.com/mr-tron/base58 v1.1.0 // indirect
12+
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
13+
github.com/minio/sha256-simd v1.0.0 // indirect
14+
github.com/mr-tron/base58 v1.2.0 // indirect
1615
github.com/multiformats/go-base32 v0.0.3 // indirect
17-
github.com/multiformats/go-multibase v0.0.1 // indirect
18-
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 // indirect
19-
golang.org/x/sys v0.0.0-20190219092855-153ac476189d // indirect
16+
github.com/multiformats/go-base36 v0.1.0 // indirect
17+
github.com/multiformats/go-multibase v0.0.3 // indirect
18+
github.com/multiformats/go-varint v0.0.6 // indirect
19+
github.com/spaolacci/murmur3 v1.1.0 // indirect
20+
golang.org/x/crypto v0.1.0 // indirect
21+
golang.org/x/sys v0.1.0 // indirect
22+
lukechampine.com/blake3 v1.1.6 // indirect
2023
)
2124

2225
go 1.19

go.sum

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
1-
github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU=
21
github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU=
3-
github.com/gxed/hashland/murmur3 v0.0.1 h1:SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJu4ZbSc=
42
github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48=
53
github.com/ipfs/go-block-format v0.0.2 h1:qPDvcP19izTjU8rgo6p7gTXZlkMkF5bz5G3fqIsSCPE=
64
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
75
github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
8-
github.com/ipfs/go-cid v0.0.2 h1:tuuKaZPU1M6HcejsO3AcYWW8sZ8MTvyxfc4uqB4eFE8=
9-
github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
6+
github.com/ipfs/go-cid v0.4.0 h1:a4pdZq0sx6ZSxbCizebnKiMCx/xI/aBBFlB73IgH4rA=
7+
github.com/ipfs/go-cid v0.4.0/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
108
github.com/ipfs/go-ipfs-util v0.0.1 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv50=
119
github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc=
12-
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
10+
github.com/ipld/go-ipld-prime v0.20.1-0.20230328042852-d5ef532e7f32 h1:G27WaHJCyVFnCicciPXIIjBr2O92IphfnZLrsqWFZ20=
11+
github.com/ipld/go-ipld-prime v0.20.1-0.20230328042852-d5ef532e7f32/go.mod h1:wmOtdy70ajP48iZITH8uLsGJVMqA4EJM61/bSfYYGhs=
12+
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
13+
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
14+
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
1315
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
14-
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ=
1516
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
16-
github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ=
17+
github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g=
18+
github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM=
1719
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
20+
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
21+
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
1822
github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI=
1923
github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA=
20-
github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmrJR+ubhT9qA=
24+
github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4=
25+
github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM=
2126
github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs=
22-
github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ=
27+
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk=
28+
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
2329
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=
30+
github.com/multiformats/go-multihash v0.2.1 h1:aem8ZT0VA2nCHHk7bPJ1BjUbHNciqZC/d16Vve9l108=
31+
github.com/multiformats/go-multihash v0.2.1/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc=
32+
github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2W/KhfNY=
33+
github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
34+
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
35+
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
2536
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
26-
golang.org/x/sys v0.0.0-20190219092855-153ac476189d h1:Z0Ahzd7HltpJtjAHHxX8QFP3j1yYgiuvjbjRzDj/KH0=
37+
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
38+
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
2739
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
40+
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
41+
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
42+
lukechampine.com/blake3 v1.1.6 h1:H3cROdztr7RCfoaTpGZFQsrqvweFLrqS73j7L7cmR5c=
43+
lukechampine.com/blake3 v1.1.6/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA=

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)