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
Assignees
Milestone

Comments

@josharian
Copy link
Contributor

@josharian josharian commented May 15, 2019

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 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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented May 16, 2019

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

@mvdan

This comment has been minimized.

Copy link
Member

@mvdan 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

This comment has been minimized.

Copy link
Contributor

@neild 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

This comment has been minimized.

Copy link
Member

@andybons andybons commented Jul 16, 2019

@neild any update on this?

@neild

This comment has been minimized.

Copy link
Contributor

@neild neild commented Jul 16, 2019

@odeke-em

This comment has been minimized.

Copy link
Member

@odeke-em 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

This comment has been minimized.

Copy link

@logrusorgru logrusorgru commented Nov 23, 2019

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

This comment has been minimized.

Copy link
Contributor Author

@josharian josharian commented Nov 23, 2019

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

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