From 1536a0c407e000815ccef10665d81cef0c855cd1 Mon Sep 17 00:00:00 2001 From: "k.nakada" <36500782+ko30005@users.noreply.github.com> Date: Wed, 15 Jul 2020 02:35:29 +0900 Subject: [PATCH] Adjust panic for IgnoreUnexported and IgnoreFields (#228) Adjust the panic message to be more specific about what the user should do, and reduces the need for the user to look at the source code. --- cmp/cmpopts/ignore.go | 2 +- cmp/cmpopts/struct_filter.go | 2 +- cmp/cmpopts/util_test.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmp/cmpopts/ignore.go b/cmp/cmpopts/ignore.go index afd36be..48787dd 100644 --- a/cmp/cmpopts/ignore.go +++ b/cmp/cmpopts/ignore.go @@ -128,7 +128,7 @@ func newUnexportedFilter(typs ...interface{}) unexportedFilter { for _, typ := range typs { t := reflect.TypeOf(typ) if t == nil || t.Kind() != reflect.Struct { - panic(fmt.Sprintf("invalid struct type: %T", typ)) + panic(fmt.Sprintf("%T must be a non-pointer struct", typ)) } ux.m[t] = true } diff --git a/cmp/cmpopts/struct_filter.go b/cmp/cmpopts/struct_filter.go index dae7ced..fe8d1b9 100644 --- a/cmp/cmpopts/struct_filter.go +++ b/cmp/cmpopts/struct_filter.go @@ -42,7 +42,7 @@ func newStructFilter(typ interface{}, names ...string) structFilter { t := reflect.TypeOf(typ) if t == nil || t.Kind() != reflect.Struct { - panic(fmt.Sprintf("%T must be a struct", typ)) + panic(fmt.Sprintf("%T must be a non-pointer struct", typ)) } var ft fieldTree for _, name := range names { diff --git a/cmp/cmpopts/util_test.go b/cmp/cmpopts/util_test.go index 37704c8..9e96632 100644 --- a/cmp/cmpopts/util_test.go +++ b/cmp/cmpopts/util_test.go @@ -1223,7 +1223,7 @@ func TestPanic(t *testing.T) { label: "IgnoreFields", fnc: IgnoreFields, args: args(&Foo1{}, "Alpha"), - wantPanic: "must be a struct", + wantPanic: "must be a non-pointer struct", reason: "the type must be a struct (not pointer to a struct)", }, { label: "IgnoreFields", @@ -1304,13 +1304,13 @@ func TestPanic(t *testing.T) { label: "IgnoreUnexported", fnc: IgnoreUnexported, args: args(nil), - wantPanic: "invalid struct type", + wantPanic: "must be a non-pointer struct", reason: "input must not be nil value", }, { label: "IgnoreUnexported", fnc: IgnoreUnexported, args: args(&Foo1{}), - wantPanic: "invalid struct type", + wantPanic: "must be a non-pointer struct", reason: "input must be a struct type (not a pointer to a struct)", }, { label: "IgnoreUnexported",