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: go list inconsistently resolves empty paths to '.' #37300

Open
perillo opened this issue Feb 19, 2020 · 7 comments
Open

cmd/go: go list inconsistently resolves empty paths to '.' #37300

perillo opened this issue Feb 19, 2020 · 7 comments
Labels
Milestone

Comments

@perillo
Copy link

@perillo perillo commented Feb 19, 2020

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

$ go version
go version go1.14rc1 linux/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="/home/manlio/.local/bin"
GOCACHE="/home/manlio/.cache/go-build"
GOENV="/home/manlio/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/src/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/manlio/sdk/go1.14rc1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/manlio/sdk/go1.14rc1/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build552987847=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.14rc1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.14rc1
uname -sr: Linux 5.5.4-arch1-1
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.31.
gdb --version: GNU gdb (GDB) 9.1

What did you do?

Inside a module github.com/perillo/goprint:

$ go list -m ""

What did you expect to see?

github.com/perillo/goprint

What did you see instead?

go list -m: module : not a known dependency

go list "" works fine. Is there a reason for this asymmetry?

If an empty module path must be rejected, the error message should be changed.

Thanks.

@perillo perillo changed the title cmd/go: go list -m fails when passing an empty module patj cmd/go: go list -m fails when passing an empty module path Feb 19, 2020
@bcmills
Copy link
Member

@bcmills bcmills commented Feb 19, 2020

go list "" works fine. Is there a reason for this asymmetry?

That looks like a bug in go list without -m.

If an empty module path must be rejected, the error message should be changed.

Agreed: we should fix the error message from go list -m.

CC @jayconrod @matloob

@bcmills bcmills added the NeedsFix label Feb 19, 2020
@bcmills bcmills added this to the Backlog milestone Feb 19, 2020
@perillo
Copy link
Author

@perillo perillo commented Feb 19, 2020

go list "" may be convenient.

The https://godoc.org/golang.org/x/tools/go/packages package uses the function

invokeGo(verb string, args ...string)

but if a program expect only one package, it may use

invokeGo(verb string, arg string)
@bcmills
Copy link
Member

@bcmills bcmills commented Feb 19, 2020

go list . is well-defined. go list "" is not: the empty string is not a valid package pattern.

@perillo
Copy link
Author

@perillo perillo commented Feb 19, 2020

Some more examples for go list without -m:

$ go list "" flag "" ""
github.com/perillo/goprint
flag
go list flag "" ""
flag
github.com/perillo/goprint

When outside a module they return an error:

go: cannot find main module; see 'go help modules'

This means that "" is treated the same as ".".

@bcmills bcmills changed the title cmd/go: go list -m fails when passing an empty module path cmd/go: go list inconsistently resolves empty paths to '.' Feb 19, 2020
@bcmills
Copy link
Member

@bcmills bcmills commented Feb 19, 2020

Those examples are consistent with "" being resolved to the same as ..

I don't think a separate issue is needed. (I suspect that the same CL can easily cover both cases, and if not we can fork another issue at that point.)

@perillo
Copy link
Author

@perillo perillo commented Feb 19, 2020

@bcmills: don't we have two different issues here?

  1. go list -m "" returns the wrong error message
  2. go list inconsistently resolve empty paths to "."
@bcmills
Copy link
Member

@bcmills bcmills commented Feb 19, 2020

Both symptoms arise from the same root cause: failure to diagnose empty-string arguments during argument parsing.

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
2 participants
You can’t perform that action at this time.