diff options
author | Jay Conrod <jayconrod@google.com> | 2021-01-07 11:14:06 -0500 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2021-01-08 20:19:51 +0000 |
commit | 6192b9875128c5f53a69b959d5a1abf0f10ae93f (patch) | |
tree | c39777eb78c5c3309578cd8bd7758989fd9901ac /src/cmd/go/internal/modload/import.go | |
parent | 25886cf4bd28be373afb80a4c068a785b43bdddf (diff) | |
download | go-6192b9875128c5f53a69b959d5a1abf0f10ae93f.tar.gz go-6192b9875128c5f53a69b959d5a1abf0f10ae93f.zip |
cmd/go: make hints in error messages more consistent
* All commands the user can run to fix the problem now appear alone on
a separate line after a tab.
* Removed -d from 'go get' commands.
* Replaced 'go mod tidy' with 'go mod download $modpath' when a
package might be provided by a module missing a sum.
* Errors about 'path@version' syntax are more explicit.
Fixes #29415
Fixes #42087
Fixes #43430
Fixes #43523
Change-Id: I4427c2c4506a727a2c727d652fd2d506bb134d3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/282121
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/import.go')
-rw-r--r-- | src/cmd/go/internal/modload/import.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go index 055878c528..9925d5b905 100644 --- a/src/cmd/go/internal/modload/import.go +++ b/src/cmd/go/internal/modload/import.go @@ -134,6 +134,7 @@ func (e *AmbiguousImportError) Error() string { // for its .zip file. type ImportMissingSumError struct { importPath string + modPaths []string found, inAll bool } @@ -145,7 +146,7 @@ func (e *ImportMissingSumError) Error() string { message = fmt.Sprintf("missing go.sum entry for module providing package %s", e.importPath) } if e.inAll { - return message + "; to add it:\n\tgo mod tidy" + return message + fmt.Sprintf("; to add it:\n\tgo mod download %s", strings.Join(e.modPaths, " ")) } return message } @@ -238,7 +239,7 @@ func importFromBuildList(ctx context.Context, path string, buildList []module.Ve // Check each module on the build list. var dirs []string var mods []module.Version - haveSumErr := false + var sumErrModPaths []string for _, m := range buildList { if !maybeInModule(path, m.Path) { // Avoid possibly downloading irrelevant modules. @@ -251,8 +252,9 @@ func importFromBuildList(ctx context.Context, path string, buildList []module.Ve // We are missing a sum needed to fetch a module in the build list. // We can't verify that the package is unique, and we may not find // the package at all. Keep checking other modules to decide which - // error to report. - haveSumErr = true + // error to report. Multiple sums may be missing if we need to look in + // multiple nested modules to resolve the import; we'll report them all. + sumErrModPaths = append(sumErrModPaths, m.Path) continue } // Report fetch error. @@ -273,8 +275,8 @@ func importFromBuildList(ctx context.Context, path string, buildList []module.Ve if len(mods) > 1 { return module.Version{}, "", &AmbiguousImportError{importPath: path, Dirs: dirs, Modules: mods} } - if haveSumErr { - return module.Version{}, "", &ImportMissingSumError{importPath: path, found: len(mods) > 0} + if len(sumErrModPaths) > 0 { + return module.Version{}, "", &ImportMissingSumError{importPath: path, modPaths: sumErrModPaths, found: len(mods) > 0} } if len(mods) == 1 { return mods[0], dirs[0], nil |