From 29dbed35ed7a42a3acb53747d669458f44b54d82 Mon Sep 17 00:00:00 2001 From: James Batt Date: Sat, 16 Apr 2022 17:24:54 +1000 Subject: [PATCH 1/2] nil handling for Call() --- container.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/container.go b/container.go index c3537a0..6f6ac44 100644 --- a/container.go +++ b/container.go @@ -150,6 +150,9 @@ func (c Container) Call(function interface{}) error { if len(result) == 0 { return nil } else if len(result) == 1 && result[0].CanInterface() { + if result[0].IsNil() { + return nil + } if err, ok := result[0].Interface().(error); ok { return err } From 454e34a917114bfe268e146403f0e3af6acb8d3e Mon Sep 17 00:00:00 2001 From: James Batt Date: Sat, 16 Apr 2022 17:28:46 +1000 Subject: [PATCH 2/2] added a testcase --- container_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/container_test.go b/container_test.go index 8d968ca..448f1da 100644 --- a/container_test.go +++ b/container_test.go @@ -223,6 +223,20 @@ func TestContainer_Call_With_A_Returning_Error(t *testing.T) { assert.EqualError(t, err, "app: some context error") } +func TestContainer_Call_With_A_Returning_Nil_Error(t *testing.T) { + instance.Reset() + + err := instance.Singleton(func() Shape { + return &Circle{} + }) + assert.NoError(t, err) + + err = instance.Call(func(s Shape) error { + return nil + }) + assert.Nil(t, err) +} + func TestContainer_Call_With_Invalid_Signature(t *testing.T) { instance.Reset()