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: %w in Printf call should be flagged #35472

Closed
josharian opened this issue Nov 8, 2019 · 9 comments
Assignees
Milestone

Comments

@josharian
Copy link
Contributor

@josharian josharian commented Nov 8, 2019

package main

import (
	"errors"
	"fmt"
)

func main() {
	err := errors.New("ABC")
	fmt.Printf("error: %w\n", err)
}

https://play.golang.org/p/-kQ6HtIIMG7

vet should complain about the %w verb. Only in Errorf format strings does it have meaning.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Nov 8, 2019

@bcmills bcmills added this to the Backlog milestone Nov 8, 2019
@mvdan mvdan added the Suggested label Nov 9, 2019
@mvdan

This comment has been minimized.

Copy link
Member

@mvdan mvdan commented Nov 9, 2019

This also seems like a pretty simple issue for anyone wanting to get started contributing to vet.

@Inconnu08

This comment has been minimized.

Copy link
Contributor

@Inconnu08 Inconnu08 commented Nov 12, 2019

I would love to take a shot on this. Any pointers to get started on this issue?

@agnivade

This comment has been minimized.

Copy link
Contributor

@agnivade agnivade commented Nov 12, 2019

The file in question is this one - https://github.com/golang/tools/blob/master/go/analysis/passes/printf/printf.go. Look at how other verbs are handled and take it from there.

@Inconnu08

This comment has been minimized.

Copy link
Contributor

@Inconnu08 Inconnu08 commented Nov 12, 2019

Ah I'm on the right track then. Thank you! I'm working on this 😃

@Inconnu08

This comment has been minimized.

Copy link
Contributor

@Inconnu08 Inconnu08 commented Nov 15, 2019

vet already complains about the %w verb in printf. I ran the above code and this is what I got:
./main.go:10:2: Printf format %w has unknown verb w.

@agnivade

This comment has been minimized.

Copy link
Contributor

@agnivade agnivade commented Nov 15, 2019

You are right. This was fixed by golang/tools@1d17272. The original issue was reported by @josharian himself which was about passing strings to a %w parameter. But the commit reported usages of %w with non-Errrof functions too.

The error message is Printf call has error-wrapping directive %w though, not the one you mentioned.

I will go ahead and close this one. Thanks for looking into it @Inconnu08.

@agnivade agnivade closed this Nov 15, 2019
@Inconnu08

This comment has been minimized.

Copy link
Contributor

@Inconnu08 Inconnu08 commented Nov 15, 2019

Exactly. But the end error message is the above one reported by vet. Anytime!

@josharian

This comment has been minimized.

Copy link
Contributor Author

@josharian josharian commented Nov 15, 2019

Oops, sorry. :( I thought I tested with tip but apparently only did 1.13. Thanks, @Inconnu08.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.