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: bad error when GOROOT not set correctly #34769

Closed
rsc opened this issue Oct 8, 2019 · 5 comments
Closed

cmd/go: bad error when GOROOT not set correctly #34769

rsc opened this issue Oct 8, 2019 · 5 comments
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Oct 8, 2019

Bad GOROOT is not diagnosed particularly well:

$ go build
$ GOROOT=/nonexist go build
go: cannot find GOROOT directory: /nonexist
$ GOROOT=/ go build
build rsc.io/kb/pw: cannot load bytes: malformed module path "bytes": missing dot in first path element
$

The first error is great. The second error is not. It should diagnose the bad GOROOT setting not complain about malformed module paths.

FWIW GOPATH mode is bad too but differently:

$ GOROOT=/ GO111MODULE=off go build
pw.go:16:2: cannot find package "bytes" in any of:
	/src/bytes (from $GOROOT)
	/Users/rsc/src/bytes (from $GOPATH)
../../../golang.org/x/crypto/blake2b/register.go:10:2: cannot find package "crypto" in any of:
	/src/crypto (from $GOROOT)
	/Users/rsc/src/crypto (from $GOPATH)
pw.go:17:2: cannot find package "crypto/rand" in any of:
	/src/crypto/rand (from $GOROOT)
	/Users/rsc/src/crypto/rand (from $GOPATH)
(many lines cut)
@bcmills bcmills added NeedsFix The path to resolution is known, but the work has not been done. modules labels Oct 8, 2019
@bcmills bcmills added this to the Go1.14 milestone Oct 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@a8m
Copy link
Contributor

a8m commented Oct 24, 2019

This issue is somehow related to CL that changes the second error.

The missing dot in first path element error returns in other cases, like this one.

@aayushrathore
Copy link

for me the issue was resolved after chaning the GOROOT environment variable from "/usr/loca/go/bin" to "/usr/local/go"

OS : Linux centos

@ezzoueidi
Copy link

For me, even changing the GOROOT variable to /usr/local/go still showing me the same output when doing go build.

@gopherbot
Copy link

Change https://golang.org/cl/210339 mentions this issue: cmd/go: avoid generating "malformed module path" errors for standard-library paths

@gopherbot
Copy link

Change https://golang.org/cl/216817 mentions this issue: go/build: update TestImportDirNotExist to accept more detailed error strings

gopherbot pushed a commit that referenced this issue Jan 29, 2020
…strings

In CL 203820, we switched go/build to use the caller's working
directory for the main module (rather than srcDir), so that go/build
resolution now respects the requirements and replacements of the main
module. When the passed-in srcDir is empty, as of that CL we use "go
list" instead of falling back to in-process (GOPATH-mode) path lookup.

Unfortunately, that broke go/build.TestImportDirNotExist when
GO111MODULE=on: the test was looking for the specific error message
produced by the in-process lookup.

This change relaxes the test to accept the error message produced by
"go list" when srcDir is empty.

Updates #34769
Updates #34860
Updates #35734
Fixes #36867

Change-Id: Id0f7814a4b7dabe8917216eb013bb4eaee283648
Reviewed-on: https://go-review.googlesource.com/c/go/+/216817
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
@golang golang locked and limited conversation to collaborators Feb 11, 2021
@rsc rsc unassigned bcmills Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants