Skip to content
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

cmd/vet: warn for reflect.DeepEqual on errors #16748

zombiezen opened this issue Aug 16, 2016 · 2 comments


None yet
4 participants
Copy link

commented Aug 16, 2016

A common antipattern I see in production code is using reflect.DeepEqual on errors in tests, which results in brittle tests. Even just adding more diagnostic information to the error can break it. The more proper thing to do is either:

  1. Check whether a substring is present in the error message (not great, but more correct).
  2. Use something like Dave Cheney's errors package to make the system-under-test provide more useful errors (great! because it's better API design anyway).

It would be helpful to have a vet check that discourages this.

(cc @dsnet)


This comment has been minimized.

Copy link

commented Aug 16, 2016

To be more specific, this is a check that warns if either a or b in reflect.DeepEqual(a, b) is of the error type.

If they are structs that contain a field of an error type, no warning is given. While I would consider using deep equal in that case a code smell, there are legitimate uses of it when it is used to compare sentinel errors.


This comment has been minimized.

Copy link

commented Aug 17, 2016

This is not a correctness issue, so it is not a vet problem. Perhaps golint should do this, but not vet.

@robpike robpike closed this Aug 17, 2016

@golang golang locked and limited conversation to collaborators Aug 17, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.