diff --git a/callbacks.go b/callbacks.go index c84f215c..1df975d8 100644 --- a/callbacks.go +++ b/callbacks.go @@ -81,7 +81,7 @@ func callFunction(f reflect.Value, bindings bindings) error { return err } ferr := out[0] - if ferrv := reflect.ValueOf(ferr); !ferrv.IsValid() || ferrv.IsNil() { + if ferrv := reflect.ValueOf(ferr); !ferrv.IsValid() || ((ferrv.Kind() == reflect.Interface || ferrv.Kind() == reflect.Pointer) && ferrv.IsNil()) { return nil } return ferr.(error) //nolint:forcetypeassert diff --git a/options_test.go b/options_test.go index f6971f8e..e549475c 100644 --- a/options_test.go +++ b/options_test.go @@ -127,3 +127,22 @@ func TestFlagNamer(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "SOMEFLAG", app.Model.Flags[1].Name) } + +type npError string + +func (e npError) Error() string { + return "ERROR: " + string(e) +} + +func TestCallbackNonPointerError(t *testing.T) { + method := func() error { + return npError("failed") + } + + var cli struct{} + + p, err := New(&cli) + assert.NoError(t, err) + err = callFunction(reflect.ValueOf(method), p.bindings) + assert.EqualError(t, err, "ERROR: failed") +}