Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: list -e -json [absolute directory outside gopath] fails #34273

Open
matloob opened this issue Sep 12, 2019 · 4 comments
Open

cmd/go: list -e -json [absolute directory outside gopath] fails #34273

matloob opened this issue Sep 12, 2019 · 4 comments
Labels
Milestone

Comments

@matloob
Copy link
Contributor

@matloob matloob commented Sep 12, 2019

What version of Go are you using (go version)?

$ go version
go version go1.13 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/matloob/Library/Caches/go-build"
GOENV="/Users/matloob/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/matloob/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/matloob/tools/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/f4/9p58ddnj40x58zchdb36p7lr004_sl/T/go-build066579511=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. set GO111MODULE=on
  2. change current directory to a module
  3. run go list -e -json /Users/matloob/Desktop (or list any existing directory outside of any module)

What did you expect to see?

exit status of 0, empty stderr, and a "Fake" package with errors set to a message saying the directory is outside any modules.

What did you see instead?

exit status of 1 and stderr of "go: directory ../Desktop outside available modules\n"

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 12, 2019

Change https://golang.org/cl/195065 mentions this issue: go/packages: suppress go list -e error when directory outside modules

gopherbot pushed a commit to golang/tools that referenced this issue Sep 12, 2019
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 <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
@bcmills bcmills added this to the Go1.14 milestone Sep 13, 2019
@bcmills
Copy link
Member

@bcmills bcmills commented Sep 13, 2019

Possibly related: #29280, #26909.

clintjedwards added a commit to clintjedwards/tools that referenced this issue Sep 19, 2019
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 <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@dominikh
Copy link
Member

@dominikh dominikh commented Oct 21, 2019

Another variation of this error:

$ go list ../...
go: pattern ../... refers to dir /tmp/foo, outside module root /tmp/foo/b
@dominikh
Copy link
Member

@dominikh dominikh commented Aug 2, 2020

I believe this is fixed in Go 1.15:

$ go version
go version go1.15beta1 linux/amd64
$ go list -json -e ../...
{
	"ImportPath": "../...",
	"Match": [
		"../..."
	],
	"Incomplete": true,
	"Error": {
		"ImportStack": [],
		"Pos": "",
		"Err": "pattern ../...: directory prefix .. outside available modules"
	}
}
$ echo $?
0
$ go list -e -json /home/dominikh/prj/src/sandbox/bar
{
	"ImportPath": "/home/dominikh/prj/src/sandbox/bar",
	"Match": [
		"/home/dominikh/prj/src/sandbox/bar"
	],
	"Incomplete": true,
	"Error": {
		"ImportStack": [],
		"Pos": "",
		"Err": "directory ../bar outside available modules"
	}
}
$ echo $?
0

git bisect points to one of these commits: 156c607, d11e1f9, 5a61de3

@matloob can you confirm this is now working as intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.