From 9af78d11003ed22b6281e47e1ac19568cf1cca81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 8 Feb 2023 10:22:20 +0100 Subject: [PATCH] tpl/collections: Improve error message in Index --- tpl/collections/index.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tpl/collections/index.go b/tpl/collections/index.go index d72d3748f..e4362fdc3 100644 --- a/tpl/collections/index.go +++ b/tpl/collections/index.go @@ -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() {