From f129c4f8ea2ea01ea93b08324e1897bd0ea728da Mon Sep 17 00:00:00 2001 From: Felix Sun Date: Wed, 25 Sep 2019 15:36:14 +0800 Subject: [PATCH] MustGet print the error field name if no such field --- get.go | 2 +- set.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/get.go b/get.go index afd8a83..46870b5 100644 --- a/get.go +++ b/get.go @@ -11,7 +11,7 @@ func MustGet(i interface{}, name string) (value interface{}) { var err error value, err = Get(i, name) if err != nil { - panic(err) + panic(fmt.Sprintf("%s: %s of %+v", err, name, i)) } return } diff --git a/set.go b/set.go index f44d133..5f14240 100644 --- a/set.go +++ b/set.go @@ -27,7 +27,7 @@ import ( "strings" ) -var NoSuchFieldError = errors.New("no such field.") +var NoSuchFieldError = errors.New("no such field") // Set value of a struct by path using reflect. func Set(i interface{}, name string, value interface{}) (err error) {