If invoked 'go list' command fails, show its stderr.

Test: manual
Change-Id: I776b71f8b6c6c3d46d60e790d944282efd6d55d7
This commit is contained in:
Sasha Smundak 2022-04-13 18:45:57 -07:00
parent ef4a5a3028
commit d5fc469dd8

View file

@ -335,12 +335,15 @@ Usage: %s [--rewrite <pkg-prefix>=<replace>] [-exclude <package>] [-regen <file>
} }
cmd := exec.Command("go", "list", "-json", "./...") cmd := exec.Command("go", "list", "-json", "./...")
output, err := cmd.Output() var stdoutb, stderrb bytes.Buffer
if err != nil { cmd.Stdout = &stdoutb
fmt.Fprintf(os.Stderr, "Failed to dump the go packages: %v\n", err) cmd.Stderr = &stderrb
if err := cmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Running %q to dump the Go packages failed: %v, stderr:\n%s\n",
cmd.String(), err, stderrb.Bytes())
os.Exit(1) os.Exit(1)
} }
decoder := json.NewDecoder(bytes.NewReader(output)) decoder := json.NewDecoder(bytes.NewReader(stdoutb.Bytes()))
pkgs := []*GoPackage{} pkgs := []*GoPackage{}
pkgMap := map[string]*GoPackage{} pkgMap := map[string]*GoPackage{}