Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
})
Expand Down Expand Up @@ -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)
}
}
Expand Down