Skip to content

Commit

Permalink
Improve ErrNotFound
Browse files Browse the repository at this point in the history
Work with ipld.ErrNotFounds.
  • Loading branch information
hsanjuan committed Mar 2, 2022
1 parent 437cdd8 commit 4c7f7bf
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion dagutils/diffenum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestDiffEnumFail(t *testing.T) {
}

err := DiffEnumerate(ctx, lgds, nds["a1"].Cid(), nds["a2"].Cid())
if err != ipld.ErrNotFound {
if !ipld.IsNotFound(err) {
t.Fatal("expected err not found")
}

Expand Down
6 changes: 3 additions & 3 deletions dagutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (e *Editor) insertNodeAtPath(ctx context.Context, root *dag.ProtoNode, path
if err == dag.ErrLinkNotFound && create != nil {
nd = create()
err = nil // no longer an error case
} else if err == ipld.ErrNotFound {
} else if ipld.IsNotFound(err) {
// try finding it in our source dagstore
nd, err = root.GetLinkedProtoNode(ctx, e.src, path[0])
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func (e *Editor) rmLink(ctx context.Context, root *dag.ProtoNode, path []string)

// search for node in both tmp dagstore and source dagstore
nd, err := root.GetLinkedProtoNode(ctx, e.tmp, path[0])
if err == ipld.ErrNotFound {
if ipld.IsNotFound(err) {
nd, err = root.GetLinkedProtoNode(ctx, e.src, path[0])
}

Expand Down Expand Up @@ -217,7 +217,7 @@ func copyDag(ctx context.Context, nd ipld.Node, from, to ipld.DAGService) error
for _, lnk := range nd.Links() {
child, err := lnk.GetNode(ctx, from)
if err != nil {
if err == ipld.ErrNotFound {
if ipld.IsNotFound(err) {
// not found means we didnt modify it, and it should
// already be in the target datastore
continue
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/ipfs/go-merkledag
require (
github.com/gogo/protobuf v1.3.2
github.com/ipfs/go-block-format v0.0.3
github.com/ipfs/go-blockservice v0.2.1
github.com/ipfs/go-blockservice v0.2.2-0.20220302144055-931fbecb724e
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.5.0
github.com/ipfs/go-ipfs-blockstore v0.2.1
github.com/ipfs/go-ipfs-exchange-offline v0.1.1
github.com/ipfs/go-ipfs-blockstore v1.1.3-0.20220302142350-af197de1c3da
github.com/ipfs/go-ipfs-exchange-offline v0.1.2-0.20220302144615-a919970e8153
github.com/ipfs/go-ipfs-util v0.0.2
github.com/ipfs/go-ipld-cbor v0.0.5
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-ipld-format v0.2.1-0.20220302134852-d02e0e18fc65
github.com/ipfs/go-ipld-legacy v0.1.0
github.com/ipld/go-codec-dagpb v1.3.0
github.com/ipld/go-ipld-prime v0.11.0
Expand Down
20 changes: 12 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/go-bitswap v0.5.1 h1:721YAEDBnLIrvcIMkCHCdqp34hA8jwL9yKMkyJpSpco=
github.com/ipfs/go-bitswap v0.5.1/go.mod h1:P+ckC87ri1xFLvk74NlXdP0Kj9RmWAh4+H78sC6Qopo=
github.com/ipfs/go-bitswap v0.5.2-0.20220302142610-595ae6937936 h1:1Ps0PF7jFKqO8/QwHaFvwCpQ0AITuYSbOI50gts3OiM=
github.com/ipfs/go-bitswap v0.5.2-0.20220302142610-595ae6937936/go.mod h1:Ro9XYuNUQxtx/YIZm+OA5mEnADStr5fyowhSUIgZtaU=
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
github.com/ipfs/go-block-format v0.0.3 h1:r8t66QstRp/pd/or4dpnbVfXT5Gt7lOqRvC+/dDTpMc=
github.com/ipfs/go-block-format v0.0.3/go.mod h1:4LmD4ZUw0mhO+JSKdpWwrzATiEfM7WWgQ8H5l6P8MVk=
github.com/ipfs/go-blockservice v0.2.1 h1:NJ4j/cwEfIg60rzAWcCIxRtOwbf6ZPK49MewNxObCPQ=
github.com/ipfs/go-blockservice v0.2.1/go.mod h1:k6SiwmgyYgs4M/qt+ww6amPeUH9EISLRBnvUurKJhi8=
github.com/ipfs/go-blockservice v0.2.2-0.20220302144055-931fbecb724e h1:Nqyg2HAa7lS19g6N7UTpbiJQFHKSO7yp+DvcqY4iBFk=
github.com/ipfs/go-blockservice v0.2.2-0.20220302144055-931fbecb724e/go.mod h1:0rezJNcrjTA32XEEXiV/DQAztHZrVduLb7GiktRq6lg=
github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
Expand All @@ -280,19 +280,22 @@ github.com/ipfs/go-ds-badger v0.2.3/go.mod h1:pEYw0rgg3FIrywKKnL+Snr+w/LjJZVMTBR
github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc=
github.com/ipfs/go-ds-leveldb v0.4.1/go.mod h1:jpbku/YqBSsBc1qgME8BkWS4AxzF2cEu1Ii2r79Hh9s=
github.com/ipfs/go-ds-leveldb v0.4.2/go.mod h1:jpbku/YqBSsBc1qgME8BkWS4AxzF2cEu1Ii2r79Hh9s=
github.com/ipfs/go-ipfs-blockstore v0.2.1 h1:624eIDnkZWNdWbp/N8aDBOUtSY0YW75aJu+vbxnNlkA=
github.com/ipfs/go-ipfs-blockstore v0.2.1/go.mod h1:jGesd8EtCM3/zPgx+qr0/feTXGUeRai6adgwC+Q+JvE=
github.com/ipfs/go-ipfs-blockstore v1.1.3-0.20220302142350-af197de1c3da h1:/TU6rnYvsuKOwqpWxQXtO/K1Uj7IYY2GFE0WUr4Gh2Y=
github.com/ipfs/go-ipfs-blockstore v1.1.3-0.20220302142350-af197de1c3da/go.mod h1:dFOiy6XAxbK5x1Jvx7OAO1rQsrcyHxaXdTLWN085QoE=
github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ=
github.com/ipfs/go-ipfs-blocksutil v0.0.1/go.mod h1:Yq4M86uIOmxmGPUHv/uI7uKqZNtLb449gwKqXjIsnRk=
github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
github.com/ipfs/go-ipfs-delay v0.0.1 h1:r/UXYyRcddO6thwOnhiznIAiSvxMECGgtv35Xs1IeRQ=
github.com/ipfs/go-ipfs-delay v0.0.1/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
github.com/ipfs/go-ipfs-ds-help v0.1.1 h1:IW/bXGeaAZV2VH0Kuok+Ohva/zHkHmeLFBxC1k7mNPc=
github.com/ipfs/go-ipfs-ds-help v0.1.1/go.mod h1:SbBafGJuGsPI/QL3j9Fc5YPLeAu+SzOkI0gFwAg+mOs=
github.com/ipfs/go-ipfs-ds-help v1.1.0 h1:yLE2w9RAsl31LtfMt91tRZcrx+e61O5mDxFRR994w4Q=
github.com/ipfs/go-ipfs-ds-help v1.1.0/go.mod h1:YR5+6EaebOhfcqVCyqemItCLthrpVNot+rsOU/5IatU=
github.com/ipfs/go-ipfs-exchange-interface v0.1.0 h1:TiMekCrOGQuWYtZO3mf4YJXDIdNgnKWZ9IE3fGlnWfo=
github.com/ipfs/go-ipfs-exchange-interface v0.1.0/go.mod h1:ych7WPlyHqFvCi/uQI48zLZuAWVP5iTQPXEfVaw5WEI=
github.com/ipfs/go-ipfs-exchange-offline v0.1.1 h1:mEiXWdbMN6C7vtDG21Fphx8TGCbZPpQnz/496w/PL4g=
github.com/ipfs/go-ipfs-exchange-offline v0.1.1/go.mod h1:vTiBRIbzSwDD0OWm+i3xeT0mO7jG2cbJYatp3HPk5XY=
github.com/ipfs/go-ipfs-exchange-offline v0.1.2-0.20220302144615-a919970e8153 h1:GtLORXk45GpVMfhPz+IyZ9YNAe36BQ+rKZvem5Bo49Y=
github.com/ipfs/go-ipfs-exchange-offline v0.1.2-0.20220302144615-a919970e8153/go.mod h1:fjwwh1LDdR2LrZ0qYeDbWx4pgdTq+Tw48YaLBjCS2qk=
github.com/ipfs/go-ipfs-pq v0.0.2 h1:e1vOOW6MuOwG2lqxcLA+wEn93i/9laCY8sXAw76jFOY=
github.com/ipfs/go-ipfs-pq v0.0.2/go.mod h1:LWIqQpqfRG3fNc5XsnIhz/wQ2XXGyugQwls7BgUmUfY=
github.com/ipfs/go-ipfs-routing v0.2.1 h1:E+whHWhJkdN9YeoHZNj5itzc+OR292AJ2uE9FFiW0BY=
Expand All @@ -303,8 +306,9 @@ github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdr
github.com/ipfs/go-ipld-cbor v0.0.5 h1:ovz4CHKogtG2KB/h1zUp5U0c/IzZrL435rCh5+K/5G8=
github.com/ipfs/go-ipld-cbor v0.0.5/go.mod h1:BkCduEx3XBCO6t2Sfo5BaHzuok7hbhdMm9Oh8B2Ftq4=
github.com/ipfs/go-ipld-format v0.0.1/go.mod h1:kyJtbkDALmFHv3QR6et67i35QzO3S0dCDnkOJhcZkms=
github.com/ipfs/go-ipld-format v0.2.0 h1:xGlJKkArkmBvowr+GMCX0FEZtkro71K1AwiKnL37mwA=
github.com/ipfs/go-ipld-format v0.2.0/go.mod h1:3l3C1uKoadTPbeNfrDi+xMInYKlx2Cvg1BuydPSdzQs=
github.com/ipfs/go-ipld-format v0.2.1-0.20220302134852-d02e0e18fc65 h1:xxnD+fUS7hziDAnfrn3qsl0ql18DOjq4rwvzBTCr1iA=
github.com/ipfs/go-ipld-format v0.2.1-0.20220302134852-d02e0e18fc65/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM=
github.com/ipfs/go-ipld-legacy v0.1.0 h1:wxkkc4k8cnvIGIjPO0waJCe7SHEyFgl+yQdafdjGrpA=
github.com/ipfs/go-ipld-legacy v0.1.0/go.mod h1:86f5P/srAmh9GcIcWQR9lfFLZPrIyyXQeVlOWeeWEuI=
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
Expand Down
20 changes: 5 additions & 15 deletions merkledag.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ func (n *dagService) Get(ctx context.Context, c cid.Cid) (format.Node, error) {

b, err := n.Blocks.GetBlock(ctx, c)
if err != nil {
if err == bserv.ErrNotFound {
return nil, format.ErrNotFound
}
return nil, fmt.Errorf("failed to get block for %s: %v", c, err)
return nil, err
}

return legacy.DecodeNode(ctx, b)
Expand Down Expand Up @@ -127,9 +124,6 @@ func GetLinksDirect(serv format.NodeGetter) GetLinks {
return func(ctx context.Context, c cid.Cid) ([]*format.Link, error) {
nd, err := serv.Get(ctx, c)
if err != nil {
if err == bserv.ErrNotFound {
err = format.ErrNotFound
}
return nil, err
}
return nd.Links(), nil
Expand All @@ -143,12 +137,8 @@ type sesGetter struct {
// Get gets a single node from the DAG.
func (sg *sesGetter) Get(ctx context.Context, c cid.Cid) (format.Node, error) {
blk, err := sg.bs.GetBlock(ctx, c)
switch err {
case bserv.ErrNotFound:
return nil, format.ErrNotFound
case nil:
// noop
default:

if err != nil {
return nil, err
}

Expand Down Expand Up @@ -358,7 +348,7 @@ func IgnoreErrors() WalkOption {
func IgnoreMissing() WalkOption {
return func(walkOptions *walkOptions) {
walkOptions.addHandler(func(c cid.Cid, err error) error {
if err == format.ErrNotFound {
if format.IsNotFound(err) {
return nil
}
return err
Expand All @@ -371,7 +361,7 @@ func IgnoreMissing() WalkOption {
func OnMissing(callback func(c cid.Cid)) WalkOption {
return func(walkOptions *walkOptions) {
walkOptions.addHandler(func(c cid.Cid, err error) error {
if err == format.ErrNotFound {
if format.IsNotFound(err) {
callback(c)
}
return err
Expand Down
2 changes: 1 addition & 1 deletion readonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestReadonlyProperties(t *testing.T) {
t.Fatal("expected ErrReadOnly")
}

if _, err := ro.Get(ctx, cids[0]); err != ipld.ErrNotFound {
if _, err := ro.Get(ctx, cids[0]); !ipld.IsNotFound(err) {
t.Fatal("expected ErrNotFound")
}
if _, err := ro.Get(ctx, cids[3]); err != nil {
Expand Down

0 comments on commit 4c7f7bf

Please sign in to comment.