Skip to content

Commit

Permalink
go/packages: suppress go list -e error when directory outside modules
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
matloob authored and clintjedwards committed Sep 19, 2019
1 parent fbfc602 commit 1fd660a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions go/packages/golist.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,16 @@ func invokeGo(cfg *Config, args ...string) (*bytes.Buffer, error) {
return bytes.NewBufferString(output), nil
}

// Workaround for #34273. go list -e with GO111MODULE=on has incorrect behavior when listing a
// directory outside any module.
if len(stderr.String()) > 0 && strings.Contains(stderr.String(), "outside available modules") {
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
// status if there's a dependency on a package that doesn't exist. But it should return
// a zero exit status and set an error on that package.
Expand Down

0 comments on commit 1fd660a

Please sign in to comment.