github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/registry/errors.go (about)

     1  package registry
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/terraform-plugin-sdk/internal/registry/regsrc"
     7  	"github.com/hashicorp/terraform-svchost/disco"
     8  )
     9  
    10  type errModuleNotFound struct {
    11  	addr *regsrc.Module
    12  }
    13  
    14  func (e *errModuleNotFound) Error() string {
    15  	return fmt.Sprintf("module %s not found", e.addr)
    16  }
    17  
    18  // IsModuleNotFound returns true only if the given error is a "module not found"
    19  // error. This allows callers to recognize this particular error condition
    20  // as distinct from operational errors such as poor network connectivity.
    21  func IsModuleNotFound(err error) bool {
    22  	_, ok := err.(*errModuleNotFound)
    23  	return ok
    24  }
    25  
    26  type errProviderNotFound struct {
    27  	addr *regsrc.TerraformProvider
    28  }
    29  
    30  func (e *errProviderNotFound) Error() string {
    31  	return fmt.Sprintf("provider %s not found", e.addr)
    32  }
    33  
    34  // IsServiceNotProvided returns true only if the given error is a "service not provided"
    35  // error. This allows callers to recognize this particular error condition
    36  // as distinct from operational errors such as poor network connectivity.
    37  func IsServiceNotProvided(err error) bool {
    38  	_, ok := err.(*disco.ErrServiceNotProvided)
    39  	return ok
    40  }
    41  
    42  // ServiceUnreachableError Registry service is unreachable
    43  type ServiceUnreachableError struct {
    44  	err error
    45  }
    46  
    47  func (e *ServiceUnreachableError) Error() string {
    48  	return e.err.Error()
    49  }
    50  
    51  // IsServiceUnreachable returns true if the registry/discovery service was unreachable
    52  func IsServiceUnreachable(err error) bool {
    53  	_, ok := err.(*ServiceUnreachableError)
    54  	return ok
    55  }