@@ -4,53 +4,31 @@ import (
4
4
"context"
5
5
6
6
cid "github.com/ipfs/go-cid"
7
+ "github.com/ipld/go-ipld-prime/storage"
7
8
)
8
9
9
10
// ErrNotFound is used to signal when a Node could not be found. The specific
10
11
// meaning will depend on the DAGService implementation, which may be trying
11
12
// to read nodes locally but also, trying to find them remotely.
12
13
//
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
45
16
46
17
// IsNotFound returns true if the error is a ErrNotFound. As it uses a
47
18
// feature-test, it is also compatible with other NotFound error types,
48
19
// 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.
49
30
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 )
54
32
}
55
33
56
34
// Either a node or an error.
0 commit comments