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: malformed module path with retract v2+ #44494

Closed
seankhliao opened this issue Feb 22, 2021 · 14 comments
Closed

cmd/go: malformed module path with retract v2+ #44494

seankhliao opened this issue Feb 22, 2021 · 14 comments

Comments

@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Feb 22, 2021

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

go version go1.16 linux/amd64
go version devel +0f66fb7b85 Sun Feb 21 02:25:41 2021 +0000 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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/arccy/.cache/go-build"
GOENV="/home/arccy/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/arccy/.data/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/arccy/.data/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/arccy/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/arccy/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel +0f66fb7b85 Sun Feb 21 02:25:41 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/arccy/testrepo-291/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1689737487=/tmp/go-build -gno-record-gcc-switches"

What did you do?

add a retract directive to a v2+ module and run go mod tidy

module go.seankhliao.com/testrepo-291/v2

go 1.16

retract v2.0.0

What did you expect to see?

no error

What did you see instead?

» go mod tidy
go: errors parsing go.mod:
/home/arccy/testrepo-291/go.mod:5: malformed module path "": empty string
@komuw
Copy link
Contributor

@komuw komuw commented Feb 22, 2021

I had reported a slight variant of this in gophers slack, where I was trying to retract a version 2 while the module is still in version 0.

repro:

mkdir -p /tmp/example; cd /tmp/example; go mod init example
rm -rf main.go
tee -a main.go <<EOF
package main
func main(){println("hello")}
EOF
go mod edit -retract=v2.0.2
go mod tidy

The error message I got is;

go: errors parsing go.mod:
/tmp/example/go.mod:5: malformed module path "": empty string

Seankhliao pointed out it should not be possible to retract a v2 while still in v0.
So, I'm just posting this here so that the error message can be improved; malformed module path would lead someone to believe that the thing they need to fix is their module name/path

@bcmills bcmills added this to the Go1.17 milestone Feb 22, 2021
@bcmills
Copy link
Member

@bcmills bcmills commented Feb 22, 2021

@bcmills
Copy link
Member

@bcmills bcmills commented Feb 22, 2021

@gopherbot, please backport to Go 1.16.

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 22, 2021

Backport issue(s) opened: #44496 (for 1.16).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@bcmills
Copy link
Member

@bcmills bcmills commented Feb 22, 2021

Just FYI: this is not fixed by CL 295150, so #44497 appears to be unrelated.

@jayconrod jayconrod self-assigned this Feb 22, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 24, 2021

Change https://golang.org/cl/296130 mentions this issue: modfile: defer fixing versions in retract directives

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 24, 2021

Change https://golang.org/cl/296131 mentions this issue: cmd: upgrade golang.org/x/mod to fix go.mod parser

gopherbot pushed a commit to golang/mod that referenced this issue Feb 25, 2021
VersionFixers require both a path and a version: if the version is
non-canonical (like a branch name), they generally need the path to
look up the proper version. This is fine for require, replace, and
exclude directives, since the path is specified with each version. For
retract directives, the path comes from the module directive, which
may appear later in the file. Previously, we just used the empty
string, but this breaks reasonable implementations.

With this change, we leave retracted versions alone until the file has
been completely parsed, then we apply the version fixer to each
retract directive. We report an error if retract is used without a
module directive.

For golang/go#44494

Change-Id: I99b7b8b55941c1fde4ee56161acfe854bcaf948d
Reviewed-on: https://go-review.googlesource.com/c/mod/+/296130
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
@gopherbot gopherbot closed this in bcac57f Feb 25, 2021
@komuw
Copy link
Contributor

@komuw komuw commented Feb 25, 2021

@jayconrod Thanks for working on & closing this.
However, if someone edits the go.mod file and adds a retract, then they still get a confusing error message when running go mod tidy or go build

mkdir -p /tmp/example; cd /tmp/example; gotip mod init example
rm -rf main.go
tee -a main.go <<EOF
package main
func main(){println("hello")}
EOF
rm -rf go.mod
tee -a go.mod <<EOF
module example
go 1.17
retract v2.0.2
EOF
gotip mod tidy
go: errors parsing go.mod:
/tmp/example/go.mod:3: malformed module path "": empty string

I still think this error message could be better. malformed module path implies that what is wrong with our mod file is the module path, yet it isn't

@bcmills bcmills reopened this Feb 25, 2021
@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Feb 25, 2021

@komuw Thanks. Looks like things are still not quite right.

Could you verify what commit you're building from? I'm actually seeing a different error at 5f15af1.

go: errors parsing go.mod:
/tmp/example/go.mod:3: malformed module path "example": missing dot in first path element
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 25, 2021

Change https://golang.org/cl/296590 mentions this issue: cmd/go/internal/modload: don't query when fixing canonical versions

@komuw
Copy link
Contributor

@komuw komuw commented Feb 26, 2021

@jayconrod
I have just updated my gotip;

gotip version
go version devel +e25040d Fri Feb 26 02:52:33 2021 +0000 darwin/amd64

and the error I now get is;

go: errors parsing go.mod:
/tmp/example/go.mod:3: malformed module path "example": missing dot in first path element
@bcmills
Copy link
Member

@bcmills bcmills commented Feb 26, 2021

@komuw, we're getting closer, then! The real problem now, I think, is that it is not possible to retract a path that cannot be fetched remotely (because how would users be notified of the retraction?).

But we still need a better error message for that case. 🙂

@gopherbot gopherbot closed this in 5fafc0b Mar 1, 2021
@komuw
Copy link
Contributor

@komuw komuw commented Mar 1, 2021

gotip version
go version devel +a400eb3 Mon Mar 1 15:24:01 2021 +0000 darwin/amd64
gotip mod tidy

go: errors parsing go.mod:
/tmp/example/go.mod:3: retract example: version "v2.0.2" invalid: should be v0 or v1, not v2
go build .

go: errors parsing go.mod:
/tmp/example/go.mod:3: malformed module path "": empty string

@jayconrod Thanks for fixing the error message. The go build error message is still off, is that intentional?
Personally, I'm okay with it since I usually run tidy before build.

@komuw
Copy link
Contributor

@komuw komuw commented Mar 1, 2021

gotip version
go version devel +a400eb3 Mon Mar 1 15:24:01 2021 +0000 darwin/amd64
gotip mod tidy

go: errors parsing go.mod:
/tmp/example/go.mod:3: retract example: version "v2.0.2" invalid: should be v0 or v1, not v2
go build .

go: errors parsing go.mod:
/tmp/example/go.mod:3: malformed module path "": empty string

@jayconrod Thanks for fixing the error message. The go build error message is still off, is that intentional?
Personally, I'm okay with it since I usually run tidy before build.

Apologies, I just realised I was running go build . instead of gotip build .

gotip build .

go: errors parsing go.mod:
/tmp/example/go.mod:3: retract example: version "v2.0.2" invalid: should be v0 or v1, not v2

using gotip build . returns the correct error

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