// Filter removes items from the ValidationErrorList that match the provided fns. func (list ValidationErrorList) Filter(fns ...errors.Matcher) ValidationErrorList { err := errors.FilterOut(errors.NewAggregate(list), fns...) if err == nil { return nil } // FilterOut that takes an Aggregate returns an Aggregate agg := err.(errors.Aggregate) return ValidationErrorList(agg.Errors()) }
// NewInvalid returns an error indicating the item is invalid and cannot be processed. func NewInvalid(kind, name string, errs fielderrors.ValidationErrorList) error { causes := make([]api.StatusCause, 0, len(errs)) for i := range errs { if err, ok := errs[i].(*fielderrors.ValidationError); ok { causes = append(causes, api.StatusCause{ Type: api.CauseType(err.Type), Message: err.Error(), Field: err.Field, }) } } return &StatusError{api.Status{ Status: api.StatusFailure, Code: StatusUnprocessableEntity, // RFC 4918: StatusUnprocessableEntity Reason: api.StatusReasonInvalid, Details: &api.StatusDetails{ Kind: kind, Name: name, Causes: causes, }, Message: fmt.Sprintf("%s %q is invalid: %v", kind, name, errors.NewAggregate(errs)), }} }