Skip to content

Commit

Permalink
improved undefined reason for object method
Browse files Browse the repository at this point in the history
  • Loading branch information
seborama committed May 11, 2024
1 parent 64f7759 commit dda1df2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion object.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func ObjectGetMethod(obj Object, name string) (FunctionalValue, bool) { //nolint
value := reflect.ValueOf(obj)
if value.IsZero() || !value.IsValid() {
return func(...Value) Value {
return NewUndefinedWithReasonf("object is nil for type '%T' or does not have a method '%s'", obj, name)
return NewUndefinedWithReasonf("object is nil for type '%T' or does not have a method '%s' (check if it has a pointer receiver)", obj, name)
}, false
}

Expand Down
2 changes: 1 addition & 1 deletion object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestObjectGetMethod(t *testing.T) {

val, ok := gal.ObjectGetMethod(nilCar, "Ignite")
require.False(t, ok)
assert.Equal(t, "undefined: object is nil for type '*gal_test.Car' or does not have a method 'Ignite'", val().String())
assert.Equal(t, "undefined: object is nil for type '*gal_test.Car' or does not have a method 'Ignite' (check if it has a pointer receiver)", val().String())

val, ok = gal.ObjectGetMethod(myCar, "DoesNotExist!")
require.False(t, ok)
Expand Down

0 comments on commit dda1df2

Please sign in to comment.