What version of Go are you using (go version
)?
$ go version go version devel go1.21-8d5065ce6e Tue May 9 01:28:10 2023 +0000 linux/amd64
Does this issue reproduce with the latest release?
Yes; appears to happen with 1.20.4 as well.
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE='' GOARCH='amd64' GOBIN='' GOCACHE='/home/mvdan/.cache/go-build' GOENV='/home/mvdan/.config/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='linux' GOINSECURE='' GOMODCACHE='/home/mvdan/go/pkg/mod' GONOPROXY='github.com/cue-unity' GONOSUMDB='github.com/cue-unity' GOOS='linux' GOPATH='/home/mvdan/go' GOPRIVATE='github.com/cue-unity' GOPROXY='https://proxy.golang.org,direct' GOROOT='/home/mvdan/tip' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLDIR='/home/mvdan/tip/pkg/tool/linux_amd64' GOVCS='' GOVERSION='devel go1.21-8d5065ce6e Tue May 9 01:28:10 2023 +0000' GCCGO='gccgo' GOAMD64='v3' AR='ar' CC='gcc' CXX='g++' CGO_ENABLED='1' GOMOD='/home/mvdan/tip/src/go.mod' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1520120181=/tmp/go-build -gno-record-gcc-switches'
What did you do?
$ cd $(go env GOROOT)/src
$ go list ./cmd/missing
stat /home/mvdan/tip/src/cmd/missing: directory not found
$ go generate ./cmd/missing
$ echo $?
0
What did you expect to see?
Both commands should fail on a missing package.
What did you see instead?
go generate
appears to happily do nothing.
It could be due to its nature of working with broken packages, for example if the generated files are required for the package to typecheck but they are missing. However, if the package can't be located at all, that should clearly be an error. I had a weird issue at work where I thought my generator wasn't working, simply because I was making a typo when writing go generate ./some/pkg
.
Comment From: cherrymui
cc @bcmills @matloob
Comment From: bcmills
Agreed, go generate
should error out if any argument pattern fails to match at least one package.
It may be as simple as adding an error check in this loop: https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/generate/generate.go;l=204;drc=93d9035c9e8b129578d3a177fd90eb308e44a597
Comment From: gopherbot
Change https://go.dev/cl/494836 mentions this issue: cmd/go/internal/generate: error if failed to find a package
Comment From: katexochen
@g4s8 Maybe this change in behavior should be documented in the release notes?
Comment From: matloob
I don't think this is a big enough change in behavior to merit a release note
Comment From: katexochen
@matloob It is a breaking changes in an API that breaks use cases downstream (nixpkgs in my case). How can that not be enough to be mentioned in the release notes?
Comment From: matloob
Hi @katexochen, sorry about the long delay in response. I'm curious about your use case: I'm assuming that go generate
is being run by a tool with packages whose existence is not known at the time of running generate? If that is the case then we should probably mention it...