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

Method Eval

cel/program.go:308–353  ·  view source on GitHub ↗

Eval implements the Program interface method.

(input any)

Source from the content-addressed store, hash-verified

306
307// Eval implements the Program interface method.
308func (p *prog) Eval(input any) (out ref.Val, det *EvalDetails, err error) {
309 // Configure error recovery for unexpected panics during evaluation. Note, the use of named
310 // return values makes it possible to modify the error response during the recovery
311 // function.
312 defer func() {
313 if r := recover(); r != nil {
314 switch t := r.(type) {
315 case interpreter.EvalCancelledError:
316 err = t
317 default:
318 err = fmt.Errorf("internal error: %v", r)
319 }
320 }
321 }()
322 // Build a hierarchical activation if there are default vars set.
323 var frame *interpreter.ExecutionFrame
324 if f, ok := input.(*interpreter.ExecutionFrame); ok {
325 frame = f
326 } else {
327 frame, err = p.newExecutionFrame(input)
328 if err != nil {
329 return nil, nil, err
330 }
331 defer frame.Close()
332 }
333 if p.observable != nil {
334 det = &EvalDetails{}
335 out = p.observable.ObserveExec(frame, func(observed any) {
336 switch o := observed.(type) {
337 case interpreter.EvalState:
338 det.state = o
339 case *interpreter.CostTracker:
340 det.costTracker = o
341 }
342 })
343 } else {
344 out = p.interpretable.Exec(frame)
345 }
346 // The output of an internal Eval may have a value (`v`) that is a types.Err. This step
347 // translates the CEL value to a Go error response. This interface does not quite match the
348 // RPC signature which allows for multiple errors to be returned, but should be sufficient.
349 if types.IsError(out) {
350 err = out.(*types.Err)
351 }
352 return
353}
354
355// ContextEval implements the Program interface.
356func (p *prog) ContextEval(ctx context.Context, input any) (ref.Val, *EvalDetails, error) {

Callers 1

ContextEvalMethod · 0.95

Calls 5

newExecutionFrameMethod · 0.95
CloseMethod · 0.95
IsErrorFunction · 0.92
ObserveExecMethod · 0.80
ExecMethod · 0.65

Tested by

no test coverage detected