From 521f1f80feee884d38779d967745c52b49ab86b8 Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Mon, 21 Oct 2019 12:26:50 +0200 Subject: [PATCH] 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 Reviewed-by: Michael Matloob --- go/packages/golist.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/go/packages/golist.go b/go/packages/golist.go index dbdc791e1eb..c581bce976c 100644 --- a/go/packages/golist.go +++ b/go/packages/golist.go @@ -1066,7 +1066,14 @@ func invokeGo(cfg *Config, args ...string) (*bytes.Buffer, error) { // TODO(matloob): command-line-arguments isn't correct here. "command-line-arguments", strings.Trim(stderr.String(), "\n")) 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