selector: workaround panic() go-ipld-prime with negative index

Waiting on https://github.com/ipld/go-ipld-prime/pull/571 to be released.
This commit is contained in:
Michael Muré
2024-09-02 18:08:49 +02:00
parent 3e40c1f16b
commit 4dd91f95f7

View File

@@ -183,6 +183,12 @@ func resolve(sel Selector, subject ipld.Node, at []string) (ipld.Node, []ipld.No
if idx < 0 {
idx = cur.Length() + idx
}
if idx < 0 {
// necessary until https://github.com/ipld/go-ipld-prime/pull/571
// after, isMissing() below will work
// TODO: remove
return nil, nil, newResolutionError(fmt.Sprintf("index out of bounds: %d", seg.Index()), at)
}
n, err := cur.LookupByIndex(idx)
if err != nil {
if isMissing(err) {