github.com/openfga/openfga@v1.5.4-rc1/internal/condition/errors.go (about) 1 package condition 2 3 import ( 4 "fmt" 5 6 "github.com/natefinch/wrap" 7 ) 8 9 var ErrEvaluationFailed = fmt.Errorf("failed to evaluate relationship condition") 10 11 type CompilationError struct { 12 Condition string 13 Cause error 14 } 15 16 func (e *CompilationError) Error() string { 17 return fmt.Sprintf("failed to compile expression on condition '%s' - %v", e.Condition, e.Cause) 18 } 19 20 func (e *CompilationError) Unwrap() error { 21 return e.Cause 22 } 23 24 type EvaluationError struct { 25 Condition string 26 Cause error 27 } 28 29 func NewEvaluationError(condition string, cause error) error { 30 return wrap.With(&EvaluationError{ 31 Condition: condition, 32 Cause: cause, 33 }, ErrEvaluationFailed) 34 } 35 36 func (e *EvaluationError) Error() string { 37 if _, ok := e.Cause.(*ParameterTypeError); ok { 38 return e.Unwrap().Error() 39 } 40 41 return fmt.Sprintf("'%s' - %v", e.Condition, e.Cause) 42 } 43 44 func (e *EvaluationError) Unwrap() error { 45 return e.Cause 46 } 47 48 type ParameterTypeError struct { 49 Condition string 50 Cause error 51 } 52 53 func (e *ParameterTypeError) Error() string { 54 return fmt.Sprintf("parameter type error on condition '%s' - %v", e.Condition, e.Cause) 55 } 56 57 func (e *ParameterTypeError) Unwrap() error { 58 return e.Cause 59 }