From d72456d188c42cf206e610ac821463ec752088b9 Mon Sep 17 00:00:00 2001 From: Pam Selle Date: Wed, 27 Mar 2019 14:20:15 -0400 Subject: [PATCH 1/2] Add friendly error for when registry unresponsive If the registry is unresponsive, you will now get an error specific to this, rather than a misleading "provider unavailable" type error. Also adds debug logging for when errors like this may occur --- command/init.go | 8 ++++++++ plugin/discovery/error.go | 4 ++++ plugin/discovery/get.go | 4 ++++ registry/client.go | 2 +- registry/errors.go | 15 +++++++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/command/init.go b/command/init.go index 6c5dd0a8e..c5438383a 100644 --- a/command/init.go +++ b/command/init.go @@ -504,6 +504,8 @@ func (c *InitCommand) getProviders(earlyConfig *earlyconfig.Config, state *state } switch { + case err == discovery.ErrorServiceUnreachable: + c.Ui.Error(errDiscoveryServiceUnreachable) case err == discovery.ErrorNoSuchProvider: c.Ui.Error(fmt.Sprintf(errProviderNotFound, provider, DefaultPluginVendorDir)) case err == discovery.ErrorNoSuitableVersion: @@ -878,6 +880,12 @@ corresponding provider blocks in configuration, with the constraint strings suggested below. ` +const errDiscoveryServiceUnreachable = ` +[reset][bold][red]Registry service unreachable.[reset][red] + +This may indicate a network issue, or an issue with the requested Terraform Registry. +` + const errProviderNotFound = ` [reset][bold][red]Provider %[1]q not available for installation.[reset][red] diff --git a/plugin/discovery/error.go b/plugin/discovery/error.go index c0b503067..b29d143a7 100644 --- a/plugin/discovery/error.go +++ b/plugin/discovery/error.go @@ -51,6 +51,10 @@ const ErrorChecksumVerification = Error("unexpected plugin checksum") // was not signed by any known key for the publisher const ErrorSignatureVerification = Error("unable to verify signature") +// ErrorServiceUnreachable indicates that the network was unable to connect +// to the registry service +const ErrorServiceUnreachable = Error("registry service is unreachable") + func (err Error) Error() string { return string(err) } diff --git a/plugin/discovery/get.go b/plugin/discovery/get.go index cc8acee6c..f1fb85b33 100644 --- a/plugin/discovery/get.go +++ b/plugin/discovery/get.go @@ -125,6 +125,10 @@ func (i *ProviderInstaller) Get(provider string, req Constraints) (PluginMeta, t // TODO: return multiple errors if err != nil { + log.Printf("[DEBUG] %s", err) + if registry.IsServiceUnreachable(err) { + return PluginMeta{}, diags, ErrorServiceUnreachable + } if registry.IsServiceNotProvided(err) { return PluginMeta{}, diags, err } diff --git a/registry/client.go b/registry/client.go index 0b90790d4..93424d176 100644 --- a/registry/client.go +++ b/registry/client.go @@ -62,7 +62,7 @@ func NewClient(services *disco.Disco, client *http.Client) *Client { func (c *Client) Discover(host svchost.Hostname, serviceID string) (*url.URL, error) { service, err := c.services.DiscoverServiceURL(host, serviceID) if err != nil { - return nil, err + return nil, &ServiceUnreachableError{err} } if !strings.HasSuffix(service.Path, "/") { service.Path += "/" diff --git a/registry/errors.go b/registry/errors.go index cdde48221..5a6a31b08 100644 --- a/registry/errors.go +++ b/registry/errors.go @@ -46,3 +46,18 @@ func IsServiceNotProvided(err error) bool { _, ok := err.(*disco.ErrServiceNotProvided) return ok } + +// ServiceUnreachableError Registry service is unreachable +type ServiceUnreachableError struct { + err error +} + +func (e *ServiceUnreachableError) Error() string { + return e.err.Error() +} + +// IsServiceUnreachable returns true if the registry/discovery service was unreachable +func IsServiceUnreachable(err error) bool { + _, ok := err.(*ServiceUnreachableError) + return ok +} From ff7245f27ceee90abf23d1d0fd8163bd69a6a9ca Mon Sep 17 00:00:00 2001 From: Pam Selle Date: Wed, 27 Mar 2019 16:22:37 -0400 Subject: [PATCH 2/2] Add status link to make message more helpful --- command/init.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/command/init.go b/command/init.go index c5438383a..f6fef4352 100644 --- a/command/init.go +++ b/command/init.go @@ -884,6 +884,8 @@ const errDiscoveryServiceUnreachable = ` [reset][bold][red]Registry service unreachable.[reset][red] This may indicate a network issue, or an issue with the requested Terraform Registry. + +Check https://status.hashicorp.com/ for registry status updates. ` const errProviderNotFound = `