1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:04:42 -07:00

go/packages: give a better error if 'go' is missing

If we can't execute the go command, check to see if it exists. If it doesn't,
say so in the error.

Fixes golang/go#29552

Change-Id: Iffd2db5fc8f1daa2e458eaa326b27d9a0d971b6b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/168777
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Michael Matloob 2019-03-21 16:31:13 -04:00
parent 86483bace6
commit 43e94f7338

View File

@ -7,6 +7,7 @@ package packages
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"go/types" "go/types"
"io/ioutil" "io/ioutil"
@ -743,6 +744,11 @@ func invokeGo(cfg *Config, args ...string) (*bytes.Buffer, error) {
// Catastrophic error: // Catastrophic error:
// - executable not found // - executable not found
// - context cancellation // - context cancellation
// Check for executable not existing.
if _, err := exec.LookPath("go"); err != nil {
return nil, errors.New("'go list' driver requires 'go' to be installed")
}
return nil, fmt.Errorf("couldn't exec 'go %v': %s %T", args, err, err) return nil, fmt.Errorf("couldn't exec 'go %v': %s %T", args, err, err)
} }