fix AtomicError panic when Set nil (#1049) (#1050)

master
NevS 3 years ago committed by GitHub
parent 2e12cd2c99
commit 004ee488a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,8 +9,10 @@ type AtomicError struct {
// Set sets the error. // Set sets the error.
func (ae *AtomicError) Set(err error) { func (ae *AtomicError) Set(err error) {
if err != nil {
ae.err.Store(err) ae.err.Store(err)
} }
}
// Load returns the error. // Load returns the error.
func (ae *AtomicError) Load() error { func (ae *AtomicError) Load() error {

@ -17,6 +17,15 @@ func TestAtomicError(t *testing.T) {
assert.Equal(t, errDummy, err.Load()) 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) { func TestAtomicErrorNil(t *testing.T) {
var err AtomicError var err AtomicError
assert.Nil(t, err.Load()) assert.Nil(t, err.Load())

Loading…
Cancel
Save