Commit 3a229598 authored by Eric Myhre's avatar Eric Myhre

ErrNotExists uses PathSegment; use in more places.

ipldfree.Node is now a much better implementation of Node.

In particular, this means it will work correctly when combined with the
typed.Node wrapper implementations which expect to be able to use
ErrNotExists for logic purposes.
Signed-off-by: default avatarEric Myhre <hash@exultant.us>
parent c157126c
......@@ -49,7 +49,7 @@ func (e ErrWrongKind) Error() string {
// a field can *never* exist (as differentiated from a map key which is
// simply absent in some data).
type ErrNotExists struct {
Segment string // REVIEW: might be better to use PathSegment, but depends on another refactor.
Segment PathSegment
}
func (e ErrNotExists) Error() string {
......
......@@ -158,7 +158,7 @@ func (n *Node) LookupString(pth string) (ipld.Node, error) {
case ipld.ReprKind_Map:
v, exists := n._map[pth]
if !exists {
return nil, fmt.Errorf("404")
return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(pth)}
}
return v, nil
case ipld.ReprKind_Invalid,
......@@ -184,7 +184,7 @@ func (n *Node) Lookup(key ipld.Node) (ipld.Node, error) {
}
v, exists := n._map[ks]
if !exists {
return nil, fmt.Errorf("404")
return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(ks)}
}
return v, nil
default:
......@@ -196,10 +196,10 @@ func (n *Node) LookupIndex(idx int) (ipld.Node, error) {
switch n.kind {
case ipld.ReprKind_List:
if idx >= len(n._arr) {
return nil, fmt.Errorf("404")
return nil, ipld.ErrNotExists{ipld.PathSegmentOfInt(idx)}
}
if n._arr[idx] == nil {
return nil, fmt.Errorf("404")
return nil, ipld.ErrNotExists{ipld.PathSegmentOfInt(idx)}
}
return n._arr[idx], nil
case ipld.ReprKind_Invalid,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment