mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
tpl/collections: Improve error message in Index
This commit is contained in:
parent
d33a7ebcc1
commit
9af78d1100
1 changed files with 8 additions and 0 deletions
|
@ -31,6 +31,14 @@ import (
|
||||||
//
|
//
|
||||||
// We deviate from the stdlib mostly because of https://github.com/golang/go/issues/14751.
|
// 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) {
|
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.
|
// TODO(moorereason): merge upstream changes.
|
||||||
v := reflect.ValueOf(item)
|
v := reflect.ValueOf(item)
|
||||||
if !v.IsValid() {
|
if !v.IsValid() {
|
||||||
|
|
Loading…
Reference in a new issue