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

suggest cmpopts.EquateErrors in error comparison panic #233

Closed
neild opened this issue Aug 17, 2020 · 0 comments · Fixed by #234
Closed

suggest cmpopts.EquateErrors in error comparison panic #233

neild opened this issue Aug 17, 2020 · 0 comments · Fixed by #234

Comments

@neild
Copy link
Collaborator

neild commented Aug 17, 2020

This panics:

cmp.Equal(errors.New("x"), errors.New("x"))
panic: cannot handle unexported field at {*errors.errorString}.s:
	"errors".errorString
consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported

The panic could detect when the type being compared implements error and suggest using cmpopts.EquateErrors.

dsnet added a commit that referenced this issue Aug 18, 2020
If cmp panics because it is trying to access an unexported field,
specially suggest the use of cmpopts.EquateErrors if the parent type
implements the error interface.

Fixes #233
dsnet added a commit that referenced this issue Aug 18, 2020
If cmp panics because it is trying to access an unexported field,
specially suggest the use of cmpopts.EquateErrors if the parent type
implements the error interface.

Fixes #233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant