Skip to content

Commit 6f1667e

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 2a4c0af commit 6f1667e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/cmd/go/internal/modload/import.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
type ImportMissingError struct {
2929
ImportPath string
3030
Module module.Version
31+
QueryErr error
3132

3233
// newMissingVersion is set to a newer version of Module if one is present
3334
// in the build list. When set, we can't automatically upgrade.
@@ -39,9 +40,12 @@ func (e *ImportMissingError) Error() string {
3940
if str.HasPathPrefix(e.ImportPath, "cmd") {
4041
return fmt.Sprintf("package %s is not in GOROOT (%s)", e.ImportPath, filepath.Join(cfg.GOROOT, "src", e.ImportPath))
4142
}
43+
if e.QueryErr != nil {
44+
return fmt.Sprintf("cannot find module providing package %s: %v", e.ImportPath, e.QueryErr)
45+
}
4246
return "cannot find module providing package " + e.ImportPath
4347
}
44-
return "missing module for import: " + e.Module.Path + "@" + e.Module.Version + " provides " + e.ImportPath
48+
return fmt.Sprintf("missing module for import: %s@%s provides %s", e.Module.Path, e.Module.Version, e.ImportPath)
4549
}
4650

4751
// 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) {
197201
if errors.Is(err, os.ErrNotExist) {
198202
// Return "cannot find module providing package […]" instead of whatever
199203
// low-level error QueryPackage produced.
200-
return module.Version{}, "", &ImportMissingError{ImportPath: path}
204+
return module.Version{}, "", &ImportMissingError{ImportPath: path, QueryErr: err}
201205
} else {
202206
return module.Version{}, "", err
203207
}

0 commit comments

Comments
 (0)