From f70aa3824b637d69aaaa944b3e4691c1fbe6c0d4 Mon Sep 17 00:00:00 2001 From: Sam Thanawalla Date: Thu, 23 Jan 2025 19:35:34 +0000 Subject: [PATCH] cmd/go: do not call base.fatal for an unset HOME for GOAUTH=netrc This CL silences errors caused by GOAUTH=netrc and HOME being unset. Instead, we log the error if the -x flag is set. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Change-Id: Ibd323769f3562c169ebf559e060e9afbb63047bc Reviewed-on: https://go-review.googlesource.com/c/go/+/643917 Reviewed-by: Michael Matloob LUCI-TryBot-Result: Go LUCI --- src/cmd/go/internal/auth/auth.go | 3 ++- src/cmd/go/testdata/script/goauth_netrc.txt | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/internal/auth/auth.go b/src/cmd/go/internal/auth/auth.go index bd80222427..79e0d8b5e8 100644 --- a/src/cmd/go/internal/auth/auth.go +++ b/src/cmd/go/internal/auth/auth.go @@ -70,7 +70,8 @@ func runGoAuth(client *http.Client, res *http.Response, url string) { case "netrc": lines, err := readNetrc() if err != nil { - base.Fatalf("go: could not parse netrc (GOAUTH=%s): %v", cfg.GOAUTH, err) + cmdErrs = append(cmdErrs, fmt.Errorf("GOAUTH=%s: %v", command, err)) + continue } // Process lines in reverse so that if the same machine is listed // multiple times, we end up saving the earlier one diff --git a/src/cmd/go/testdata/script/goauth_netrc.txt b/src/cmd/go/testdata/script/goauth_netrc.txt index 26e03f8968..0baa09de1e 100644 --- a/src/cmd/go/testdata/script/goauth_netrc.txt +++ b/src/cmd/go/testdata/script/goauth_netrc.txt @@ -53,6 +53,19 @@ go get vcs-test.golang.org/auth/or401 env NETRC=$WORK/missing ! go get vcs-test.golang.org/auth/or401 stderr '^\tserver response: ACCESS DENIED, buddy$' + +[short] skip 'requires a remote vcs lookup' +[!git] skip +# An unset home directory should warn the user but not cause a failure. +env NETRC= +env HOME= +env USERPROFILE= +env home= +go get -x vcs-test.golang.org/git/emptytest.git +[!GOOS:windows] [!GOOS:plan9] stderr 'GOAUTH=netrc: \$HOME is not defined' +[GOOS:windows] stderr 'GOAUTH=netrc: \%userprofile\% is not defined' +[GOOS:plan9] stderr 'GOAUTH=netrc: \$home is not defined' + -- go.mod -- module private.example.com -- $WORK/empty -- -- 2.48.1