MCPcopy Create free account
hub / github.com/cel-expr/cel-go / validate

Method validate

common/cost/validate.go:52–91  ·  view source on GitHub ↗
(inPrior bool)

Source from the content-addressed store, hash-verified

50}
51
52func (m OverloadModel) validate(inPrior bool) error {
53 if m.ID == "" {
54 return errors.New("overload model requires an ID")
55 }
56 if m.manual && m.manualEstimator {
57 return fmt.Errorf("overload %q cannot combine ManualCost with ManualEstimator", m.ID)
58 }
59 if m.manual && (m.Cost != nil || m.hasSize) {
60 return fmt.Errorf("overload %q cannot combine ManualCost with EvalCost or ResultSize", m.ID)
61 }
62 if m.manual && (m.estimator == nil || m.tracker == nil) {
63 return fmt.Errorf("overload %q ManualCost requires both a FunctionEstimator and a FunctionTracker", m.ID)
64 }
65 if m.manualEstimator && m.hasSize {
66 return fmt.Errorf("overload %q cannot combine ManualEstimator with ResultSize", m.ID)
67 }
68 if m.manualEstimator && m.estimator == nil {
69 return fmt.Errorf("overload %q ManualEstimator requires a FunctionEstimator", m.ID)
70 }
71 if !m.manual && m.Cost == nil && !(inPrior && (m.manualEstimator || m.hasSize)) {
72 return fmt.Errorf("overload %q requires an EvalCost expression or ManualCost", m.ID)
73 }
74 if m.Cost != nil {
75 if err := validateQuantityExpr(m.Cost); err != nil {
76 return fmt.Errorf("overload %q eval cost: %w", m.ID, err)
77 }
78 }
79 if m.Size != nil || (m.hasSize && !inPrior) {
80 if err := validateQuantityExpr(m.Size); err != nil {
81 return fmt.Errorf("overload %q result size: %w", m.ID, err)
82 }
83 }
84 if !m.IsMember && (hasTarget(m.Cost) || hasTarget(m.Size)) {
85 return fmt.Errorf("overload %q is global but its model references the receiver; use MemberOverload", m.ID)
86 }
87 if m.Size != nil && references(m.Size, func(e QuantityExpr) bool { _, ok := e.(resultExpr); return ok }) {
88 return fmt.Errorf("overload %q result size references Result()", m.ID)
89 }
90 return validatePriors(m)
91}
92
93func validatePriors(m OverloadModel) error {
94 seen := make(map[uint32]struct{}, len(m.priors))

Callers 3

ValidateMethod · 0.95
TestClaimsCustomTypesFunction · 0.80
validatePriorsFunction · 0.80

Calls 5

validateQuantityExprFunction · 0.85
hasTargetFunction · 0.85
referencesFunction · 0.85
validatePriorsFunction · 0.85
NewMethod · 0.80

Tested by 1

TestClaimsCustomTypesFunction · 0.64