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 with absolute path reports 'malformed module path: empty path element' #38038

Closed
perillo opened this issue Mar 24, 2020 · 8 comments
Closed
Milestone

Comments

@perillo
Copy link

@perillo perillo commented Mar 24, 2020

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

$ go version
go version go1.14.1 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="*.local"
GONOPROXY=""
GONOSUMDB="*.local"
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/src/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/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-build155643044=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.14.1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.14.1
uname -sr: Linux 5.5.10-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?

I noted that go get golang.org/x/mod/module/// does not report an error. Probably it should, since the path specified is not a valid import path.

The trailing slashes are removed before doing the HTTP request.

Thanks


EDIT by jayconrod: see comments below. go get $(pwd) reports an error when run in the module root directory if no package is present.

@mvdan

This comment has been minimized.

Copy link
Member

@mvdan mvdan commented Mar 24, 2020

Following the same idea, should go build ./foo/ fail?

@dmitshur

This comment has been minimized.

Copy link
Member

@dmitshur dmitshur commented Mar 24, 2020

@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Mar 24, 2020

This doesn't seem like a bug. Why should cmd/go reject these paths?

Arguments to go get and other build commands aren't expected to be valid import paths. We allow file paths, directory paths, local paths (../foo), patterns (with ...), metapackages (cmd, std, all), non-clean import paths and so on. On Windows, paths may also use backslashes.

This is pretty convenient, I think. Changing this would break scripts and automation, too.

@bcmills bcmills modified the milestones: Backlog, Unplanned Mar 24, 2020
@perillo

This comment has been minimized.

Copy link
Author

@perillo perillo commented Mar 24, 2020

@jayconrod you are right, thanks. I was not aware that go get supported patterns, but it is clearly documented. go get golang.org/x/mod/... works as expected, as an example.

I'm not sure what go get ./pkg or go get ... is supposed to do, however.

Out of curiosity I tried, inside a module.

$ go get -v ~/src/go/src/test.local/bar
go get /home/manlio/src/go/src/test.local/bar: malformed module path "/home/manlio/src/go/src/test.local/bar": empty path element

with a little expectation for go get to get the local module (like pip with Python, if I remember correctly).

On the other hand (using the same test.local/bar package)

$ go get -v ../bar
go get ../bar: path /tmp/.tmp/bar is not a package in module rooted at /tmp/.tmp/foo

When outside a module

go get -v ../bar
go: cannot find main module; see 'go help modules'

That is a different error message, compared to the case of getting a remote module. This means that go get does not handle .../bar as a remote import path. But how does go get handle it?

Thanks.

@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Mar 24, 2020

go get takes a set of packages, then updates the modules that provide those packages to the latest version (or any other version named after an @ suffix). The main module can't be updated to a different version, so it usually doesn't make sense to go get packages in the main module unless you're using the -u flag flag (which updates modules that provide dependencies of the named packages).

For go get -v ~/src/go/src/test.local/bar, the error message seems bad. Where is go.mod for that? What's the module path? What's in that directory?

For go get -v ../bar, that message seems correct. When naming a package with a relative path, you can only refer to packages in active modules. So that's either the main module, something in the module cache, or something on the right side of a replace directive.

For go get -v ../bar outside a module, relative paths can't really work since there are no active modules. So that message seems okay, though not great.

@perillo

This comment has been minimized.

Copy link
Author

@perillo perillo commented Mar 24, 2020

For go get -v ~/src/go/src/test.local/bar, the go.mod file inside that directory is

module test.local/bar

go 1.13

Thanks.

@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Mar 24, 2020

Thanks, reproduced that one with 1.14.1.

If it's all right, I'll repurpose this issue for fixing that message specifically. I think the other behaviors and messages are correct.

@jayconrod jayconrod changed the title cmd/go: go get should reject import paths with trailing slashes cmd/go: go get with absolute path reports 'malformed module path: empty path element' Mar 24, 2020
@jayconrod jayconrod modified the milestones: Unplanned, Backlog Mar 24, 2020
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Apr 1, 2020

Change https://golang.org/cl/226857 mentions this issue: cmd/go: report 'go get' errors for absolute paths outside module root

@gopherbot gopherbot closed this in 44ae947 Apr 6, 2020
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
6 participants
You can’t perform that action at this time.