Fix err handling due to cel update

This commit is contained in:
cici37 2022-03-14 13:43:24 -07:00
parent aa383570f0
commit ed03e0955c
2 changed files with 3 additions and 3 deletions

View File

@ -185,14 +185,14 @@ func (s *Validator) validateExpressions(fldPath *field.Path, sts *schema.Structu
// been bypassed. int-or-string is typed as dynamic and so bypasses compiler type checking. // been bypassed. int-or-string is typed as dynamic and so bypasses compiler type checking.
errs = append(errs, field.Invalid(fldPath, obj, fmt.Sprintf("'%v': call arguments did not match a supported operator, function or macro signature for rule: %v", err, ruleErrorString(rule)))) errs = append(errs, field.Invalid(fldPath, obj, fmt.Sprintf("'%v': call arguments did not match a supported operator, function or macro signature for rule: %v", err, ruleErrorString(rule))))
} else if strings.HasPrefix(err.Error(), "operation cancelled: actual cost limit exceeded") { } else if strings.HasPrefix(err.Error(), "operation cancelled: actual cost limit exceeded") {
errs = append(errs, field.Invalid(fldPath, obj, fmt.Sprintf("'%v': call cost exceeds limit for rule: %v", err, ruleErrorString(rule)))) errs = append(errs, field.Invalid(fldPath, obj, fmt.Sprintf("'%v': no further validation rules will be run due to call cost exceeds limit for rule: %v", err, ruleErrorString(rule))))
return errs, -1
} else { } else {
// no such key: {key}, index out of bounds: {index}, integer overflow, division by zero, ... // no such key: {key}, index out of bounds: {index}, integer overflow, division by zero, ...
errs = append(errs, field.Invalid(fldPath, obj, fmt.Sprintf("%v evaluating rule: %v", err, ruleErrorString(rule)))) errs = append(errs, field.Invalid(fldPath, obj, fmt.Sprintf("%v evaluating rule: %v", err, ruleErrorString(rule))))
} }
continue continue
} }
if evalResult != types.True { if evalResult != types.True {
if len(rule.Message) != 0 { if len(rule.Message) != 0 {
errs = append(errs, field.Invalid(fldPath, obj, rule.Message)) errs = append(errs, field.Invalid(fldPath, obj, rule.Message))

View File

@ -1721,7 +1721,7 @@ func TestValidationExpressions(t *testing.T) {
} }
errs, _ = celValidator.Validate(field.NewPath("root"), &s, tt.obj, tt.costBudget) errs, _ = celValidator.Validate(field.NewPath("root"), &s, tt.obj, tt.costBudget)
for _, err := range errs { for _, err := range errs {
if err.Type == field.ErrorTypeInvalid && strings.Contains(err.Error(), "call cost exceeds limit for rule") { if err.Type == field.ErrorTypeInvalid && strings.Contains(err.Error(), "no further validation rules will be run due to call cost exceeds limit for rule") {
found = true found = true
break break
} }