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

Don't use %#v to format error #7070

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Don't use %#v to format error #7070

wants to merge 3 commits into from

Conversation

huww98
Copy link

@huww98 huww98 commented Mar 19, 2024

%#v is not suitable for print error. It is unreadable, and missing important information.
For example, before (with %#v):

&url.Error{Op:"Post", URL:"https://...", Err:(*net.OpError)(0x14002fa4000)}

after (in this PR, with %w or %v):

Post "https://...": dial tcp: lookup example.com: no such host

find alicloud -name '*.go' | xargs sed -E -e '/fmt\.Errorf\(/ s/%#v.?", (.*)err\)$/%w", \1err)/' -i ''

%#v is not suitable for print error. It is unreadable, and missing important information.
For example, before (with %#v):

  &url.Error{Op:"Post", URL:"https://...", Err:(*net.OpError)(0x14002fa4000)}

after (in this PR, with %w):

  Post "https://...": dial tcp: lookup example.com: no such host
find alicloud -name '*.go' | xargs sed -E -e 's/%#v.?", (.*)err\)$/%v", \1err)/' -i ''

the same as the previous commit, for cases that not use fmt.Errorf()
@CLAassistant
Copy link

CLAassistant commented Mar 19, 2024

CLA assistant check
All committers have signed the CLA.

the same as the above commits, but changed manually, with the help of:

golangci-lint run --disable-all --enable errorlint --max-same-issues 100 ./alicloud/...
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