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: error text for missing package import becomes confusing after toolchain selection #61871

Closed
dmitshur opened this issue Aug 8, 2023 · 2 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dmitshur
Copy link
Contributor

dmitshur commented Aug 8, 2023

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

$ go version
go version go1.21.0 darwin/arm64

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='arm64'
GOBIN=''
GOCACHE='/Users/gopher/Library/Caches/go-build'
GOENV='/Users/gopher/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/gopher/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/gopher/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/s_/5sjqzr0j6xggz_xtzmq_8r4m00jwcj/T/go-build4187513592=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I tried building a Go program, while using GOTOOLCHAIN to select an older version of the Go toolchain (1.20.7 instead of 1.21.0), that should fail because it imports a package that doesn't exist in the Go standard library at that version:

package p

import _ "pkgnotinstd"
$ GOTOOLCHAIN=go1.20.7 go build

(The real thing I was doing was using GOTOOLCHAIN=<older toolchain> go test ./... to check that my change that starts to use Go 1.21's new "slices" package in a build-constrained .go file didn't accidentally break with older supported Go releases too.)

What did you expect to see?

An error message that mentions the name of the package. For example, something like:

p.go:3:8: package pkgnotinstd is not in std (/usr/local/go/src/pkgnotinstd)

Or more realistically, the less-improved error message as implemented in Go 1.20.7:

p.go:3:8: package pkgnotinstd is not in GOROOT (/usr/local/go/src/pkgnotinstd)

What did you see instead?

An error message that says "" instead of the package name or path:

p.go:3:8: import "": import of unknown directory

CC @bcmills, @matloob, @rsc.

@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Aug 8, 2023
@dmitshur dmitshur added this to the Backlog milestone Aug 8, 2023
@bcmills
Copy link
Contributor

bcmills commented Sep 18, 2023

I think this is the same underlying issue as #61873 — it should be fixed in the latest Go 1.20 patch release.

@dmitshur, can you confirm?

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 18, 2023
@dmitshur
Copy link
Contributor Author

Thanks. I can confirm:

$ GOTOOLCHAIN=go1.20.7 go build
p.go:3:8: import "": import of unknown directory
$ GOTOOLCHAIN=go1.20.8 go build
go: downloading go1.20.8 (darwin/arm64)
p.go:3:8: package pkgnotinstd is not in GOROOT (/Users/gopher/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.20.8.darwin-arm64/src/pkgnotinstd)

@dmitshur dmitshur removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants