1
0
mirror of https://github.com/golang/go synced 2024-11-19 01:24:39 -07:00

go/packages: handle "outside module root" error printed to stderr by go list -e

Running `go ../...` fails if the glob refers to modules that lie
outside the current module:

$ go list ../...
go: pattern ../... refers to dir /tmp/foo, outside module root /tmp/foo/b

This is very similar to the "outside available modules" error you get
when not using globs.

Change-Id: I766af058d1ee685fdbfb4e60512a342437fecf14
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202437
Run-TryBot: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Dominik Honnef 2019-10-21 12:26:50 +02:00
parent 8456940f41
commit 521f1f80fe

View File

@ -1066,7 +1066,14 @@ func invokeGo(cfg *Config, args ...string) (*bytes.Buffer, error) {
// TODO(matloob): command-line-arguments isn't correct here. // TODO(matloob): command-line-arguments isn't correct here.
"command-line-arguments", strings.Trim(stderr.String(), "\n")) "command-line-arguments", strings.Trim(stderr.String(), "\n"))
return bytes.NewBufferString(output), nil return bytes.NewBufferString(output), nil
}
// Another variation of the previous error
if len(stderr.String()) > 0 && strings.Contains(stderr.String(), "outside module root") {
output := fmt.Sprintf(`{"ImportPath": %q,"Incomplete": true,"Error": {"Pos": "","Err": %q}}`,
// TODO(matloob): command-line-arguments isn't correct here.
"command-line-arguments", strings.Trim(stderr.String(), "\n"))
return bytes.NewBufferString(output), nil
} }
// Workaround for an instance of golang.org/issue/26755: go list -e will return a non-zero exit // Workaround for an instance of golang.org/issue/26755: go list -e will return a non-zero exit