Skip to content

Commit

Permalink
[chore] pkg/ottl check for condition first (#14614)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Oct 1, 2022
1 parent 3a59b75 commit 3613f46
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions pkg/ottl/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,24 @@ type EnumParser func(*EnumSymbol) (*Enum, error)
type Enum int64

func (p *Parser[K]) newFunctionCall(inv invocation) (ExprFunc[K], error) {
if f, ok := p.functions[inv.Function]; ok {
args, err := p.buildArgs(inv, reflect.TypeOf(f))
if err != nil {
return nil, err
}

returnVals := reflect.ValueOf(f).Call(args)
f, ok := p.functions[inv.Function]
if !ok {
return nil, fmt.Errorf("undefined function %v", inv.Function)
}
args, err := p.buildArgs(inv, reflect.TypeOf(f))
if err != nil {
return nil, err
}

if returnVals[1].IsNil() {
err = nil
} else {
err = returnVals[1].Interface().(error)
}
returnVals := reflect.ValueOf(f).Call(args)

return returnVals[0].Interface().(ExprFunc[K]), err
if returnVals[1].IsNil() {
err = nil
} else {
err = returnVals[1].Interface().(error)
}
return nil, fmt.Errorf("undefined function %v", inv.Function)

return returnVals[0].Interface().(ExprFunc[K]), err
}

func (p *Parser[K]) buildArgs(inv invocation, fType reflect.Type) ([]reflect.Value, error) {
Expand Down

0 comments on commit 3613f46

Please sign in to comment.