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

Closed
perillo opened this issue Feb 17, 2020 · 3 comments
Closed
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@perillo
Copy link
Contributor

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
Copy link
Contributor

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 The path to resolution is known, but the work has not been done. label Feb 18, 2020
@jayconrod jayconrod added this to the Go1.15 milestone Feb 18, 2020
@ianlancetaylor
Copy link
Contributor

The CL is marked wait-release, so rolling this issue forward to 1.16.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.15, Go1.16 Jun 16, 2020
@ianlancetaylor ianlancetaylor added the GoCommand cmd/go label Jun 16, 2020
@jayconrod
Copy link
Contributor

The error message now looks like this:

$ go list -m
go: no module declaration in go.mod. To specify the module path:
	go mod edit -module=example.com/mod

@golang golang locked and limited conversation to collaborators Jan 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants