From 4893fcc24fe55f619fe8e44fb1868fe015104cf8 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 22 Jun 2017 15:28:39 -0400 Subject: [PATCH] improve plugin error formatting Remove "checksum" from the error, and only indicate that the plugin has changed. Always show requested versions even if it's "any", and found versions of plugins. --- command/plugins.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/command/plugins.go b/command/plugins.go index dd82ebc8a..ca94f07b9 100644 --- a/command/plugins.go +++ b/command/plugins.go @@ -46,7 +46,7 @@ func (r *multiVersionProviderResolver) ResolveProviders( var errs []error chosen := choosePlugins(r.Available, reqd) - for name := range reqd { + for name, req := range reqd { if newest, available := chosen[name]; available { digest, err := newest.SHA256() if err != nil { @@ -54,7 +54,7 @@ func (r *multiVersionProviderResolver) ResolveProviders( continue } if !reqd[name].AcceptsSHA256(digest) { - errs = append(errs, fmt.Errorf("provider.%s: checksum mismatch", name)) + errs = append(errs, fmt.Errorf("provider.%s: new or changed plugin executable", name)) continue } @@ -63,20 +63,24 @@ func (r *multiVersionProviderResolver) ResolveProviders( } else { msg := fmt.Sprintf("provider.%s: no suitable version installed", name) - if req := reqd[name]; req.Versions.String() != "" { - foundVersions := []string{} - for meta := range r.Available.WithName(name) { - foundVersions = append(foundVersions, fmt.Sprintf("%q", meta.Version)) - } - - found := "none" - if len(foundVersions) > 0 { - found = strings.Join(foundVersions, ", ") - } - - msg += fmt.Sprintf("\n version requirements: %q\n versions found: %s", req.Versions, found) + required := req.Versions.String() + // no version is unconstrained + if required == "" { + required = "(any version)" } + foundVersions := []string{} + for meta := range r.Available.WithName(name) { + foundVersions = append(foundVersions, fmt.Sprintf("%q", meta.Version)) + } + + found := "none" + if len(foundVersions) > 0 { + found = strings.Join(foundVersions, ", ") + } + + msg += fmt.Sprintf("\n version requirements: %q\n versions installed: %s", required, found) + errs = append(errs, errors.New(msg)) } }