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