Go list returning directory starting with underscore on Ubuntu

784 views
Skip to first unread message

Michel Hollands

unread,
Mar 1, 2018, 12:22:43 PM3/1/18
to golang-nuts
Hello,

When running go list on Ubuntu the results are weird:

michel@michel-VirtualBox:~/git/grpcurl$ go list .
_/home/michel/git/grpcurl
michel@michel-VirtualBox:~/git/grpcurl$ 

Running the same on the Mac returns just grpcurl, which is the correct package.

The Go version is: 

go version go1.10 linux/amd64

The Ubuntu is 16.04.4 LTS which was freshly installed.

Any ideas about what could be wrong?

Thanks in advance,

Michel

Sebastien Binet

unread,
Mar 1, 2018, 1:07:39 PM3/1/18
to Michel Hollands, golang-nuts
Hi Michel,

I believe this is because you ran 'go list' from a directory outside of $GOPATH.

-s

sent from my droid

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michel Hollands

unread,
Mar 2, 2018, 3:37:56 AM3/2/18
to golang-nuts
Hello Sebastien,

After setting GOPATH it still occurs.

Thanks,

Michel 

Sebastien Binet

unread,
Mar 2, 2018, 3:43:39 AM3/2/18
to Michel Hollands, golang-nuts
Michel,

Could you post the output of 'go env' and the name of the directory from which you re-ran 'go list'?

-s

sent from my droid

Michel Hollands

unread,
Mar 2, 2018, 3:49:41 AM3/2/18
to golang-nuts
My mistake: there was no src directory under the gopath. It works now.

run...@uber.com

unread,
Apr 24, 2018, 11:41:43 PM4/24/18
to golang-nuts
Even with GOPATH set correctly, this can happen if you're running `go list ./...` and any directory in your current path is called `testdata`. ie. 

```
$ pwd
/home/user/xyz/testdata/whatever/
$ go list ./...
_/home/user/xyz/testdata/whatever/xxx
```

Dave Cheney

unread,
Apr 25, 2018, 1:05:10 AM4/25/18
to golang-nuts
If the path start with _ then it is not within the list of directories in your GOPATH.

run...@uber.com

unread,
Apr 25, 2018, 11:21:43 AM4/25/18
to golang-nuts
Not accurate. 

$ cat ~/code/scratch/repro-underscore-issue.sh
echo "GOPATH: $GOPATH"
mkdir -p $GOPATH/src/github.com/testcase/testdata
echo "package testdata" > $GOPATH/src/github.com/testcase/testdata/testdata.go
echo "Running go list ./..."
go list ./...

$ ~/code/scratch/repro-underscore-issue.sh
GOPATH: /Users/prungta/code/gocode
Running go list ./...
_/Users/prungta/code/gocode/src/github.com/testcase/testdata

Should this be a bug report? 

Daniel Martí

unread,
Oct 11, 2018, 12:25:54 PM10/11/18
to golang-nuts
I've encountered similar behavior with testdata directories within GOPATH,
when not in module-aware mode.

I found this thread while searching for answers, so I'm linking the issue I just
created in case anyone else runs into the same bug:

ipob...@kdu.cl

unread,
Nov 21, 2018, 3:09:29 PM11/21/18
to golang-nuts
Hi, I have the same problem, but I just want to scan my custom packages, when I do the go list. / ... it returns the correct routes, but with the underscore at the beginning of the routes, it is worth noting that the project does not have it inside the $ GOPATH (my $ GOPATH is in $ HOME / go)

tatsuya...@nftlearning.com

unread,
Jan 8, 2019, 3:17:01 PM1/8/19
to golang-nuts
I don't know it helps as I'm on zshell.  I replaced `GOPATH=~/works/golang` with `export GOPATH=~/works/golang`. then, it fixed.



Before

% go list ./server/...

_/Users/myuser/works/golang/src/mattermost-plugin-dialect/src/server



After
% go list ./server/...

mattermost-plugin-dialect/src/server

ufuk.o...@gmail.com

unread,
Jul 1, 2019, 3:42:20 PM7/1/19
to golang-nuts
Seeing paths that begin with "_" in the go list output means those modules are not in your GOPATH. In my case, I was collecting list of modules in a subshell (i.e. $(shell)) which doesn't have my GOPATH. If I run my go list command via backtick then it can use the global GOPATH define and works fine.
Reply all
Reply to author
Forward
0 new messages