]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/testdir: print stderr if go list fails while gathering stdlib import...
authorthepudds <thepudds1460@gmail.com>
Wed, 21 Jun 2023 18:42:03 +0000 (14:42 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 20 Nov 2024 13:07:35 +0000 (13:07 +0000)
If cmd/compile is in an unhappy state, the testdir test can
fail with an unhelpful 'exit code 1' log message if
'go list' fails while gathering stdlib import config
When running individual files, such as:

 go test cmd/internal/testdir -run='Test/escape.*.go'

This might also happen in other uses, or it might be
that a more expansive set of tests such as run.bash
might first trigger a more useful error.

This change prints stderr and states that it is 'go list'
that is having problems to help someone track down the
proper issue.

Change-Id: Iba658ea139bb9087ab8adb00c9f65080a1b6ee76
Reviewed-on: https://go-review.googlesource.com/c/go/+/524941
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/internal/testdir/testdir_test.go

index f716e1b697c48df7bd415bce8e5216eb051405c7..7469a6491aa4bbb9e3f2dc36ea7df5f87a71c497 100644 (file)
@@ -215,8 +215,11 @@ var stdlibImportcfg = sync.OnceValue(func() string {
        cmd := exec.Command(goTool, "list", "-export", "-f", "{{if .Export}}packagefile {{.ImportPath}}={{.Export}}{{end}}", "std")
        cmd.Env = append(os.Environ(), "GOENV=off", "GOFLAGS=")
        output, err := cmd.Output()
+       if err, ok := err.(*exec.ExitError); ok && len(err.Stderr) != 0 {
+               log.Fatalf("'go list' failed: %v: %s", err, err.Stderr)
+       }
        if err != nil {
-               log.Fatal(err)
+               log.Fatalf("'go list' failed: %v", err)
        }
        return string(output)
 })