1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:54:40 -07:00

go/packages: correct logging of driver stderr

This moves the GOPACKAGESPRINTDRIVERERRORS and stderr.Bytes() checks to after
the driver command is run. Before, these were checked before the driver command
was run and so stderr was always empty.

Change-Id: I8fb3d45eab5dacee3871d454038fbcc1b6351cb6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207581
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Jeff Hodges 2019-11-17 18:26:56 -08:00 committed by Brad Fitzpatrick
parent 0f69de236b
commit 7093a17b04

View File

@ -84,13 +84,14 @@ func findExternalDriver(cfg *Config) driver {
cmd.Stdin = bytes.NewReader(req) cmd.Stdin = bytes.NewReader(req)
cmd.Stdout = buf cmd.Stdout = buf
cmd.Stderr = stderr cmd.Stderr = stderr
if len(stderr.Bytes()) != 0 && os.Getenv("GOPACKAGESPRINTDRIVERERRORS") != "" {
fmt.Fprintf(os.Stderr, "%s stderr: <<%s>>\n", cmdDebugStr(cmd, words...), stderr)
}
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("%v: %v: %s", tool, err, cmd.Stderr) return nil, fmt.Errorf("%v: %v: %s", tool, err, cmd.Stderr)
} }
if len(stderr.Bytes()) != 0 && os.Getenv("GOPACKAGESPRINTDRIVERERRORS") != "" {
fmt.Fprintf(os.Stderr, "%s stderr: <<%s>>\n", cmdDebugStr(cmd, words...), stderr)
}
var response driverResponse var response driverResponse
if err := json.Unmarshal(buf.Bytes(), &response); err != nil { if err := json.Unmarshal(buf.Bytes(), &response); err != nil {
return nil, err return nil, err