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 <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Heschi Kreinick 2018-10-17 16:50:47 -04:00
parent 7099c87f61
commit 4a1b41eed1
1 changed files with 10 additions and 12 deletions

View File

@ -588,7 +588,7 @@ func golist(cfg *Config, args []string) (*bytes.Buffer, error) {
// Catastrophic error: // Catastrophic error:
// - executable not found // - executable not found
// - context cancellation // - 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? // 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. // (despite the -e flag) and the Export field is blank.
// Do not fail in that case. // Do not fail in that case.
if !usesExportData(cfg) { 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". // As of writing, go list -export prints some non-fatal compilation
// Due to the -e flag, this should be empty. // errors to stderr, even with -e set. We would prefer that it put
// However, in -export mode it contains build errors. // them in the Package.Error JSON (see http://golang.org/issue/26319).
// Should go list save build errors in the Package.Error JSON field? // In the meantime, there's nowhere good to put them, but they can
// See https://github.com/golang/go/issues/26319. // be useful for debugging. Print them if $GOPACKAGESPRINTGOLISTERRORS
// If so, then we should continue to print stderr as go list // is set.
// will be silent unless something unexpected happened. if len(stderr.Bytes()) != 0 && os.Getenv("GOPACKAGESPRINTGOLISTERRORS") != "" {
// If not, perhaps we should suppress it to reduce noise. fmt.Fprintf(os.Stderr, "go %v stderr: <<\n%s\n>>\n", args, stderr)
if len(stderr.Bytes()) != 0 {
fmt.Fprintf(os.Stderr, "go list stderr <<%s>>\n", stderr)
} }
// debugging // debugging