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

cmp/cmpopts: use errors.Is with ≥go1.13 in compareErrors #251

Merged
merged 1 commit into from Feb 5, 2021

Conversation

tklauser
Copy link
Contributor

@tklauser tklauser commented Feb 4, 2021

Use the standard definition of errors.Is to implement compareErrors with
≥go1.13. Retain the implementation using golang.org/x/xerrors for versions <go1.13.

This will allow packages using newer Go versions and already relying on
the errors package to get rid of the transitive dependency on
golang.org/x/xerrors.

@tklauser
Copy link
Contributor Author

tklauser commented Feb 4, 2021

I see that previously #225 and #243 attempted to get rid of the golang.org/x/xerrors as well. However it looks like these weren't accepted based on the fact that they broke cmp for Go versions older than 1.13, while this PR retains compatibility for older versions.

cmp/cmpopts/errors_go113.go Outdated Show resolved Hide resolved
cmp/cmpopts/errors_xerrors.go Outdated Show resolved Hide resolved
@dsnet
Copy link
Collaborator

dsnet commented Feb 4, 2021

What's the effect of this PR on the go.mod file?

Use the standard definition of errors.Is to implement compareErrors with
≥go1.13. Retain the implementation using golang.org/x/xerrors for versions <go1.13.

This will allow packages using newer Go versions and already relying on
the errors package to get rid of the transitive dependency on
golang.org/x/xerrors.
@tklauser
Copy link
Contributor Author

tklauser commented Feb 4, 2021

What's the effect of this PR on the go.mod file?

As far as I can tell there will be no effect on the go.mod file because cmp/cmpopts/util_test.go still uses xerrors unconditionally. Running go mod tidy doesn't change go.mod or go.sum.

However, a package importing cmp which uses go1 .13 or newer in go.mod should no longer see an indirect dependency on xerrors.

@dsnet
Copy link
Collaborator

dsnet commented Feb 4, 2021

The presence of xerrors in the go.mod file is unfortunate especially since older versions of Go (which is why the dependency even needs to exist) don't use Go modules.

Anyways, I agree this change in a step in the direction we want to go.

@dsnet dsnet merged commit 3a98a11 into google:master Feb 5, 2021
@tklauser tklauser deleted the go-1.13-use-stdlib-errors branch February 5, 2021 07:28
This was referenced Mar 6, 2021
This was referenced Mar 8, 2021
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 this pull request may close these issues.

None yet

2 participants