diff --git a/request.go b/request.go index f665857..d94eeeb 100644 --- a/request.go +++ b/request.go @@ -430,7 +430,7 @@ func unmarshalAttribute( // As a final catch-all, ensure types line up to avoid a runtime panic. if fieldValue.Kind() != value.Kind() { - err = ErrInvalidType + err = fmt.Errorf("%w: %s is of type %s, cannot set %s", ErrInvalidType, structField.Name, fieldValue.Type().String(), value.Type().String()) return } diff --git a/request_test.go b/request_test.go index 300c7de..71c6554 100644 --- a/request_test.go +++ b/request_test.go @@ -281,14 +281,13 @@ func TestUnmarshalInvalidJSON_BadType(t *testing.T) { out := new(ModelBadTypes) in := map[string]interface{}{} in[test.Field] = test.BadValue - expectedErrorMessage := test.Error.Error() err := UnmarshalPayload(samplePayloadWithBadTypes(in), out) if err == nil { t.Fatalf("Expected error due to invalid type.") } - if err.Error() != expectedErrorMessage { + if !errors.Is(err, test.Error) { t.Fatalf("Unexpected error message: %s", err.Error()) } }) @@ -959,7 +958,7 @@ func TestUnmarshalCustomTypeAttributes_ErrInvalidType(t *testing.T) { t.Fatal("Expected an error unmarshalling the payload due to type mismatch, got none") } - if err != ErrInvalidType { + if !errors.Is(err, ErrInvalidType) { t.Fatalf("Expected error to be %v, was %v", ErrInvalidType, err) } }