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: Should warn against using %v print verb in Error() methods #33884

Closed
mattayes opened this issue Aug 27, 2019 · 3 comments
Closed

cmd/vet: Should warn against using %v print verb in Error() methods #33884

mattayes opened this issue Aug 27, 2019 · 3 comments

Comments

@mattayes
Copy link

@mattayes mattayes commented Aug 27, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.9 darwin/amd64

Does this issue reproduce with the latest release?

Yes (1.12.9 is the latest release).

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mattayes/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mattayes/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.9/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.9/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/10/46nlr7tj7z70cz9jyzdcntvr0000gn/T/go-build974633075=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I accidentally used the default printing verb (%v) in an Error() method on a struct, causing a stack overflow.

https://play.golang.org/p/P6Vpeg6-JDv

What did you expect to see?

I expected vet to catch the mistake and warn me about it, like it does when attempting to do this in a String() method.

https://play.golang.org/p/kw_-rXcc7iv

What did you see instead?

I received no warning and took down production 🙃.

@mattayes mattayes changed the title cmd/vet: Should warn against using %v print verb in Error() method cmd/vet: Should warn against using %v print verb in Error() methods Aug 27, 2019
@bcmills
Copy link
Member

@bcmills bcmills commented Aug 27, 2019

@bcmills bcmills added this to the Go1.14 milestone Aug 27, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@gsserge
Copy link

@gsserge gsserge commented Mar 12, 2020

I'd like to work on this one.

gsserge added a commit to gsserge/tools that referenced this issue Mar 12, 2020
go vet should warn against using %v verb in Error() methods just like it
does for String().

Fixes golang/go#33884
@gopherbot
Copy link

@gopherbot gopherbot commented Mar 12, 2020

Change https://golang.org/cl/223239 mentions this issue: go/analysis/passes/printf: warn against using %v verb in Error() methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.