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: clarify "does not contain package" error? #39593

Open
kstenerud opened this issue Jun 15, 2020 · 4 comments
Open

cmd/go: clarify "does not contain package" error? #39593

kstenerud opened this issue Jun 15, 2020 · 4 comments

Comments

@kstenerud
Copy link

@kstenerud kstenerud commented Jun 15, 2020

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

$ go version
go version go1.14.4 windows/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
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\karl\AppData\Local\go-build
set GOENV=C:\Users\karl\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\karl\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\karl\code\winsrv\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\karl\AppData\Local\Temp\go-build530336870=/tmp/go-build -gno-record-gcc-switches

What did you do?

main.go:

package main

func main() {

}

go.mod:

module mymod

go 1.13

require golang.org/x/sys v0.0.0-20190204203706-41f3e6584952

go build

What did you expect to see?

I expected it to download that version of sys.

What did you see instead?

go: finding module for package golang.org/x/sys
main.go:4:2: module golang.org/x/sys@latest found (v0.0.0-20200610111108-226ff32320da), but does not contain package golang.org/x/sys

I wanted version 20190204203706-41f3e6584952 but it's attempting to download 20200610111108-226ff32320da instead, and also failing for some reason.

@bcmills
Copy link
Member

@bcmills bcmills commented Jun 15, 2020

What did you do?

Please post the actual program that reproduces the problem. This one does not — the main.go file seems to have been oversimplified.

mymod$ txtar * </dev/null
-- go.mod --
module mymod

go 1.13

require golang.org/x/sys v0.0.0-20190204203706-41f3e6584952
-- main.go --
package main

func main() {

}

mymod$ go build

mymod$ cat go.mod
module mymod

go 1.13

require golang.org/x/sys v0.0.0-20190204203706-41f3e6584952

From the error message you are reporting, I suspect that your actual program includes the line

import (
	"golang.org/x/sys"
)

which provokes go build to attempt to find some version of a module containing the package golang.org/x/sys. The module golang.org/x/sys does not have any .go source files at its root, so there is no such package (as the error message states).

@kstenerud
Copy link
Author

@kstenerud kstenerud commented Jun 15, 2020

Ah I see, the error message isn't very clear about this. It just says "does not contain package XYZ", not "There are no go files at this level".

@bcmills bcmills changed the title Go ignores required version cmd/go: clarify "does not contain package" error? Jun 17, 2020
@bcmills
Copy link
Member

@bcmills bcmills commented Jun 17, 2020

CC @jayconrod @matloob

I'm not sure how we could make this clearer without also making it too verbose, but if you have a specific suggestion we could consider it.

@bcmills bcmills added this to the Unplanned milestone Jun 17, 2020
@kstenerud
Copy link
Author

@kstenerud kstenerud commented Jun 17, 2020

Maybe keep the current error msg, plus append "No go files found. Are you sure you have the correct import path?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.