aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/go/internal/modfetch/proxy.go12
-rw-r--r--src/cmd/go/testdata/script/get_version_error_44810.txt10
2 files changed, 18 insertions, 4 deletions
diff --git a/src/cmd/go/internal/modfetch/proxy.go b/src/cmd/go/internal/modfetch/proxy.go
index 896f310bdf..bddeca3340 100644
--- a/src/cmd/go/internal/modfetch/proxy.go
+++ b/src/cmd/go/internal/modfetch/proxy.go
@@ -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,
}
}
diff --git a/src/cmd/go/testdata/script/get_version_error_44810.txt b/src/cmd/go/testdata/script/get_version_error_44810.txt
new file mode 100644
index 0000000000..37c7b8e4be
--- /dev/null
+++ b/src/cmd/go/testdata/script/get_version_error_44810.txt
@@ -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'