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 suggested action when installing a module while -mod=readonly is on #44975

Closed
deltamualpha opened this issue Mar 12, 2021 · 5 comments
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@deltamualpha
Copy link

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

$ go version
go version go1.16 darwin/amd64

Does this issue reproduce with the latest release?

Yep.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/davidashby/Library/Caches/go-build"
GOENV="/Users/davidashby/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/davidashby/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/davidashby/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/davidashby/Code/ixauth/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/zl/y389cwmn45sfrdcqt23b1ynh0000gn/T/go-build889417450=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

$ go install github.com/mitranim/gow

What did you expect to see?

No output and a binary installed in GOBIN.

What did you see instead?

no required module provides package github.com/mitranim/gow; to add it:
        go get github.com/mitranim/gow

My intention was to install a helper binary for some tests. Previously, I'd used go get github.com/mitranim/gow to install the binary into GOBIN (which I place in my PATH), but since my actual application doesn't rely on that module, I was excited to switch to install so I wouldn't have to run go mod tidy all the time to clean up after it. Instead, I got the somewhat cryptic error message above. This is related to -mod defaulting to readonly now, it seems.

Apparently, the proper invocation is to add a specific version to the install path: go install github.com/mitranim/gow@latest does what I expected. It'd be nice if the error-message hinted at that.

@seankhliao seankhliao changed the title Clarify suggested action when installing a module while -mod=readonly is on cmd/go: clarify suggested action when installing a module while -mod=readonly is on Mar 12, 2021
@jayconrod jayconrod added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 12, 2021
@jayconrod jayconrod added this to the Go1.17 milestone Mar 12, 2021
@jayconrod
Copy link
Contributor

Thanks for opening this issue.

The go command should provide hints for both adding a dependency to the current module and for installing a command independent of the current module.

@deltamualpha
Copy link
Author

The command does spit out a nice message when not in a module: https://github.com/golang/go/blob/master/src/cmd/go/internal/work/build.go#L615, but load.CheckPackageErrors(pkgs) on line 618 exits on error and doesn't let us add any extra information afterward.

@deltamualpha
Copy link
Author

Augmenting https://github.com/golang/go/blob/master/src/cmd/go/internal/modload/import.go#L73 looks like it has the least impact, but might appear more places than just go install. Maybe "%s; to add it:\n\tgo get %s\nto install it as a binary:\n\tgo install %s@latest"? Unclear to me if e.Module.Version would be expected to be set at this point in the execution (I think not, since e.Module.Path == "" is the trigger for that entire block.)

@iwdgo
Copy link
Contributor

iwdgo commented May 13, 2021

Issue seems to duplicate #42638 which was solved by CL 277355 merge to close

>gotip version
go version devel go1.17-4c8f48ed4f Sat May 8 05:57:31 2021 +0000 windows/amd64

>gotip install github.com/mitranim/gow
go install: version is required when current directory is not in a module
        Try 'go install github.com/mitranim/gow@latest' to install the latest version

@deltamualpha
Copy link
Author

Yep, that looks like it solves my concern!

@golang golang locked and limited conversation to collaborators May 13, 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