Skip to content

Commit

Permalink
tpl/collections: Improve error message in Index
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Feb 8, 2023
1 parent d33a7eb commit 9af78d1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tpl/collections/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ import (
//
// We deviate from the stdlib mostly because of https://github.com/golang/go/issues/14751.
func (ns *Namespace) Index(item any, args ...any) (any, error) {
v, err := ns.doIndex(item, args...)
if err != nil {
return nil, fmt.Errorf("index of type %T with args %v failed: %s", item, args, err)
}
return v, nil
}

func (ns *Namespace) doIndex(item any, args ...any) (any, error) {
// TODO(moorereason): merge upstream changes.
v := reflect.ValueOf(item)
if !v.IsValid() {
Expand Down

0 comments on commit 9af78d1

Please sign in to comment.