Skip to content

Commit 3720d1e

Browse files
committed
go/packages: suppress go list -e error when directory outside modules
If an absolute directory path being listed is outside any modules, go list -e returns a non-zero exit status and non-empty stderr, but should suppress the error. This was causing a weird bug when golang.org/cl/186337 was submitted because that changed the conditions when -export was passed, which in turn affected how we suppressed the go list -e error (because -export causes a compile it overtriggers errors, so we explicitly suppress errors in that case). The way the error was being suppressed, no error was generated, and no fake package was generated (which go list is supposed to do), so the contains query fallback code wasn't run. Fixes golang/go#34265 Updates golang/go#34273 Change-Id: I1213cff0e03a62c6976e50db5b2d805aa3ddbb7a Reviewed-on: https://go-review.googlesource.com/c/tools/+/195065 Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 87d9f09 commit 3720d1e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

go/packages/golist.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,16 @@ func invokeGo(cfg *Config, args ...string) (*bytes.Buffer, error) {
940940
return bytes.NewBufferString(output), nil
941941
}
942942

943+
// Workaround for #34273. go list -e with GO111MODULE=on has incorrect behavior when listing a
944+
// directory outside any module.
945+
if len(stderr.String()) > 0 && strings.Contains(stderr.String(), "outside available modules") {
946+
output := fmt.Sprintf(`{"ImportPath": %q,"Incomplete": true,"Error": {"Pos": "","Err": %q}}`,
947+
// TODO(matloob): command-line-arguments isn't correct here.
948+
"command-line-arguments", strings.Trim(stderr.String(), "\n"))
949+
return bytes.NewBufferString(output), nil
950+
951+
}
952+
943953
// Workaround for an instance of golang.org/issue/26755: go list -e will return a non-zero exit
944954
// status if there's a dependency on a package that doesn't exist. But it should return
945955
// a zero exit status and set an error on that package.

0 commit comments

Comments
 (0)