mirror of
https://github.com/golang/go.git
synced 2026-04-02 09:20:29 +09:00
cmd/go: avoid repetitive "invalid version" error on go get
When go get encounters an invalid version string like "branch/with/slash", the error message redundantly repeats the version information: go get: pkg@branch/with/slash: invalid version: version "branch/with/slash" invalid: disallowed version string This happens because proxyRepo.versionError wraps the error from module.EscapeVersion (which already returns an InvalidVersionError) in another InvalidVersionError, causing ModuleError.Error to format both layers. Avoid the double wrapping by checking whether the error is already an InvalidVersionError before creating a new one. The resulting message is: go get: pkg@branch/with/slash: invalid version: disallowed version string Fixes #44810 Change-Id: I5c259ef6f1ea23b6673689defbe7e51c8ec813ec Reviewed-on: https://go-review.googlesource.com/c/go/+/744920 Auto-Submit: Sean Liao <sean@liao.dev> Reviewed-by: Antonio Camacho <antoniocho444@gmail.com> Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
@@ -238,13 +238,17 @@ func (p *proxyRepo) CheckReuse(ctx context.Context, old *codehost.Origin) error
|
||||
// versionError returns err wrapped in a ModuleError for p.path.
|
||||
func (p *proxyRepo) versionError(version string, err error) error {
|
||||
if version != "" && version != module.CanonicalVersion(version) {
|
||||
return &module.ModuleError{
|
||||
Path: p.path,
|
||||
Err: &module.InvalidVersionError{
|
||||
var iv *module.InvalidVersionError
|
||||
if !errors.As(err, &iv) {
|
||||
iv = &module.InvalidVersionError{
|
||||
Version: version,
|
||||
Pseudo: module.IsPseudoVersion(version),
|
||||
Err: err,
|
||||
},
|
||||
}
|
||||
}
|
||||
return &module.ModuleError{
|
||||
Path: p.path,
|
||||
Err: iv,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
10
src/cmd/go/testdata/script/get_version_error_44810.txt
vendored
Normal file
10
src/cmd/go/testdata/script/get_version_error_44810.txt
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# Issue #44810: go get should not produce unnecessarily repetitive
|
||||
# "invalid version" error messages.
|
||||
|
||||
go mod init m
|
||||
|
||||
# A version string containing a slash should produce a concise error
|
||||
# without repeating the version information multiple times.
|
||||
! go get example.com/mod@branch/with/slash
|
||||
stderr '^go: example.com/mod@branch/with/slash: invalid version: disallowed version string$'
|
||||
! stderr 'version "branch/with/slash" invalid'
|
||||
Reference in New Issue
Block a user