Skip to content

Commit d8a2a07

Browse files
committed
go/packages: improve go invocation errors
Rather than coming up with an ad-hoc error message, use the friendly errors from the gocommand package. I noticed this because the latter is missing the verb. I *think* this is generally an improvement; instead of seeing a massive command line, users just see the actual error from the go command. Even if it's not, I'd rather improve the single source of the error than play whack-a-mole. Change-Id: Ib110eaac6c3984e617339cf14cffe3b59f33591b Reviewed-on: https://go-review.googlesource.com/c/tools/+/287033 Trust: Heschi Kreinick <[email protected]> Run-TryBot: Heschi Kreinick <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 19db92e commit d8a2a07

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

go/packages/golist.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"encoding/json"
1111
"fmt"
1212
"go/types"
13-
exec "golang.org/x/sys/execabs"
1413
"io/ioutil"
1514
"log"
1615
"os"
@@ -23,6 +22,7 @@ import (
2322
"sync"
2423
"unicode"
2524

25+
exec "golang.org/x/sys/execabs"
2626
"golang.org/x/tools/go/internal/packagesdriver"
2727
"golang.org/x/tools/internal/gocommand"
2828
"golang.org/x/xerrors"
@@ -865,7 +865,7 @@ func (state *golistState) invokeGo(verb string, args ...string) (*bytes.Buffer,
865865
if gocmdRunner == nil {
866866
gocmdRunner = &gocommand.Runner{}
867867
}
868-
stdout, stderr, _, err := gocmdRunner.RunRaw(cfg.Context, inv)
868+
stdout, stderr, friendlyErr, err := gocmdRunner.RunRaw(cfg.Context, inv)
869869
if err != nil {
870870
// Check for 'go' executable not being found.
871871
if ee, ok := err.(*exec.Error); ok && ee.Err == exec.ErrNotFound {
@@ -886,7 +886,7 @@ func (state *golistState) invokeGo(verb string, args ...string) (*bytes.Buffer,
886886

887887
// Related to #24854
888888
if len(stderr.String()) > 0 && strings.Contains(stderr.String(), "unexpected directory layout") {
889-
return nil, fmt.Errorf("%s", stderr.String())
889+
return nil, friendlyErr
890890
}
891891

892892
// Is there an error running the C compiler in cgo? This will be reported in the "Error" field
@@ -999,7 +999,7 @@ func (state *golistState) invokeGo(verb string, args ...string) (*bytes.Buffer,
999999
// TODO(matloob): Remove these once we can depend on go list to exit with a zero status with -e even when
10001000
// packages don't exist or a build fails.
10011001
if !usesExportData(cfg) && !containsGoFile(args) {
1002-
return nil, fmt.Errorf("go %v: %s: %s", args, exitErr, stderr)
1002+
return nil, friendlyErr
10031003
}
10041004
}
10051005
return stdout, nil

0 commit comments

Comments
 (0)