golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.65k stars 17.61k forks source link

cmd/go: misleading error message for replacement module with capital letters #38220

Closed retgits closed 4 years ago

retgits commented 4 years ago

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

$ go version
go version go1.14.1 darwin/amd64

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/lstigter/Library/Caches/go-build"
GOENV="/Users/lstigter/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/lstigter/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
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/4b/hq3khbrx30b_wk3fz63z9vww0000gq/T/go-build752664778=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I forked a project from https://github.com/wavefrontHQ/wavefront-lambda-go which doesn't use Go modules yet to help them adopt Go modules. I created a go.mod file, using

$ go mod init github.com/wavefrontHQ/wavefront-lambda-go
$ go mod tidy

That results in the go.mod file

module github.com/wavefronthq/wavefront-lambda-go

go 1.14

require (
    github.com/aws/aws-lambda-go v1.12.1
    github.com/rcrowley/go-metrics v0.0.0-20190706150252-9beb055b7962
    github.com/wavefronthq/go-metrics-wavefront v0.9.0
)

The resulting code was committed to the forked repo https://github.com/retgits/wavefront-lambda-go

In a project where I want to use this new module, I added a replace directive into my go.mod file to point to the new location

module github.com/retgits/acme-serverless-payment

replace github.com/wavefronthq/wavefront-lambda-go => github.com/retgits/wavefront-lambda-go v0.0.0-20200402174306-c89629d5856a

go 1.13

require (
    github.com/aws/aws-lambda-go v1.15.0
    github.com/aws/aws-sdk-go v1.29.27
    github.com/getsentry/sentry-go v0.5.1
    github.com/gofrs/uuid v3.2.0+incompatible
    github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
    github.com/pulumi/pulumi v1.12.1
    github.com/pulumi/pulumi-aws v1.26.0
    github.com/retgits/creditcard v0.6.0
    github.com/retgits/pulumi-helpers v0.1.3
    github.com/wavefronthq/wavefront-lambda-go v0.0.0-20190812171804-d9475d6695cc
    gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
    gopkg.in/yaml.v2 v2.2.8 // indirect
)

Running any of the go commands throws an error

What did you expect to see?

$go mod tidy
<no errors>

What did you see instead?

$ go mod tidy                                              
go: github.com/retgits/wavefront-lambda-go@v0.0.0-20200402161507-0edb5b9bfe10: parsing go.mod:
        module declares its path as: github.com/wavefrontHQ/wavefront-lambda-go
                but was required as: github.com/retgits/wavefront-lambda-go

The error message is a little misleading, and as @jayconrod discovered is about the capitalization of wavefrontHQ. After changing it all to lowercase in the module, it was solved.

jayconrod commented 4 years ago

This error was also printed by go list -m all. Since it popped up during module loading, tools like go mod graph and go mod why weren't helpful for finding where the module was loaded (though in this case, it was loaded from the main module).

The error message should use the original module's path, not the replacement module path on the "required as" line.

go: github.com/retgits/wavefront-lambda-go@v0.0.0-20200402161507-0edb5b9bfe10: parsing go.mod:
        module declares its path as: github.com/wavefrontHQ/wavefront-lambda-go
                but was required as: github.com/wavefronthq/wavefront-lambda-go
gopherbot commented 4 years ago

Change https://golang.org/cl/227097 mentions this issue: cmd/go: report original module path in error parsing replaced go.mod