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 mod -replace without old version creates invalid go.mod #26373

Closed
myitcv opened this issue Jul 13, 2018 · 2 comments
Closed

cmd/go: go mod -replace without old version creates invalid go.mod #26373

myitcv opened this issue Jul 13, 2018 · 2 comments

Comments

@myitcv
Copy link
Member

myitcv commented Jul 13, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version devel +8a330454dc Fri Jul 13 03:53:00 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

No, working with tip.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/tmp/tmp.KCiNC02W22"
GOPROXY=""
GORACE=""
GOROOT="/home/myitcv/gos"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/tmp.KCiNC02W22/hello/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-build520682053=/tmp/go-build -gno-record-gcc-switches"

What did you do?

cd `mktemp -d`
export GOPATH=$PWD
mkdir hello
cd hello
go mod -init -module example.com/hello
go mod -require github.com/gopherjs/gopherjs@master
go mod -replace github.com/gopherjs/gopherjs=github.com/myitcv/gopherjs@vgo
cat go.mod
go mod -json

What did you expect to see?

The JSON representation of the go.mod file

What did you see instead?

go: errors parsing go.mod:
/tmp/tmp.KCiNC02W22/hello/go.mod:5: invalid module version ithub.com/myitcv/gopherjs: unrecognized import path "ithub.com/myitcv/gopherjs" (https fetch: Get https://ithub.com/myitcv/gopherjs?go-get=1: x509: certificate has expired or is not yet valid)

because the replace directive has incorrectly written the go.mod file:

$ cat go.mod
module example.com/hello

require github.com/gopherjs/gopherjs v0.0.0-20180628210949-0892b62f0d9f

replace github.com/gopherjs/gopherjs => ithub.com/myitcv/gopherjs vgo

Notice the replace target ithub.com/myitcv/gopherjs

/cc @rsc @bcmills

@myitcv myitcv added the modules label Jul 13, 2018
@myitcv myitcv added this to the Go1.11 milestone Jul 13, 2018
@bcmills
Copy link
Contributor

bcmills commented Jul 13, 2018

Off-by-one error in https://golang.org/cl/122404. Fix goes here:

old, new := strings.TrimSpace(arg[:i]), strings.TrimSpace(arg[i+2:])

We should add a test along with the fix. 🙂

@gopherbot
Copy link

Change https://golang.org/cl/123778 mentions this issue: cmd/go: fix module replace flag parsed bug

@golang golang locked and limited conversation to collaborators Jul 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants