8 // EvalNode is the interface that must be implemented by graph nodes to
10 type EvalNode interface {
11 // Eval evaluates this node with the given context. The second parameter
12 // are the argument values. These will match in order and 1-1 with the
13 // results of the Args() return value.
14 Eval(EvalContext) (interface{}, error)
17 // GraphNodeEvalable is the interface that graph nodes must implement
18 // to enable valuation.
19 type GraphNodeEvalable interface {
23 // EvalEarlyExitError is a special error return value that can be returned
24 // by eval nodes that does an early exit.
25 type EvalEarlyExitError struct{}
27 func (EvalEarlyExitError) Error() string { return "early exit" }
29 // Eval evaluates the given EvalNode with the given context, properly
30 // evaluating all args in the correct order.
31 func Eval(n EvalNode, ctx EvalContext) (interface{}, error) {
32 // Call the lower level eval which doesn't understand early exit,
33 // and if we early exit, it isn't an error.
34 result, err := EvalRaw(n, ctx)
36 if _, ok := err.(EvalEarlyExitError); ok {
44 // EvalRaw is like Eval except that it returns all errors, even if they
45 // signal something normal such as EvalEarlyExitError.
46 func EvalRaw(n EvalNode, ctx EvalContext) (interface{}, error) {
49 path = strings.Join(ctx.Path(), ".")
52 log.Printf("[DEBUG] %s: eval: %T", path, n)
53 output, err := n.Eval(ctx)
55 if _, ok := err.(EvalEarlyExitError); ok {
56 log.Printf("[DEBUG] %s: eval: %T, err: %s", path, n, err)
58 log.Printf("[ERROR] %s: eval: %T, err: %s", path, n, err)