Repository: go
Issue: cmd/go: print useful reason when 'go mod tidy' and 'go get' fail due to missing git authentication credentials
Labels: help wanted,NeedsFix,modules

<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version devel +cb6646234c Fri Apr 5 20:54:50 2019 +0000 darwin/amd64
</pre>

### Does this issue reproduce with the latest release?
Yes


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/Gurpartap/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Gurpartap/Projects/go"
GOPROXY=""
GORACE=""
GOROOT="/Users/Gurpartap/.gimme/versions/go"
GOTMPDIR=""
GOTOOLDIR="/Users/Gurpartap/.gimme/versions/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ly/3f450xdn7g3bjzjdkh7y66tm0000gn/T/go-build674837816=/tmp/go-build -gno-record-gcc-switches -fno-common"
</pre></details>

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->
<pre>
$ mkdir fresh && cd fresh # outside $GOPATH
$ set -x -g GO111MODULE on
$ go mod init fresh
$ go get -v -x "google.golang.org/grpc"
</pre>

### What did you expect to see?

#### • If user was authenticated to pull from cloud.google.com:
The requested module to be downloaded and defined in go.mod. No problem.

#### • If user was not authenticated to pull from cloud.google.com:

This `go get` output needs to convey an actionable error reason for the user to fix the situation. Something like:

<pre>
$ go get "google.golang.org/grpc"
go: finding cloud.google.com/go v0.26.0
go: google.golang.org/grpc@v1.19.1 ->
        cloud.google.com/go@v0.26.0: fatal: remote error: 

Invalid authentication credentials.

Please generate a new identifier:
  https://code.googlesource.com/new-password
</pre>


### What did you see instead?

This `go get` output does not convey any actionable error reason for the user to fix the situation.

<pre>
$ go get "google.golang.org/grpc"
go: finding cloud.google.com/go v0.26.0
go: google.golang.org/grpc@v1.19.1 ->
        cloud.google.com/go@v0.26.0: unknown revision v0.26.0
</pre>

I had to dig deeper with `go get -v -x ` to find the command that failed. Thanks @thepudds and @heschik.

Then I had to manually execute the failing command (`git ls-remote -q ...`) to find the actual/useful failure reason.

<details><summary><code>go get -v -x "google.golang.org/grpc"</code> Output</summary><br><pre>
$ go get -v -x "google.golang.org/grpc"
Fetching https://google.golang.org/grpc?go-get=1
Parsing meta tags from https://google.golang.org/grpc?go-get=1 (status code 200)
get "google.golang.org/grpc": found meta tag get.metaImport{Prefix:"google.golang.org/grpc", VCS:"git", RepoRoot:"https://github.com/grpc/grpc-go"} at https://google.golang.org/grpc?go-get=1
mkdir -p /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs # git2 https://github.com/grpc/grpc-go
# lock /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs/53ab5f2f034ba42de32f909aa45670cf730847987f38664c4052b329152ad727.lock# /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs/53ab5f2f034ba42de32f909aa45670cf730847987f38664c4052b329152ad727 for git2 https://github.com/grpc/grpc-go
cd /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs/53ab5f2f034ba42de32f909aa45670cf730847987f38664c4052b329152ad727; git ls-remote -q https://github.com/grpc/grpc-go
6.443s # cd /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs/53ab5f2f034ba42de32f909aa45670cf730847987f38664c4052b329152ad727; git ls-remote -q https://github.com/grpc/grpc-go
Fetching https://cloud.google.com/go?go-get=1
Parsing meta tags from https://cloud.google.com/go?go-get=1 (status code 200)
get "cloud.google.com/go": found meta tag get.metaImport{Prefix:"cloud.google.com/go", VCS:"git", RepoRoot:"https://code.googlesource.com/gocloud"} at https://cloud.google.com/go?go-get=1
mkdir -p /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs # git2 https://code.googlesource.com/gocloud
# lock /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs/b0e27935eb83c1d7843713bafab507e95768b550f0552cb42d9f41e5fd9c8375.lock# /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs/b0e27935eb83c1d7843713bafab507e95768b550f0552cb42d9f41e5fd9c8375 for git2 https://code.googlesource.com/gocloud
go: finding cloud.google.com/go v0.26.0
cd /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs/b0e27935eb83c1d7843713bafab507e95768b550f0552cb42d9f41e5fd9c8375; git tag -l
0.011s # cd /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs/b0e27935eb83c1d7843713bafab507e95768b550f0552cb42d9f41e5fd9c8375; git tag -l
cd /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs/b0e27935eb83c1d7843713bafab507e95768b550f0552cb42d9f41e5fd9c8375; git ls-remote -q https://code.googlesource.com/gocloud
1.439s # cd /Users/Gurpartap/Projects/go/pkg/mod/cache/vcs/b0e27935eb83c1d7843713bafab507e95768b550f0552cb42d9f41e5fd9c8375; git ls-remote -q https://code.googlesource.com/gocloud
go: google.golang.org/grpc@v1.19.1 ->
	cloud.google.com/go@v0.26.0: unknown revision v0.26.0
</pre></details>

<pre>
$ git ls-remote -q https://code.googlesource.com/gocloud

fatal: remote error: 

Invalid authentication credentials.

Please generate a new identifier:
  https://code.googlesource.com/new-password
</pre>