testify icon indicating copy to clipboard operation
testify copied to clipboard

#562: assert.NoError() and assert.Error() now behave correctly when a nil error struct is supplied

Open e-nikolov opened this issue 6 years ago • 4 comments
trafficstars

Fixes #562

assert.Nil already does this correctly by checking via reflection if the supplied value isn't nil wrapped in an interface in order to not give false results. I think assert.NoError should do the same.

e-nikolov avatar Oct 03 '19 13:10 e-nikolov

I can imagine that this could be considered as breaking backwards compatibility, so perhaps there could be new functions to do this instead of modifying the behaviour of the existing ones. But I think it's quite useful to be able to use something like assert.NoError(err) on custom error types.

Perhaps something like this:

assert.NoCustomError(err) assert.CustomError(err)

e-nikolov avatar Oct 03 '19 13:10 e-nikolov

Could you please add a unit test covering the use-case you're solving? If I understand correctly, this change only fixes for the following scenario:

type MyCustomError {
    err error
}

a := MyCustomError{err=nil}

?

boyan-soubachov avatar Jun 01 '20 10:06 boyan-soubachov

Any plans to merge this change?

ronaknnathani avatar Jan 08 '24 15:01 ronaknnathani

Looks like bad change leading to implicit bugs. @dolmen I propose to close this PR

Antonboom avatar Jan 08 '24 18:01 Antonboom

#562 is invalid. This patch will break correct behaviour instead of fixing.

Thanks @Antonboom for review.

dolmen avatar Mar 06 '24 01:03 dolmen