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: add regression test for 'go build' error in module mode when no 'git' binary is available #28948

Closed
horseboxer opened this issue Nov 26, 2018 · 12 comments
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done. Testing An issue that has been verified to require only test changes, not just a test failure.
Milestone

Comments

@horseboxer
Copy link

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

$ go version
go version go1.11.2 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
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/test/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/test/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/scratchpad/hello/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 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build952622232=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Followed the quick-start example from the Go 1.11 Wiki page.

Link: https://github.com/golang/go/wiki/Modules#quick-start-example

What did you expect to see?

It work

What did you see instead?

Error after running go build the first time.

build github.com/you/hello: cannot find module for path rsc.io/quote
@mvdan
Copy link
Member

mvdan commented Nov 26, 2018

Please provide all the files, including Go files and go.mod, to reproduce this issue. Also provide exactly what commands you ran to encounter the error.

@andybons andybons changed the title Modules Quick Start Example Does Not Work documentation: modules quick start example does not work Nov 26, 2018
@andybons andybons added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. modules labels Nov 26, 2018
@andybons andybons added this to the Unplanned milestone Nov 26, 2018
@bcmills
Copy link
Contributor

bcmills commented Nov 27, 2018

CC @thepudds @myitcv

@thepudds
Copy link
Contributor

Hmm. I just ran through that "Quick Start Example" by copy/pasting from the wiki, and it seemed to work.

Prep by cleaning slate:

rm -rf /tmp/scratchpad/hello

Commands copied from the wiki:

mkdir -p /tmp/scratchpad/hello
cd /tmp/scratchpad/hello
go mod init github.com/you/hello
cat <<EOF > hello.go
package main

import (
    "fmt"
    "rsc.io/quote"
)

func main() {
    fmt.Println(quote.Hello())
}
EOF

go build 
./hello

Output:

Hello, world.

And here is the resulting go.mod:

$ cat go.mod

module github.com/you/hello

require rsc.io/quote v1.5.2

@horseboxer In addition to the questions @mvdan asked, what do you see if you do go get -v rsc.io/quote from within that directory /tmp/scratchpad/hello?

@thepudds
Copy link
Contributor

thepudds commented Dec 9, 2018

@horseboxer just wanted to check in to see if you were able to look at this a bit more? (For example, see the immediately prior comment as well as the suggestions from @mvdan).

Note that go get -v rsc.io/quote will likely tell you more information than go build alone. For example, it can be that go build will give a very general error you saw like cannot find module for path rsc.io/quote without any additional detail, but then running go get -v rsc.io/quote will often give a more specific error (which can be more helpful than the initial error from go build).

@horseboxer
Copy link
Author

Turns out freshly installed Ubuntu VMs don't have git installed :-(. Fixed the user-error and it works now. Sorry to waste your time.

@mvdan
Copy link
Member

mvdan commented Dec 19, 2018

I think cmd/go should give a better error message here. I can reproduce OP's confusing error with a few commands inside a Docker image:

$ cat repro.sh
docker run -i golang:1.11.3-alpine <<-SCRIPT
        export GO111MODULE=on
        git version && { echo "git needs to be missing"; exit 1; }
        mkdir /foo && cd /foo
        go mod init test.tld/foo
        go env GOMOD
        cat >f.go <<-FILE
                package main
                import _ "rsc.io/quote"
                func main() {}
        FILE
        go build
SCRIPT
$ sh repro.sh
/bin/sh: git: not found
go: creating new go.mod: module test.tld/foo
/foo/go.mod
build test.tld/foo: cannot find module for path rsc.io/quote

@bcmills note that this only happens with a package main. With package foo, I get:

f.go:5:1: unknown import path "rsc.io/quote": git init --bare in /go/pkg/mod/cache/vcs/4db0c9594744360b0eaa452d2ccfbd45b05dffb9810882957d10d69e61e66382: exec: "git": exec
utable file not found in $PATH

@mvdan mvdan reopened this Dec 19, 2018
@bcmills bcmills changed the title documentation: modules quick start example does not work cmd/go: confusing error message when building package main without a 'git' binary available Dec 19, 2018
@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go and removed Documentation WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Dec 19, 2018
@bcmills bcmills modified the milestones: Unplanned, Go1.13 Dec 19, 2018
@mvdan
Copy link
Member

mvdan commented Dec 19, 2018

@bcmills for what it's worth, I can't reproduce the issue on go version devel +9ed9df6ca2 Wed Dec 19 00:13:22 2018 +0000 linux/amd64, which should be pretty close to the first beta.

Frustratingly enough, there's no 1.12 docker image at the moment, so I can't be 100% sure. But locally, PATH=/home/mvdan/tip/bin gotip build gives a good error, while PATH=/home/mvdan/tip/bin go1.11.3 build gives the confusing error. So this might be already fixed in master.

@bcmills
Copy link
Contributor

bcmills commented Dec 19, 2018

@mvdan, thanks for investigating in detail!

My results match yours: I don't know why, but this seems to be fixed in 1.12.

$ PATH=~/bin go1.11.4 build .
build golang.org/issue/scratch: cannot find module for path rsc.io/quote

$ PATH=~/bin go1.12beta1 build .
build golang.org/issue/scratch: cannot load rsc.io/quote: git init --bare in /tmp/tmp.BJQhURaAuR/_gopath/pkg/mod/cache/vcs/4db0c9594744360b0eaa452d2ccfbd45b05dffb9810882957d10d69e61e66382: exec: "git": executable file not found in $PATH

@bcmills bcmills closed this as completed Dec 19, 2018
@mvdan
Copy link
Member

mvdan commented Dec 19, 2018

@bcmills perhaps we should add a regression test, particularly since noone seems to know how we fixed this :)

@bcmills
Copy link
Contributor

bcmills commented Dec 19, 2018

A regression test does seem like a good idea.

@bcmills bcmills reopened this Dec 19, 2018
@bcmills bcmills changed the title cmd/go: confusing error message when building package main without a 'git' binary available cmd/go: add regression test for 'go build' error in module mode when no 'git' binary is available Dec 19, 2018
@bcmills bcmills added Testing An issue that has been verified to require only test changes, not just a test failure. NeedsFix The path to resolution is known, but the work has not been done. labels Dec 19, 2018
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 19, 2018
@mvdan
Copy link
Member

mvdan commented Dec 19, 2018

I can submit my reproducer above as a test script by tomorrow.

@gopherbot
Copy link

Change https://golang.org/cl/155537 mentions this issue: cmd/go: add regresion test for cryptic vcs errors

@golang golang locked and limited conversation to collaborators Dec 22, 2019
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. Testing An issue that has been verified to require only test changes, not just a test failure.
Projects
None yet
Development

No branches or pull requests

6 participants