opentofu/registry/errors.go
Sander van Harmelen a5a2156584 core: enhance service discovery
This PR improves the error handling so we can provide better feedback about any service discovery errors that occured.

Additionally it adds logic to test for specific versions when discovering a service using `service.vN`. This will enable more informational errors which can indicate any version incompatibilities.
2018-12-10 20:52:05 +01:00

49 lines
1.4 KiB
Go

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