github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/reconciler/contract.go (about) 1 package reconciler 2 3 import ( 4 "fmt" 5 "strings" 6 7 reconcilerApi "github.com/kyma-incubator/reconciler/pkg/keb" 8 kebError "github.com/kyma-project/kyma-environment-broker/internal/error" 9 ) 10 11 type reconcilerError struct { 12 components []string 13 message string 14 } 15 16 func (e reconcilerError) Error() string { 17 return e.message 18 } 19 20 func (e reconcilerError) Component() kebError.ErrComponent { 21 return kebError.ErrReconciler 22 } 23 24 func (e reconcilerError) Reason() kebError.ErrReason { 25 if e.components == nil { 26 return kebError.ErrReconcilerNilFailures 27 } 28 29 return kebError.ErrReason(strings.Join(e.components, ", ")) 30 } 31 32 func errorf(components []string, format string, args ...interface{}) kebError.ErrorReporter { 33 return reconcilerError{components: components, message: fmt.Sprintf(format, args...)} 34 } 35 36 func NewReconcilerError(failures *[]reconcilerApi.Failure, format string, args ...interface{}) kebError.ErrorReporter { 37 var components []string 38 39 if failures == nil { 40 return errorf(nil, format, args...) 41 } 42 43 for _, f := range *failures { 44 components = append(components, f.Component) 45 } 46 47 return errorf(components, format, args...) 48 } 49 50 func PrettyFailures(response *reconcilerApi.HTTPClusterResponse) string { 51 var errs []string 52 failures := response.Failures 53 54 if failures == nil { 55 return "" 56 } 57 58 for _, f := range *failures { 59 errs = append(errs, fmt.Sprintf("component %v failed: %v", f.Component, f.Reason)) 60 } 61 return strings.Join(errs, ", ") 62 }