Skip to content

cmd/go: "go generate" appears to be a silent no-op when given a missing package #60079

@mvdan

Description

@mvdan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions