Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ld-format
Commits
0ae16c84
Commit
0ae16c84
authored
Mar 23, 2020
by
Hector Sanjuan
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ErrNotFound: Make struct. Expose Cid field. Implement NotFound()
parent
d6515058
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
17 deletions
+19
-17
batch_test.go
batch_test.go
+4
-4
daghelpers.go
daghelpers.go
+1
-1
merkledag.go
merkledag.go
+14
-12
No files found.
batch_test.go
View file @
0ae16c84
...
...
@@ -26,7 +26,7 @@ func (d *testDag) Get(ctx context.Context, cid cid.Cid) (Node, error) {
if
n
,
ok
:=
d
.
nodes
[
cid
.
KeyString
()];
ok
{
return
n
,
nil
}
return
nil
,
ErrNotFound
Cid
{
cid
}
return
nil
,
ErrNotFound
{
cid
}
}
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
if
n
,
ok
:=
d
.
nodes
[
c
.
KeyString
()];
ok
{
out
<-
&
NodeOption
{
Node
:
n
}
}
else
{
out
<-
&
NodeOption
{
Err
:
ErrNotFound
Cid
{
c
}}
out
<-
&
NodeOption
{
Err
:
ErrNotFound
{
c
}}
}
}
close
(
out
)
...
...
@@ -157,11 +157,11 @@ func TestErrorTypes(t *testing.T) {
err2
:=
fmt
.
Errorf
(
"could not read: %w"
,
err
)
if
!
errors
.
Is
(
err
,
ErrNotFound
)
{
if
!
errors
.
Is
(
err
,
ErrNotFound
{}
)
{
t
.
Fatal
(
"should be an ErrNotFound"
)
}
if
!
errors
.
Is
(
err2
,
ErrNotFound
)
{
if
!
errors
.
Is
(
err2
,
ErrNotFound
{}
)
{
t
.
Fatal
(
"should be an ErrNotFound"
)
}
}
daghelpers.go
View file @
0ae16c84
...
...
@@ -61,7 +61,7 @@ func GetNodes(ctx context.Context, ds NodeGetter, keys []cid.Cid) []*NodePromise
case
opt
,
ok
:=
<-
nodechan
:
if
!
ok
{
for
_
,
p
:=
range
promises
{
p
.
Fail
(
ErrNotFound
)
p
.
Fail
(
ErrNotFound
{}
)
}
return
}
...
...
merkledag.go
View file @
0ae16c84
...
...
@@ -10,35 +10,37 @@ import (
// ErrNotFound is used to signal when a Node could not be found. The specific
// meaning will depend on the DAGService implementation, which may be trying
// to read nodes locally but also, trying to find them remotely.
var
ErrNotFound
=
ErrNotFoundCid
{}
// ErrNotFoundCid can be use to provide specific CID information in a NotFound
// error.
type
ErrNotFoundCid
struct
{
c
cid
.
Cid
//
// The Cid field can be filled in to provide additional context.
type
ErrNotFound
struct
{
Cid
cid
.
Cid
}
// Error implements the error interface and returns a human-readable
// message for this error.
func
(
e
ErrNotFound
Cid
)
Error
()
string
{
if
e
.
c
==
cid
.
Undef
{
func
(
e
ErrNotFound
)
Error
()
string
{
if
e
.
Cid
==
cid
.
Undef
{
return
"ipld: node not found"
}
return
fmt
.
Sprintf
(
"ipld: %s not found"
,
e
.
c
)
return
fmt
.
Sprintf
(
"ipld: %s not found"
,
e
.
Cid
)
}
// Is allows to check whether any error is of this ErrNotFound
Cid
type.
// Is allows to check whether any error is of this ErrNotFound type.
// Do not use this directly, but rather errors.Is(yourError, ErrNotFound).
func
(
e
ErrNotFound
Cid
)
Is
(
err
error
)
bool
{
func
(
e
ErrNotFound
)
Is
(
err
error
)
bool
{
switch
err
.
(
type
)
{
case
ErrNotFound
Cid
:
case
ErrNotFound
:
return
true
default
:
return
false
}
}
func
(
e
ErrNotFound
)
NotFound
()
bool
{
return
true
}
// Either a node or an error.
type
NodeOption
struct
{
Node
Node
...
...
tavit ohanian
@tavit
mentioned in commit
6a5fbeae
·
Apr 19, 2021
mentioned in commit
6a5fbeae
mentioned in commit 6a5fbeae4745f8c5f305d320a4e626756ff16279
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment