aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modcmd/download.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2019-08-07 16:27:39 -0400
committerJay Conrod <jayconrod@google.com>2019-08-08 20:38:47 +0000
commit1dc0110bf725640a9b912e3d31e6654ed1c4da9d (patch)
tree96a093b582c17b9e7e39d2d10716a81753ad0c27 /src/cmd/go/internal/modcmd/download.go
parentc5178ef69eedce1374e684212ea9cdae6220e0f6 (diff)
downloadgo-1dc0110bf725640a9b912e3d31e6654ed1c4da9d.tar.gz
go-1dc0110bf725640a9b912e3d31e6654ed1c4da9d.zip
cmd/go: improve 'go mod download' and 'go list -m' error messages
modload.ListModules now wraps errors as module.ModuleError as appropriate. The resulting errors always include the module path and will include the version, if known. 'go mod download' no longer ignores errors reported by ListModules. Previously, it started requesting module info, go.mod, and zip. Those requests would fail, overwriting the original failure. They were usually less descriptive. 'go mod download' with a module not in the build list (and no version query) is now an error. Previously, this was silently ignored. Fixes #30743 Change-Id: Icee8c1c6c5240de135a8b6ba42d6bbcdb757cdac Reviewed-on: https://go-review.googlesource.com/c/go/+/189323 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modcmd/download.go')
-rw-r--r--src/cmd/go/internal/modcmd/download.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/cmd/go/internal/modcmd/download.go b/src/cmd/go/internal/modcmd/download.go
index 1137982e47..60d0d5b6e2 100644
--- a/src/cmd/go/internal/modcmd/download.go
+++ b/src/cmd/go/internal/modcmd/download.go
@@ -89,7 +89,8 @@ func runDownload(cmd *base.Command, args []string) {
if info.Replace != nil {
info = info.Replace
}
- if info.Version == "" {
+ if info.Version == "" && info.Error == nil {
+ // main module
continue
}
m := &moduleJSON{
@@ -97,6 +98,10 @@ func runDownload(cmd *base.Command, args []string) {
Version: info.Version,
}
mods = append(mods, m)
+ if info.Error != nil {
+ m.Error = info.Error.Err
+ continue
+ }
work.Add(m)
}
@@ -110,12 +115,17 @@ func runDownload(cmd *base.Command, args []string) {
// downloading the modules.
var latestArgs []string
for _, m := range mods {
+ if m.Error != "" {
+ continue
+ }
latestArgs = append(latestArgs, m.Path+"@latest")
}
- for _, info := range modload.ListModules(latestArgs, listU, listVersions) {
- if info.Version != "" {
- latest[info.Path] = info.Version
+ if len(latestArgs) > 0 {
+ for _, info := range modload.ListModules(latestArgs, listU, listVersions) {
+ if info.Version != "" {
+ latest[info.Path] = info.Version
+ }
}
}
}
@@ -169,7 +179,7 @@ func runDownload(cmd *base.Command, args []string) {
} else {
for _, m := range mods {
if m.Error != "" {
- base.Errorf("%s@%s: %s\n", m.Path, m.Version, m.Error)
+ base.Errorf("%s", m.Error)
}
}
base.ExitIfErrors()