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>
diff --git a/go/packages/golist.go b/go/packages/golist.go
index dbdc791..c581bce 100644
--- a/go/packages/golist.go
+++ b/go/packages/golist.go
@@ -1066,7 +1066,14 @@
 				// 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