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 list -m error is confusing when go.mod lacks module directive #37264

Open
perillo opened this issue Feb 17, 2020 · 1 comment
Open

cmd/go: go list -m error is confusing when go.mod lacks module directive #37264

perillo opened this issue Feb 17, 2020 · 1 comment
Labels
Milestone

Comments

@perillo
Copy link

@perillo perillo commented Feb 17, 2020

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

$ go version
go version go1.14rc1 linux/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
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/manlio/.local/bin"
GOCACHE="/home/manlio/.cache/go-build"
GOENV="/home/manlio/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/src/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/manlio/sdk/go1.14rc1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/manlio/sdk/go1.14rc1/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build648332856=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.14rc1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.14rc1
uname -sr: Linux 5.5.4-arch1-1
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.31.
gdb --version: GNU gdb (GDB) 9.1

What did you do?

Inside the HOME directory:

$ go list -m -json
{
	"Path": "command-line-arguments",
	"Main": true
}

But if I add a go.mod file in a parent directory:

$ sudo touch ../go.mod
$ go list -m -json
go: cannot determine module path for source directory /home (outside GOPATH, module path must be specified)

Example usage:
	'go mod init example.com/m' to initialize a v0 or v1 module
	'go mod init example.com/m/v2' to initialize a v2 module

Run 'go help mod init' for more information.

This is confusing for two reasons:

  1. My HOME directory is also outside `GOPATH
  2. go list -m returns the usage message for go mod init, and this may confuse newcomers
@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Feb 18, 2020

This is almost the same issue as #35070. The problem is that go list is failing to load the go.mod file because it doesn't contain a module directive. It appears that it's trying to add the module directive and is failing to infer the module path.

Instead, we should reject a go.mod file without a module directive with a clear message. This is based on @rsc's comment in CL 211597.

Tentatively tagging both issues for 1.15. I expect they will both be fixed by CL 211597.

cc @matloob

@jayconrod jayconrod changed the title cmd/go: go list -m is confusing when go.mod is in a parent directory outside GOPATH cmd/go: go list -m error is confusing when go.mod lacks module directive Feb 18, 2020
@jayconrod jayconrod added the NeedsFix label Feb 18, 2020
@jayconrod jayconrod added this to the Go1.15 milestone Feb 18, 2020
@bcmills bcmills added the modules label Feb 19, 2020
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
3 participants
You can’t perform that action at this time.