Merge pull request #20853 from pselle/err-handling-registry-unresponsive
Add friendly error for when registry unresponsive
This commit is contained in:
commit
d1c1bc6cdb
|
@ -504,6 +504,8 @@ func (c *InitCommand) getProviders(earlyConfig *earlyconfig.Config, state *state
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
case err == discovery.ErrorServiceUnreachable:
|
||||||
|
c.Ui.Error(errDiscoveryServiceUnreachable)
|
||||||
case err == discovery.ErrorNoSuchProvider:
|
case err == discovery.ErrorNoSuchProvider:
|
||||||
c.Ui.Error(fmt.Sprintf(errProviderNotFound, provider, DefaultPluginVendorDir))
|
c.Ui.Error(fmt.Sprintf(errProviderNotFound, provider, DefaultPluginVendorDir))
|
||||||
case err == discovery.ErrorNoSuitableVersion:
|
case err == discovery.ErrorNoSuitableVersion:
|
||||||
|
@ -878,6 +880,14 @@ corresponding provider blocks in configuration, with the constraint strings
|
||||||
suggested below.
|
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.
|
||||||
|
|
||||||
|
Check https://status.hashicorp.com/ for registry status updates.
|
||||||
|
`
|
||||||
|
|
||||||
const errProviderNotFound = `
|
const errProviderNotFound = `
|
||||||
[reset][bold][red]Provider %[1]q not available for installation.[reset][red]
|
[reset][bold][red]Provider %[1]q not available for installation.[reset][red]
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,10 @@ const ErrorChecksumVerification = Error("unexpected plugin checksum")
|
||||||
// was not signed by any known key for the publisher
|
// was not signed by any known key for the publisher
|
||||||
const ErrorSignatureVerification = Error("unable to verify signature")
|
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 {
|
func (err Error) Error() string {
|
||||||
return string(err)
|
return string(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,10 @@ func (i *ProviderInstaller) Get(provider string, req Constraints) (PluginMeta, t
|
||||||
|
|
||||||
// TODO: return multiple errors
|
// TODO: return multiple errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("[DEBUG] %s", err)
|
||||||
|
if registry.IsServiceUnreachable(err) {
|
||||||
|
return PluginMeta{}, diags, ErrorServiceUnreachable
|
||||||
|
}
|
||||||
if registry.IsServiceNotProvided(err) {
|
if registry.IsServiceNotProvided(err) {
|
||||||
return PluginMeta{}, diags, err
|
return PluginMeta{}, diags, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func (c *Client) Discover(host svchost.Hostname, serviceID string) (*url.URL, error) {
|
||||||
service, err := c.services.DiscoverServiceURL(host, serviceID)
|
service, err := c.services.DiscoverServiceURL(host, serviceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, &ServiceUnreachableError{err}
|
||||||
}
|
}
|
||||||
if !strings.HasSuffix(service.Path, "/") {
|
if !strings.HasSuffix(service.Path, "/") {
|
||||||
service.Path += "/"
|
service.Path += "/"
|
||||||
|
|
|
@ -46,3 +46,18 @@ func IsServiceNotProvided(err error) bool {
|
||||||
_, ok := err.(*disco.ErrServiceNotProvided)
|
_, ok := err.(*disco.ErrServiceNotProvided)
|
||||||
return ok
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue