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: does not verify existence of replace directory #28032

Open
komuw opened this issue Oct 5, 2018 · 8 comments
Open

cmd/go: does not verify existence of replace directory #28032

komuw opened this issue Oct 5, 2018 · 8 comments
Labels
modules NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@komuw
Copy link
Contributor

komuw commented Oct 5, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11.1 linux/amd64

Does this issue reproduce with the latest release?

yes

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

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

What did you do?

create this go.mod file;

module aha

require (
	github.com/davecgh/go-spew v1.1.1 // indirect
	github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect
	github.com/gin-gonic/gin v1.3.0 // indirect
	github.com/golang/protobuf v1.2.0 // indirect
	github.com/json-iterator/go v1.1.5 // indirect
	github.com/mattn/go-isatty v0.0.4 // indirect
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
	github.com/modern-go/reflect2 v1.0.1 // indirect
	github.com/pmezard/go-difflib v1.0.0 // indirect
	github.com/rs/cors v1.5.0
	github.com/stretchr/testify v1.2.2 // indirect
	github.com/ugorji/go/codec v0.0.0-20180927125128-99ea80c8b19a // indirect
	golang.org/x/net v0.0.0-20181005035420-146acd28ed58 // indirect
	golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect
	golang.org/x/sys v0.0.0-20181004145325-8469e314837c // indirect
	gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
	gopkg.in/go-playground/validator.v8 v8.18.2 // indirect
	gopkg.in/yaml.v2 v2.2.1 // indirect
)

replace github.com/rs/cors/wrapper/gin => ../nonexistentDirectory/AntherDirectoryThatDoesNotExist

and this main.go file;

package main

import (
	"fmt"

	"github.com/rs/cors/wrapper/gin"
)

func main() {
	fmt.Println(gin.Options{})
}

then run;

go mod tidy && \
go mod verify && \
go run main.go

What did you expect to see?

a failure with a nice error message pointing out that the path ../nonexistentDirectory/AntherDirectoryThatDoesNotExist does not exist.

What did you see instead?

all modules verified
{[] <nil> [] [] [] 0 false false false}
@komuw
Copy link
Contributor Author

komuw commented Oct 5, 2018

very odd; if I however have the following;
go.mod

module aha
require github.com/pkg/errors v0.8.0
replace github.com/pkg/errors => ../nonexistentDirectory/AntherDirectoryThatDoesNotExist

and main.go

package main

import (
	"fmt"

	"github.com/pkg/errors"
)

func main() {
	fmt.Println(errors.New("Hey ya"))
}

I get a nice error message;

go mod tidy && \
go mod verify && \
go run main.go
go: parsing ../nonexistentDirectory/AntherDirectoryThatDoesNotExist/go.mod: open /home/myname/Downloads/nonexistentDirectory/AntherDirectoryThatDoesNotExist/go.mod: no such file or directory
go: error loading module requirements

@komuw
Copy link
Contributor Author

komuw commented Oct 5, 2018

@gopherbot please add modules

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 5, 2018
@bcmills bcmills added this to the Go1.12 milestone Oct 5, 2018
@ianlancetaylor ianlancetaylor changed the title go does not verify existence of replace directory cmd/go: does not verify existence of replace directory Nov 28, 2018
@bcmills
Copy link
Contributor

bcmills commented Dec 6, 2018

go mod tidy probably does not report the error because go mod tidy has trouble reporting errors in general (#27063).

go mod verify correctly does not report the error, because it only checks downloaded modules and in this case the replacement is not a downloaded module.

go run main.go correctly does not report the error, because it has no reason to examine the module github.com/rs/cors/wrapper/gin at all: the module at that path is not in the set of active modules, and the import in main.go can be satisfied from a different module that is active (specifically, github.com/rs/cors v1.5.0).

@bcmills
Copy link
Contributor

bcmills commented Dec 6, 2018

I'm not sure that go mod tidy should report an error here either. It does not generally change replace or exclude directives, and the require directives here are consistent and satisfy all of the imports of package main.

@bcmills
Copy link
Contributor

bcmills commented Dec 6, 2018

There are three possible directions we could go here:

  1. We could make go mod tidy verify the consistency of replace directives even if they are not used.
  2. We could make go mod tidy remove replace directives that have no effect.
  3. We could leave the behavior of go mod tidy as is.

I'm not sure which of those makes the most sense. I'll discuss with @rsc.

@bcmills bcmills added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Dec 6, 2018
@bcmills bcmills modified the milestones: Go1.12, Go1.13 Dec 6, 2018
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 6, 2018
@komuw
Copy link
Contributor Author

komuw commented Jan 4, 2019

We could make go mod tidy verify the consistency of replace directives even if they are not used.

This is what I would have expected a command calledtidy todo; tidy up go.mod

from go help mod tidy

Tidy makes sure ........, and it removes unused modules that
don't provide any relevant packages.
(emphasis is mine)

@bcmills
Copy link
Contributor

bcmills commented Jan 17, 2019

I'm leaning toward option (2): if a replace directive has no effect in the main module, it has no effect anywhere, and go mod tidy should remove it.

@komuw
Copy link
Contributor Author

komuw commented Jan 17, 2019 via email

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@rsc rsc unassigned bcmills Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants