-
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 behaves unexpectedly with nil struct #562
Comments
@dominicbarnes Since you're returning |
@dominicbarnes as @devdinu mentions (thanks!), the issue is a bug in the example. That is a common gotcha from Go. Closing. |
I am running into the same issue as well and forced to use
But then it requires type casting to the custom error type to take advantage it e.g to access fields in the custom error struct. |
Yes, if you wanna propagate information through custom error type, the you've to typecast it in the caller side. Idiomatic way suggested to use errors as values. |
That common gotcha is explained there: https://golang.org/doc/faq#nil_error Adding this link since people still ask about it. |
…y when a nil error struct is supplied
…y when a nil error struct is supplied
We have some internal functions that return a struct dedicated to wrapping customer-facing errors, and thus have more to it than the standard
error
interface. To enforce that we use these structs everywhere, as we want to, we're returning our custom*errors.Error
type instead oferror
.However, when passing the returned value to
assert.NoError(t, err)
it will always indicate an error, even when the value isnil
. Our type implementsError()
, so it can be passed places thaterror
is expected, so testify's behavior here feels like a bug.This looks like an edge-case in the way that
nil
values are being detected, and the workaround for now is to userequire.Nil(t, err)
but I have been usingNoError()
for a long time elsewhere and will probably forget at some point. 😛The text was updated successfully, but these errors were encountered: