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 get` fails when repository ends with `.go` unless it has a trailing slash #32483

Open
wallyqs opened this issue Jun 7, 2019 · 8 comments

Comments

Projects
None yet
5 participants
@wallyqs
Copy link

commented Jun 7, 2019

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

$ go version
go version go1.12 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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/himitsu/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/himitsu/repos/lkjh-dev"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/xl/vzfvbyrs29s3t2mmh15ygmv00000gn/T/go-build506667951=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

When trying to fetch the latest version or a tag of the NATS Go client as follows, it fails with a no such file or directory error.

GO111MODULE=on go get github.com/nats-io/nats.go@latest
stat github.com/nats-io/nats.go: no such file or directory

GO111MODULE=on go get github.com/nats-io/nats.go@v1.8.1
stat github.com/nats-io/nats.go: no such file or directory

One workaround for this when using Go 1.12 is to append an extra slash at the end of the repository name and then add the explicit version as follows:

GO111MODULE=on go get github.com/nats-io/nats.go/@latest
...

# Explicit tag version
GO111MODULE=on go get github.com/nats-io/nats.go/@v1.8.0
go: finding github.com/nats-io/nats.go v1.8.0
go: downloading github.com/nats-io/nats.go v1.8.0
go: extracting github.com/nats-io/nats.go v1.8.0

What did you expect to see?

I expected go get to download the library as follows:

GO111MODULE=on go get github.com/nats-io/nats.go@v1.8.0
go: finding github.com/nats-io/nats.go v1.8.0
go: downloading github.com/nats-io/nats.go v1.8.0
go: extracting github.com/nats-io/nats.go v1.8.0

Or when not specifying a version either, expected for it to download the latest one:

GO111MODULE=on go get github.com/nats-io/nats.go
go: finding github.com/nats-io/nats.go v1.8.1
go: downloading github.com/nats-io/nats.go v1.8.1
go: extracting github.com/nats-io/nats.go v1.8.1

What did you see instead?

GO111MODULE=on go get github.com/nats-io/nats.go@v1.8.0
stat github.com/nats-io/nats.go: no such file or directory

Also when not specifying any version always fail, regardless of trailing slash or not:

GO111MODULE=on go get github.com/nats-io/nats.go/
stat github.com/nats-io/nats.go: no such file or directory

GO111MODULE=on go get github.com/nats-io/nats.go
stat github.com/nats-io/nats.go: no such file or directory

@bcmills bcmills changed the title cmd/go/: `go get` fails when repository ends with `.go` unless it has a trailing slash cmd/go: `go get` fails when repository ends with `.go` unless it has a trailing slash Jun 7, 2019

@bcmills bcmills added this to the Go1.14 milestone Jun 7, 2019

@bcmills

This comment has been minimized.

Copy link
Member

commented Jun 7, 2019

Paths ending in .go usually refer to source files rather than package or module paths; presumably that is the problem here.

CC @jayconrod

@gopherbot

This comment has been minimized.

Copy link

commented Jun 10, 2019

Change https://golang.org/cl/180923 mentions this issue: cmd/goget: support package ended with '.go'

@letientai299

This comment has been minimized.

Copy link

commented Jun 10, 2019

@dmitshur, I'm still quite new to golang project workflow, so, thanks for the reminder, and please guide me through this second CL.

My fix in above CL is basically trying load patterns ended with .go as go files, and if it fails, fall back to loading the patterns as packages.

@dmitshur

This comment has been minimized.

Copy link
Member

commented Jun 10, 2019

Thanks @letientai299. You should discuss the approach you've considered with @bcmills and @jayconrod here, since they're owners of cmd/go behavior, and see what they think.

trying load patterns ended with .go as go files, and if it fails, fall back to loading the patterns as packages.

I have a potential concern about it, in that it introduces unpredictable behavior. The same command invocation may act differently depending on whether or not a .go file exists and can be accessed without errors. I'm not sure of a better solution, I just wanted to point out the potential concern.

@bcmills bcmills removed the modules label Jun 10, 2019

@bcmills

This comment has been minimized.

Copy link
Member

commented Jun 10, 2019

Note that the same command also fails in GOPATH mode, at least as far back as 1.11.10:

$ GO111MODULE=off go1.12.5 get github.com/nats-io/nats.go
stat github.com/nats-io/nats.go: no such file or directory

$ GO111MODULE=off go1.11.10 get github.com/nats-io/nats.go
stat github.com/nats-io/nats.go: no such file or directory

Given the lack of other reports of this issue, perhaps nats-go should just pick a less ambiguous name for their module‽

(Or are there substantially more examples of this in the wild?)

@wallyqs

This comment has been minimized.

Copy link
Author

commented Jun 10, 2019

@bcmills yes you also have to add trailing slash if not using Go modules. From a similar past issue that is open it seems that this may have been introduced around Go 1.11, still ok in Go 1.10: #27096

@bcmills

This comment has been minimized.

Copy link
Member

commented Jun 10, 2019

@wallyqs, note that the concrete example of such a package in #27096 is also nats-io/nats.go.

@wallyqs

This comment has been minimized.

Copy link
Author

commented Jun 10, 2019

@bcmills I mean that the issue mentions others running into a similar issue, though we also commented on that issue. Btw thanks @letientai299 for looking at the possible fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.