diff options
author | Jay Conrod <jayconrod@google.com> | 2019-03-11 18:53:08 -0400 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2019-04-03 18:00:56 +0000 |
commit | 1e3cdd1edce67350f8007e4a9b9b555f1e27c5b4 (patch) | |
tree | 27da504871234bf4adb147096acfad96834a121e /src/cmd/go/internal/modload/load.go | |
parent | 8c896aa46655cfbdfd9971fb16a830046fcdf81c (diff) | |
download | go-1e3cdd1edce67350f8007e4a9b9b555f1e27c5b4.tar.gz go-1e3cdd1edce67350f8007e4a9b9b555f1e27c5b4.zip |
cmd/go: print require chains in build list errors
mvs.BuildList and functions that invoke it directly (UpgradeAll) now
return an *mvs.BuildListError when there is an error retrieving the
requirements for a module. This new error prints the chain of
requirements from the main module to the module where the error
occurred.
These errors come up most commonly when a go.mod file has an
unexpected module path or can't be parsed for some other reason. It's
currently difficult to debug these errors because it's not clear where
the "bad" module is required from. Tools like "go list -m" and
"go mod why" don't work without the build graph.
Fixes #30661
Change-Id: I3c9d4683dcd9a5d7c259e5e4cc7e1ee209700b10
Reviewed-on: https://go-review.googlesource.com/c/go/+/166984
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/modload/load.go')
-rw-r--r-- | src/cmd/go/internal/modload/load.go | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index ea0ac6771f..78681b165a 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -1023,13 +1023,11 @@ func (r *mvsReqs) required(mod module.Version) ([]module.Version, error) { gomod := filepath.Join(dir, "go.mod") data, err := ioutil.ReadFile(gomod) if err != nil { - base.Errorf("go: parsing %s: %v", base.ShortPath(gomod), err) - return nil, ErrRequire + return nil, fmt.Errorf("parsing %s: %v", base.ShortPath(gomod), err) } f, err := modfile.ParseLax(gomod, data, nil) if err != nil { - base.Errorf("go: parsing %s: %v", base.ShortPath(gomod), err) - return nil, ErrRequire + return nil, fmt.Errorf("parsing %s: %v", base.ShortPath(gomod), err) } if f.Go != nil { r.versions.LoadOrStore(mod, f.Go.Version) @@ -1050,22 +1048,18 @@ func (r *mvsReqs) required(mod module.Version) ([]module.Version, error) { data, err := modfetch.GoMod(mod.Path, mod.Version) if err != nil { - base.Errorf("go: %s@%s: %v\n", mod.Path, mod.Version, err) - return nil, ErrRequire + return nil, fmt.Errorf("%s@%s: %v", mod.Path, mod.Version, err) } f, err := modfile.ParseLax("go.mod", data, nil) if err != nil { - base.Errorf("go: %s@%s: parsing go.mod: %v", mod.Path, mod.Version, err) - return nil, ErrRequire + return nil, fmt.Errorf("%s@%s: parsing go.mod: %v", mod.Path, mod.Version, err) } if f.Module == nil { - base.Errorf("go: %s@%s: parsing go.mod: missing module line", mod.Path, mod.Version) - return nil, ErrRequire + return nil, fmt.Errorf("%s@%s: parsing go.mod: missing module line", mod.Path, mod.Version) } if mpath := f.Module.Mod.Path; mpath != origPath && mpath != mod.Path { - base.Errorf("go: %s@%s: parsing go.mod: unexpected module path %q", mod.Path, mod.Version, mpath) - return nil, ErrRequire + return nil, fmt.Errorf("%s@%s: parsing go.mod: unexpected module path %q", mod.Path, mod.Version, mpath) } if f.Go != nil { r.versions.LoadOrStore(mod, f.Go.Version) @@ -1074,11 +1068,6 @@ func (r *mvsReqs) required(mod module.Version) ([]module.Version, error) { return r.modFileToList(f), nil } -// ErrRequire is the sentinel error returned when Require encounters problems. -// It prints the problems directly to standard error, so that multiple errors -// can be displayed easily. -var ErrRequire = errors.New("error loading module requirements") - func (*mvsReqs) Max(v1, v2 string) string { if v1 != "" && semver.Compare(v1, v2) == -1 { return v2 |