go list: 没有与查询”latest”匹配的版本

huangapple go评论87阅读模式
英文:

go list: no matching versions for query "latest"

问题

我正在尝试在opentelemetry-collector-contrib项目上运行go list -mod=readonly -m -u -json all命令。

它失败并显示以下错误:

$ go list -mod=readonly -m -u -json all
go list -m: 加载模块 github.com/DataDog/datadog-agent/pkg/trace/exportable@v0.0.0-20201016145401-4646cf596b02 的撤销:没有匹配的版本查询“latest”
go list -m: 加载模块 github.com/influxdata/line-protocol/v2@v2.0.0-20210428091617-0567a5134992 的撤销:没有匹配的版本查询“latest”
$ echo $?
1

我正在使用go 1.16.5:

$ go version
go version go1.16.5 linux/amd64

我已经使用go clean -modcache清理了go缓存,但结果相同。

我在https://pkg.go.dev/上找到了这两个模块:

似乎对于_github.com/DataDog/datadog-agent/pkg/trace/exportable_存在确切的版本,但对于_github.com/influxdata/line-protocol_不存在,但两者都报告了相同的错误。

我不知道golang在这里期望什么,也不知道如何开始解决这个问题。

有人可以帮忙吗?

英文:

I am trying to run the go list -mod=readonly -m -u -json all command on the opentelemetry-collector-contrib project.

It fails with the below error:

$ go list -mod=readonly -m -u -json all
go list -m: loading module retractions for github.com/DataDog/datadog-agent/pkg/trace/exportable@v0.0.0-20201016145401-4646cf596b02: no matching versions for query "latest"
go list -m: loading module retractions for github.com/influxdata/line-protocol/v2@v2.0.0-20210428091617-0567a5134992: no matching versions for query "latest"
$ echo $?
1

I am using go 1.16.5:

$ go version
go version go1.16.5 linux/amd64

I have cleaned the go cache with go clean -modcache with the same result.

I have found both modules https://pkg.go.dev/:

It seems the exact version exists for github.com/DataDog/datadog-agent/pkg/trace/exportable but not for github.com/influxdata/line-protocol, but both report the same error anyway.

I have no clue what golang expects here and how to start troubleshooting the issue.

Can anybody help?

答案1

得分: 1

似乎这是一个 bug(https://github.com/golang/go/issues/45305),是由于在 Go 1.16 中引入了 go.mod 中的 retract 指令导致的。实际上,如果省略 -m 标志,该命令会正常运行。

如在问题线程中提到的,您可以添加 -e 标志以忽略错误继续执行:

$ go list -mod=readonly -m -u -e -json all

{
	"Path": "github.com/open-telemetry/opentelemetry-collector-contrib",
	"Main": true,
	"Dir": "/Users/me/go/opentelemetry-collector-contrib",
	"GoMod": "/Users/me/go/opentelemetry-collector-contrib/go.mod",
	"GoVersion": "1.16"
}
... 更多内容

关于 -e 标志,go help list 中有说明:

> -e 标志改变了对错误包的处理方式,即那些无法找到或格式错误的包。[...] 使用 -e 标志,列表命令不会将错误打印到标准错误输出,而是按照通常的方式处理错误包并打印输出。错误包将具有非空的 ImportPath 和非空的 Error 字段;其他信息可能存在或可能缺失(被清零)。

该 bug 在 Go 1.17 中已修复。

英文:

It seems it's a bug (https://github.com/golang/go/issues/45305) due to the introduction of the retract directive in go.mod in Go 1.16. In fact if you omit the -m flag, the command runs fine.

As mentioned in the issue thread, you can add the -e flag to move on despite errors:

$ go list -mod=readonly -m -u -e -json all

{
	"Path": "github.com/open-telemetry/opentelemetry-collector-contrib",
	"Main": true,
	"Dir": "/Users/me/go/opentelemetry-collector-contrib",
	"GoMod": "/Users/me/go/opentelemetry-collector-contrib/go.mod",
	"GoVersion": "1.16"
}
... much more

About the -e flag, go help list:

> The -e flag changes the handling of erroneous packages, those that
cannot be found or are malformed. [...]
With the -e flag, the list command never prints errors to standard
error and instead processes the erroneous packages with the usual
printing. Erroneous packages will have a non-empty ImportPath and
a non-nil Error field; other information may or may not be missing
(zeroed).

The bug is fixed in Go 1.17.

huangapple
  • 本文由 发表于 2021年6月15日 00:54:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/67974303.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定