-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Use errors.Is
for error equality checks
#18576
Comments
Hi @ianlancetaylor, Thanks for raising this issue. We aim to have the main branch working with the latest Go version released. When a new minor is released. We work to adopt the new version (refer to issues like #18443 and #18548) and plan/log the work in a version bump issue. Thanks for raising awareness about comparing errors with I think the best action item for this issue is to close it for now, as we'll work on the Go 1.24.0 update when it gets released. Thanks again, Ian. |
We discussed this issue and #18510 in our fortnightly etcd triage meeting. We'll keep this issue open and use it as an umbrella to track the adoption of |
/retitle Use |
errors.Is
for error equality checks
/assign |
Will try to get time tomorrow to submit PRs for this issue. |
Created a number of pull requests just now. These should constitute all changes originally in #18551 for the remaining errors.Is conversions. |
@ianlancetaylor, I'm a culprit here, but it occurred to me- are there possible performance concerns with |
@serathius, WDYT? |
If the choice is between using For testing purposes a better choice is often just |
Once we finish addressing this, let's enable https://golangci-lint.run/usage/linters/#errorlint as part of this effort, as suggested by @mmorel-35. |
@ivanvc @mmorel-35, let me know if there's anything more you need me to do here for this issue. @mmorel-35, it looks like you are handling adding in errorlint, which is great. |
You can activate errorlint through golangci config and pass it on your modified files. If there is nothing left to do you are good to go . What I'm doing is exactly this for each errorlint. Once the project is ready I will persist the configuration |
Closing as all tasks are complete, and the |
Bug report criteria
What happened?
When using the current Go HEAD which will be the future Go 1.24 release, in the directory etcd-io/etcd/server, running
go test ./embed
fails. The test error messages are:What did you expect to happen?
I expected the tests to pass.
How can we reproduce it (as minimally and precisely as possible)?
Build Go from HEAD as outlined at https://go.dev/doc/install/source. Use the newly built Go to run the etcd-io/server tests.
Anything else we need to know?
In general we recommend against testing for exact error strings. The Go standard library reserves the right to change error strings. It's better to simply test whether an error occurred or not. If it's necessary to check for a particular error, it's better to use
errors.Is
orerrors.As
to check the error. If that is infeasible, it's better to usestrings.Contains
to check that the error message contains some identifying string. Thanks.Etcd version (please run commands below)
Etcd configuration (command line flags or environment variables)
linux/amd64
Etcd debug information (please run commands below, feel free to obfuscate the IP address or FQDN in the output)
Relevant log output
No response
The text was updated successfully, but these errors were encountered: