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_.
This commit is contained in:
Martin Atkins 2017-06-20 17:40:28 -07:00
parent aa130b070a
commit 3dc7d618f7
1 changed files with 14 additions and 2 deletions

View File

@ -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:
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))
}