From 22a56b629d86508a36d1dd8b90124ccd9dc90e06 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 28 Apr 2021 11:47:49 -0400 Subject: [PATCH] cmd/go/internal/modload: in importFromModules, do not wrap module graph errors in ImportMissingError If an error occurs in loading the module graph (such as a missing checksum for a relevant go.mod file), that error should be terminal and we should not look elsewhere to try to resolve the import. An ImportMissingError instructs the caller to do exactly that, so don't use that error type for this case. (This behavior is tested incidentally in a later CL in this stack.) For #36460 Change-Id: I963e39cc7fbc457c12a626c1402c0be29203d23b Reviewed-on: https://go-review.googlesource.com/c/go/+/314633 Trust: Bryan C. Mills Run-TryBot: Bryan C. Mills TryBot-Result: Go Bot Reviewed-by: Michael Matloob --- src/cmd/go/internal/modload/import.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go index 1d321bb24b..4e62e61bb0 100644 --- a/src/cmd/go/internal/modload/import.go +++ b/src/cmd/go/internal/modload/import.go @@ -303,7 +303,11 @@ func importFromModules(ctx context.Context, path string, rs *Requirements) (m mo } else { mg, err = rs.Graph(ctx) if err != nil { - return module.Version{}, "", &ImportMissingError{Path: path, QueryErr: err} + // We might be missing one or more transitive (implicit) dependencies from + // the module graph, so we can't return an ImportMissingError here — one + // of the missing modules might actually contain the package in question, + // in which case we shouldn't go looking for it in some new dependency. + return module.Version{}, "", err } }