From 3dc7d618f7fbcf72a720f8ef7e606b458357b6fb Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 20 Jun 2017 17:40:28 -0700 Subject: [PATCH] command: avoid empty string constraints in plugin install errors This takes care of a few dangling cases where we were still stringifying empty version constraints, which creates confusing error messages due to it stringing as the empty string. For the "no suitable versions available" message, we fall back on the "provider not found" message if no versions were found even though it's unconstrained. This should only happen in an edge case where the provider's index page exists on the releases server but no versions are yet present. For the message about plugin protocol versions, this again is an edge case since with no constraints this should happen only if we release an incompatible Terraform version but don't release a new version of the plugin that's compatible. In this case we just show the constraint as "(any version)" to make sure we always show _something_. --- command/init.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/command/init.go b/command/init.go index 9624770b56..fbfbcd0806 100644 --- a/command/init.go +++ b/command/init.go @@ -250,12 +250,24 @@ func (c *InitCommand) getProviders(path string, state *terraform.State, upgrade case discovery.ErrorNoSuchProvider: c.Ui.Error(fmt.Sprintf(errProviderNotFound, provider, DefaultPluginVendorDir)) case discovery.ErrorNoSuitableVersion: - c.Ui.Error(fmt.Sprintf(errProviderVersionsUnsuitable, provider, reqd.Versions)) + if reqd.Versions.Unconstrained() { + // This should never happen, but might crop up if we catch + // the releases server in a weird state where the provider's + // directory is present but does not yet contain any + // versions. We'll treat it like ErrorNoSuchProvider, then. + c.Ui.Error(fmt.Sprintf(errProviderNotFound, provider, DefaultPluginVendorDir)) + } else { + c.Ui.Error(fmt.Sprintf(errProviderVersionsUnsuitable, provider, reqd.Versions)) + } case discovery.ErrorNoVersionCompatible: // FIXME: This error message is sub-awesome because we don't // have enough information here to tell the user which versions // we considered and which versions might be compatible. - c.Ui.Error(fmt.Sprintf(errProviderIncompatible, provider, reqd.Versions)) + constraint := reqd.Versions.String() + if constraint == "" { + constraint = "(any version)" + } + c.Ui.Error(fmt.Sprintf(errProviderIncompatible, provider, constraint)) default: c.Ui.Error(fmt.Sprintf(errProviderInstallError, provider, err.Error(), DefaultPluginVendorDir)) }