aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2019-08-08 17:08:19 -0400
committerBryan C. Mills <bcmills@google.com>2019-09-11 16:28:37 +0000
commit6f1667ea3e6a9c2bee8b5aea9859be1a677ee24e (patch)
tree6f724b6a730e4a160d436049afc793bfd0eb1fce /src
parent2a4c0afee72953f16e852131bebd560120353d1d (diff)
downloadgo-6f1667ea3e6a9c2bee8b5aea9859be1a677ee24e.tar.xz
cmd/go/internal/modload: propagate errors from Query for missing imports
Updates #30748 Updates #28459 Change-Id: I1c34b3dae0bf9361dba0dae66bb868901ecafe29 Reviewed-on: https://go-review.googlesource.com/c/go/+/189780 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go/internal/modload/import.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go
index 70add3507a..bb5e05e9e3 100644
--- a/src/cmd/go/internal/modload/import.go
+++ b/src/cmd/go/internal/modload/import.go
@@ -28,6 +28,7 @@ import (
type ImportMissingError struct {
ImportPath string
Module module.Version
+ QueryErr error
// newMissingVersion is set to a newer version of Module if one is present
// in the build list. When set, we can't automatically upgrade.
@@ -39,9 +40,12 @@ func (e *ImportMissingError) Error() string {
if str.HasPathPrefix(e.ImportPath, "cmd") {
return fmt.Sprintf("package %s is not in GOROOT (%s)", e.ImportPath, filepath.Join(cfg.GOROOT, "src", e.ImportPath))
}
+ if e.QueryErr != nil {
+ return fmt.Sprintf("cannot find module providing package %s: %v", e.ImportPath, e.QueryErr)
+ }
return "cannot find module providing package " + e.ImportPath
}
- return "missing module for import: " + e.Module.Path + "@" + e.Module.Version + " provides " + e.ImportPath
+ return fmt.Sprintf("missing module for import: %s@%s provides %s", e.Module.Path, e.Module.Version, e.ImportPath)
}
// Import finds the module and directory in the build list
@@ -197,7 +201,7 @@ func Import(path string) (m module.Version, dir string, err error) {
if errors.Is(err, os.ErrNotExist) {
// Return "cannot find module providing package […]" instead of whatever
// low-level error QueryPackage produced.
- return module.Version{}, "", &ImportMissingError{ImportPath: path}
+ return module.Version{}, "", &ImportMissingError{ImportPath: path, QueryErr: err}
} else {
return module.Version{}, "", err
}