aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/mvs/mvs.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2019-04-15 15:34:49 -0400
committerJay Conrod <jayconrod@google.com>2019-04-16 18:50:43 +0000
commit2bdbc942f5ae3da8cad8d0f2bd3f4ce75a821e6c (patch)
tree8553aefca5a2194b5a5bd80666d8d50b3816353d /src/cmd/go/internal/mvs/mvs.go
parentf7c967259254fa90e1f1951f83fb66850ae3809a (diff)
downloadgo-2bdbc942f5ae3da8cad8d0f2bd3f4ce75a821e6c.tar.gz
go-2bdbc942f5ae3da8cad8d0f2bd3f4ce75a821e6c.zip
cmd/go: print package import chains for some build list errors
When we construct the build list by loading packages (e.g., in "go build", "go list", or "go test"), we may load additional modules not mentioned in the original build list. If we encounter an error loading one of these modules, mvs.BuildList currently returns a BuildListError with a chain of requirments. Unfortunately, this is not helpful, since the graph is structured such that these missing modules are direct requirements of the main module. With this change, loader.load keeps track of the package that caused each "missing" module to be added. If an error occurs in a missing module, the chain of package imports is printed instead of the module requirements. Fixes #31475 Change-Id: Ie484814af42ceea3e85fedc38e705ba3a38cd495 Reviewed-on: https://go-review.googlesource.com/c/go/+/171859 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/mvs/mvs.go')
-rw-r--r--src/cmd/go/internal/mvs/mvs.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/cmd/go/internal/mvs/mvs.go b/src/cmd/go/internal/mvs/mvs.go
index 284a6fc339..d1c3d8c08a 100644
--- a/src/cmd/go/internal/mvs/mvs.go
+++ b/src/cmd/go/internal/mvs/mvs.go
@@ -65,7 +65,7 @@ type Reqs interface {
// while constructing a build list. BuildListError prints the chain
// of requirements to the module where the error occurred.
type BuildListError struct {
- err error
+ Err error
stack []buildListErrorElem
}
@@ -77,9 +77,18 @@ type buildListErrorElem struct {
nextReason string
}
+// Module returns the module where the error occurred. If the module stack
+// is empty, this returns a zero value.
+func (e *BuildListError) Module() module.Version {
+ if len(e.stack) == 0 {
+ return module.Version{}
+ }
+ return e.stack[0].m
+}
+
func (e *BuildListError) Error() string {
b := &strings.Builder{}
- errMsg := e.err.Error()
+ errMsg := e.Err.Error()
stack := e.stack
// Don't print modules at the beginning of the chain without a
@@ -177,7 +186,7 @@ func buildList(target module.Version, reqs Reqs, upgrade func(module.Version) mo
if node.err != nil {
err := &BuildListError{
- err: node.err,
+ Err: node.err,
stack: []buildListErrorElem{{m: node.m}},
}
for n, prev := neededBy[node], node; n != nil; n, prev = neededBy[n], n {