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/go: "go generate" appears to be a silent no-op when given a missing package #60079

Closed
mvdan opened this issue May 9, 2023 · 6 comments
Closed
Labels
GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mvdan
Copy link
Member

mvdan commented May 9, 2023

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.

@cherrymui cherrymui added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels May 9, 2023
@cherrymui cherrymui added this to the Backlog milestone May 9, 2023
@cherrymui
Copy link
Member

cc @bcmills @matloob

@bcmills
Copy link
Contributor

bcmills commented May 11, 2023

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

@bcmills bcmills added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels May 11, 2023
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 11, 2023
g4s8 added a commit to g4s8/go that referenced this issue May 13, 2023
Add check for package loader to print error and fail `go generate`
command, if package can not be found.

Fixes golang#60079
@gopherbot
Copy link

Change https://go.dev/cl/494836 mentions this issue: cmd/go/internal/generate: error if failed to find a package

g4s8 added a commit to g4s8/go that referenced this issue May 17, 2023
Add check for package loader to print error and fail `go generate`
command, if package can not be found.

Fixes golang#60079
g4s8 added a commit to g4s8/go that referenced this issue May 24, 2023
Add check for package loader to print error and fail `go generate`
command, if package no go files in package or specified import
doesn't exist.

Fixes golang#60079
g4s8 added a commit to g4s8/go that referenced this issue May 25, 2023
Add check for package loader to print error and fail `go generate`
command, if package no go files in package or specified import
doesn't exist.

Fixes golang#60079
g4s8 added a commit to g4s8/go that referenced this issue Sep 5, 2023
Add check for package loader to print error and fail `go generate`
command, if package no go files in package or specified import
doesn't exist.

Fixes golang#60079
g4s8 added a commit to g4s8/go that referenced this issue Sep 8, 2023
Add check for package loader to print error and fail `go generate`
command, if package no go files in package or specified import
doesn't exist.

Fixes golang#60079
@katexochen
Copy link

katexochen commented Mar 19, 2024

@g4s8 Maybe this change in behavior should be documented in the release notes?

@matloob
Copy link
Contributor

matloob commented Mar 26, 2024

I don't think this is a big enough change in behavior to merit a release note

@katexochen
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants