-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert.NoError have unexpected behavior #1298
Comments
I'm not able to reproduce your problem: https://go.dev/play/p/V2YQ2_ozEKc Can you share a minimal recreate? |
Here it is : https://go.dev/play/p/sciEHYfC7dv Is the nil assignation is done to an interface variable, it's fine. But when the nil assignation is done to an object that fits the error interface, there is a problem. It is still nil, you can't call .Error() on it. |
This one better explain my point https://go.dev/play/p/sX_e79lX2H7 Thanks for your time ! I appreciate. |
Apologies if I've not understood you properly, I could really use an example of a test that fails but you expect to pass. You are expecting a non-nil error that contains a nil pointer to indicate "no error", according to the specification that is not correct. The panic when you call |
We both understand what's going on. I think there is two way of seeing it. As you said, and I agree, an interface pointing to a struct that is nil should not be equal to nil because it isn't. I was expecting assert.Nil to take care of this situation. About the NoError, I was expecting it to return false if there is no Error in the chain. If you consider it right, I'm pretty fine with that and I thank you for your time and patience. My mindset is build on the way that I learned Go : If you are checking an interface{} for nil value, make sure you look at its value with reflect.ValueOf('interface').IsNil(). Thank you again and you may close this issue as you please. |
I agree with @brackendawson.
|
Hi !
I just had issue with a custom made error struct because of a nil pointer.
If I use
assert.NoError
passing a nil pointer, it will fail.error
being an interface, you should check fornil underlying values
.Here is the sandbox to explain the issue : https://go.dev/play/p/03adogriDwB
References : https://go.dev/tour/methods/12
Solution : in the file assertion.go, line #1381-1396
If you want me to open a pull-request for this quick fix, just let me know.
Thanks !
The text was updated successfully, but these errors were encountered: