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: check %w Errorf flag #32070

Closed
josharian opened this issue May 15, 2019 · 8 comments
Closed

cmd/vet: check %w Errorf flag #32070

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

Comments

@josharian
Copy link
Contributor

We should teach cmd/vet about the new %w Errorf flag.

Vet seems perfectly happy with this code:

func f(s string) error {
	return fmt.Errorf("abc %w", s)
}

cc @mvdan @jba @mpvl

@josharian josharian added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels May 15, 2019
@josharian josharian added this to the Go1.13 milestone May 15, 2019
@josharian josharian changed the title cmd/vet: handle %w printf flag cmd/vet: check %w Errorf flag May 15, 2019
@neild neild self-assigned this May 16, 2019
@gopherbot
Copy link

Change https://golang.org/cl/177601 mentions this issue: go/analysis/passes/printf: improve support for %w

@mvdan
Copy link
Member

mvdan commented May 18, 2019

Weren't part of the errors changes reverted in master? Just want to double-check that we don't add checks to vet that don't reflect the released behavior of fmt.

@neild
Copy link
Contributor

neild commented May 19, 2019

The %w format was retained, with some slight modification to make it less of a special case:
#29934 (comment) (decision)
https://golang.org/cl/176998 (updated %w implementation)

@andybons
Copy link
Member

@neild any update on this?

@neild
Copy link
Contributor

neild commented Jul 16, 2019

@odeke-em
Copy link
Member

odeke-em commented Aug 1, 2019

Hello @neild, this is a kind ping to check on this as this Jonathan reviewed and +2'd it and the associated CL is marked for Go1.13 which will soon be released. Thank you!

@logrusorgru
Copy link

So, go1.13, go vet doesn't say anything about "%w" in a Sprintf for example. Is it expected behavior?

package main

import (
	"errors"
	"fmt"
)

var (
	ErrOne = errors.New("one error")
	ErrTwo = errors.New("two error")
)

func main() {

	var (
		err = fmt.Errorf("double wrap: %w, and %w", ErrOne, ErrTwo)
		str = fmt.Sprintf("double wrap: %w, and %w", ErrOne, ErrTwo)
	)

	fmt.Println(err)
	fmt.Println(str)
}

play.golang.org

$ go vet main.go
$ go version
go version go1.13.3 linux/amd64

@josharian
Copy link
Contributor Author

josharian commented Nov 23, 2019

This should be fixed in the 1.14 release (and the beta coming out soon).

@golang golang locked and limited conversation to collaborators Nov 22, 2020
@rsc rsc unassigned neild Jun 23, 2022
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. release-blocker
Projects
None yet
Development

No branches or pull requests

7 participants