Skip to content

Commit

Permalink
basicnode: don't panic on negative index
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed Sep 1, 2024
1 parent 40c3462 commit 9070551
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions node/basicnode/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func (plainList) LookupByNode(datamodel.Node) (datamodel.Node, error) {
return mixins.List{TypeName: "list"}.LookupByNode(nil)
}
func (n *plainList) LookupByIndex(idx int64) (datamodel.Node, error) {
if idx < 0 {
return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)}
}

Check warning on line 36 in node/basicnode/list.go

View check run for this annotation

Codecov / codecov/patch

node/basicnode/list.go#L35-L36

Added lines #L35 - L36 were not covered by tests
if n.Length() <= idx {
return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)}
}
Expand Down

0 comments on commit 9070551

Please sign in to comment.