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: misleading error message for go mod download in incorrect workspace #54419

Open
zephyrtronium opened this issue Aug 12, 2022 · 0 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@zephyrtronium
Copy link
Contributor

zephyrtronium commented Aug 12, 2022

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

$ go version
go version go1.19 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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/branden/.cache/go-build"
GOENV="/home/branden/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/branden/go/pkg/mod"
GONOPROXY=(omitted)
GONOSUMDB=(omitted)
GOOS="linux"
GOPATH="/home/branden/go"
GOPRIVATE=(omitted)
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK="/home/branden/work/(omitted)/go.work"
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2013897630=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I cloned an existing module, say git.example.com/example/example-mod, to my filesystem at ~/work/example/example-mod. It contains a valid go.mod file. GOPRIVATE is configured as *.example.com. I created a new workspace via go work init in ~/work/example, but I forgot to add the module to it. Then, I ran go mod download inside the module.

What did you expect to see?

Successfully downloaded dependencies, or an error message explaining that the current module is not in the workspace. Notably, I realized my problem because go build produced the latter:

~/work/example/example-mod$ go build
go: no modules were found in the current workspace; see 'go help work'

What did you see instead?

A confusing error message about the standard library with no indication of a problem with the workspace:

~/work/example/example-mod$ go mod download
go: cannot match "all": go.mod file not found in current directory or any parent directory; see 'go help modules'

This was confusing because all, i.e. std cmd, refers to valid modules in my Go installation, and the module in which I was running this command has a go.mod.

@joedian joedian added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 15, 2022
@joedian joedian added this to the Go1.20 milestone Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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