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

x/tools/cmd/stringer: error message is less clear than that of go build when there's a build error due to multiple package names in same directory #46207

Open
gucio321 opened this issue May 17, 2021 · 4 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@gucio321
Copy link

gucio321 commented May 17, 2021

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

$ go version
go version go1.16.4 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3225948580=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Hi!
I was changing my project's structure. In my enums directory I have files with //go:generate stringer directives. At some point, I forgot to change package name in a file copied from somewhere else. I've tried to run go generate and and got stuck:

stringer: no value for constant type2s1
file2.go:3: running "stringer": exit status 1

Example

there are two files in package, but with another package names
the go build . returns:

found packages package1 (file1.go) and package2 (file2.go) in /home/user/test/

but go generate returns something strange:

stringer: no value for constant type2s1
file2.go:3: running "stringer": exit status 1
file1.go
package package1

//go:generate stringer -linecomment -type type1

type type1 byte

const (
	type1s1 type1 = iota
	type1s2
)
file2.go
package package2

//go:generate stringer -linecomment -type type2

type type2 byte

const (
	type2s1 type2 = iota
	type2s2
)

What did you expect to see?

go generate should report understandable message when build errors found

What did you see instead?

stringer: no value for constant type2s1
file2.go:3: running "stringer": exit status 1
@dmitshur
Copy link
Contributor

dmitshur commented May 17, 2021

go generate invokes commands. If a command fails, go generate displays the output from said command. A command may fail because there are build errors, or it might fail for another completely unrelated reason.

So, if there's anything to do here, it's to improve stringer to print better error messages when it fails due to a build error. I'll retitle the issue to be about that.

@dmitshur dmitshur changed the title go/internal/generate returns weird values when build errors x/tools/cmd/stringer: error message is less clear than that of go build when there's a build error due to multiple package names in same directory May 17, 2021
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 17, 2021
@gopherbot gopherbot added this to the Unreleased milestone May 17, 2021
@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository. and removed Tools This label describes issues relating to any tools in the x/tools repository. labels May 17, 2021
@dmitshur
Copy link
Contributor

dmitshur commented May 17, 2021

CC @mvdan via owners.

Issue #25650 may be relevant.

@gucio321
Copy link
Author

go generate invokes commands. If a command fails, go generate displays the output from said command. A command may fail because there are build errors, or it might fail for another completely unrelated reason.

good point. Just couldn't found reproducable example with calling stringer

@gucio321
Copy link
Author

oh, okey, so:
in my example calling stringer -type type2 . will crash as described

stringer: no value for constant type2s1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants