diff --git a/core/errorx/atomicerror.go b/core/errorx/atomicerror.go index bc52d54c..2a3db80e 100644 --- a/core/errorx/atomicerror.go +++ b/core/errorx/atomicerror.go @@ -9,7 +9,9 @@ type AtomicError struct { // Set sets the error. func (ae *AtomicError) Set(err error) { - ae.err.Store(err) + if err != nil { + ae.err.Store(err) + } } // Load returns the error. diff --git a/core/errorx/atomicerror_test.go b/core/errorx/atomicerror_test.go index d05f8866..10c7b44d 100644 --- a/core/errorx/atomicerror_test.go +++ b/core/errorx/atomicerror_test.go @@ -17,6 +17,15 @@ func TestAtomicError(t *testing.T) { assert.Equal(t, errDummy, err.Load()) } +func TestAtomicErrorSetNil(t *testing.T) { + var ( + errNil error + err AtomicError + ) + err.Set(errNil) + assert.Equal(t, errNil, err.Load()) +} + func TestAtomicErrorNil(t *testing.T) { var err AtomicError assert.Nil(t, err.Load())