opentofu/internal/registry/errors.go
Martin Atkins 4c5b866dea Move registry/ to internal/registry/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00

48 lines
1.3 KiB
Go

package registry
import (
"fmt"
"github.com/hashicorp/terraform-svchost/disco"
"github.com/hashicorp/terraform/internal/registry/regsrc"
)
type errModuleNotFound struct {
addr *regsrc.Module
}
func (e *errModuleNotFound) Error() string {
return fmt.Sprintf("module %s not found", e.addr)
}
// IsModuleNotFound returns true only if the given error is a "module not found"
// error. This allows callers to recognize this particular error condition
// as distinct from operational errors such as poor network connectivity.
func IsModuleNotFound(err error) bool {
_, ok := err.(*errModuleNotFound)
return ok
}
// IsServiceNotProvided returns true only if the given error is a "service not provided"
// error. This allows callers to recognize this particular error condition
// as distinct from operational errors such as poor network connectivity.
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
}