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
Closed

cmd/vet: %w in Printf call should be flagged #35472

josharian opened this issue Nov 8, 2019 · 9 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@josharian
Copy link
Contributor

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
Copy link
Contributor

bcmills commented Nov 8, 2019

CC @ianthehat @matloob @dominikh

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 8, 2019
@bcmills bcmills added this to the Backlog milestone Nov 8, 2019
@mvdan mvdan added the Suggested Issues that may be good for new contributors looking for work to do. label Nov 9, 2019
@mvdan
Copy link
Member

mvdan commented Nov 9, 2019

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

@Inconnu08
Copy link
Contributor

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

@agnivade
Copy link
Contributor

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
Copy link
Contributor

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

@bcmills bcmills removed the Suggested Issues that may be good for new contributors looking for work to do. label Nov 12, 2019
@Inconnu08
Copy link
Contributor

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
Copy link
Contributor

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.

@Inconnu08
Copy link
Contributor

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

@josharian
Copy link
Contributor Author

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

invidian added a commit to flexkube/libflexkube that referenced this issue Nov 24, 2019
Refs golang/go#35472

Signed-off-by: Mateusz Gozdek <mgozdekof@gmail.com>
@golang golang locked and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants