go mod tidy: "no matching versions for query "latest""

go version

go version go1.19.4 linux/amd64

go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ishmeets/.cache/go-build"
GOENV="/home/ishmeets/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS="-modcacherw"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ishmeets/go/pkg/mod"
GONOPROXY="ssd-git.juniper.net"
GONOSUMDB="ssd-git.juniper.net"
GOOS="linux"
GOPATH="/home/ishmeets/go"
GOPRIVATE="ssd-git.juniper.net"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/ishmeets/.local"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/ishmeets/.local/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/ishmeets/go/pkg/mod/xxx/xxx/fabric-mgmt-api@v0.0.0-20230119053658-acd5a1e86128/go.mod"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2990676511=/tmp/go-build -gno-record-gcc-switches"

When I do go mod tidy in the module cache, it’s giving this error.

xxx/xxx/fabric-mgmt-api/internal/app/network-mgmt/xxx/primitives/mock: no matching versions for query "latest"

I have placed the mock files at location that is having the package mock. Still, error is there.

Things I have tried.

  1. Copy the repo outside GOMODCACHE. Then go mod tidy works. cp -a ~/go/pkg/mod/xxx/xxx/fabric-mgmt-api@v0.0.0-20230119053658-acd5a1e86128 ~/workspace/ cd ~/workspace/fabric-mgmt-api@v0.0.0-20230119053658-acd5a1e86128 && go mod tidy
  2. Used go 1.18. This also works.
  3. Tried on go 1.20.1. It doesn’t work.

Hi @Ishmeet, welcome to the forum!

Under normal circumstances, it should not be necessary to run Go commands inside the module cache. Can you explain what you are trying to achieve?