From 4a1b41eed170862fe82028699015842e9382fe2b Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Wed, 17 Oct 2018 16:50:47 -0400 Subject: [PATCH] go/packages: don't spam stderr Some editors combine stdout and stderr when running tools, so printing to stderr without failing confuses them. Stop printing go list's warnings. They're still useful for debugging, so users can set GOPACKAGESPRINTGOLISTERRORS to see them. This isn't part of the API and has no compatibility guarantees. Change-Id: I9cf091cf59d082123149888468fa0d126dc972c7 Reviewed-on: https://go-review.googlesource.com/c/142997 Run-TryBot: Heschi Kreinick Reviewed-by: Ian Cottrell TryBot-Result: Gobot Gobot --- go/packages/golist.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/go/packages/golist.go b/go/packages/golist.go index ce352c7f..37a6b8b1 100644 --- a/go/packages/golist.go +++ b/go/packages/golist.go @@ -588,7 +588,7 @@ func golist(cfg *Config, args []string) (*bytes.Buffer, error) { // Catastrophic error: // - executable not found // - context cancellation - return nil, fmt.Errorf("couldn't exec 'go list': %s %T", err, err) + return nil, fmt.Errorf("couldn't exec 'go %v': %s %T", args, err, err) } // Old go list? @@ -601,20 +601,18 @@ func golist(cfg *Config, args []string) (*bytes.Buffer, error) { // (despite the -e flag) and the Export field is blank. // Do not fail in that case. if !usesExportData(cfg) { - return nil, fmt.Errorf("go list: %s: %s", exitErr, cmd.Stderr) + return nil, fmt.Errorf("go %v: %s: %s", args, exitErr, cmd.Stderr) } } - // Print standard error output from "go list". - // Due to the -e flag, this should be empty. - // However, in -export mode it contains build errors. - // Should go list save build errors in the Package.Error JSON field? - // See https://github.com/golang/go/issues/26319. - // If so, then we should continue to print stderr as go list - // will be silent unless something unexpected happened. - // If not, perhaps we should suppress it to reduce noise. - if len(stderr.Bytes()) != 0 { - fmt.Fprintf(os.Stderr, "go list stderr <<%s>>\n", stderr) + // As of writing, go list -export prints some non-fatal compilation + // errors to stderr, even with -e set. We would prefer that it put + // them in the Package.Error JSON (see http://golang.org/issue/26319). + // In the meantime, there's nowhere good to put them, but they can + // be useful for debugging. Print them if $GOPACKAGESPRINTGOLISTERRORS + // is set. + if len(stderr.Bytes()) != 0 && os.Getenv("GOPACKAGESPRINTGOLISTERRORS") != "" { + fmt.Fprintf(os.Stderr, "go %v stderr: <<\n%s\n>>\n", args, stderr) } // debugging